Why Automation is Inevitable
Manual engineering in TIA Portal is slow and error-prone. Right-clicking, creating blocks, copy-pasting code... These repetitive tasks must disappear. Thanks to the Openness API (and its T-IA Connect REST wrapper), you can drive TIA Portal like any modern software.
Prerequisites
- TIA Portal V16, V17, V18, V19 or V21 installed
- A T-IA Connect license (Freemium or paid)
- PowerShell or Python installed on your machine
Step 1: Start the REST API
Instead of launching TIA Portal manually, we will start the T-IA Connect server which will act as a gateway. Open your terminal and run:
./TiaPortalApi.App.exe --headless
Step 2: Health Check
Before anything else, let's verify that the API is running and check which TIA Portal versions are available on the machine.
curl http://localhost:9000/api/health curl http://localhost:9000/api/health/versions
{
"status": "healthy",
"tiaPortalConnected": true,
"uptime": "00:01:23"
}
{
"installedVersions": ["V17", "V18", "V19"]
}Step 3: Create a Project
No more 'File > New' menus. Let's send a POST request to instantiate a blank project.
curl -X POST http://localhost:9000/api/projects/actions/create \
-H "Content-Type: application/json" \
-d '{
"name": "MyAutomatedProject",
"path": "C:\\TIA_Projects",
"version": "V19"
}'{
"name": "MyAutomatedProject",
"path": "C:\\TIA_Projects\\MyAutomatedProject",
"version": "V19",
"created": true
}Step 4: Add a PLC & Create an FB
Search the hardware catalog for a CPU, add it to the project, then create a Function Block with SCL code — all in a few API calls.
# Search the hardware catalog
curl -X POST http://localhost:9000/api/catalog/actions/search \
-H "Content-Type: application/json" \
-d '{ "searchPattern": "CPU 1511" }'
# Add the device to the project
curl -X POST http://localhost:9000/api/projects/devices/actions/add \
-H "Content-Type: application/json" \
-d '{
"name": "PLC_1",
"typeId": "<typeId from search>",
"deviceName": "CPU 1511C-1 PN"
}'
# Create a Function Block
curl -X POST http://localhost:9000/api/devices/PLC_1/blocks \
-H "Content-Type: application/json" \
-d '{
"name": "FB_MotorControl",
"type": "FB",
"programmingLanguage": "SCL"
}'
# Add SCL code to the block
curl -X POST http://localhost:9000/api/devices/PLC_1/blocks/FB_MotorControl/networks \
-H "Content-Type: application/json" \
-d '{
"title": "Motor control logic",
"code": "#Running := #Start AND NOT #Stop;\nIF #Running THEN\n #Speed := #SpeedSetpoint;\nEND_IF;"
}'// Block creation response
{
"name": "FB_MotorControl",
"type": "FB",
"programmingLanguage": "SCL",
"number": 1
}
// Network added
{
"networkId": 1,
"title": "Motor control logic",
"created": true
}Step 5: Create Tags
Import PLC tags (inputs, outputs, memory) in bulk via a single API call. No more clicking through tag tables one by one.
curl -X POST http://localhost:9000/api/devices/PLC_1/tags/actions/import \
-H "Content-Type: application/json" \
-d '{
"tagTable": "Motors",
"tags": [
{ "name": "Motor1_Start", "dataType": "Bool", "address": "%I0.0" },
{ "name": "Motor1_Stop", "dataType": "Bool", "address": "%I0.1" },
{ "name": "Motor1_Running", "dataType": "Bool", "address": "%Q0.0" },
{ "name": "Motor1_Speed", "dataType": "Real", "address": "%QD4" },
{ "name": "Motor1_Fault", "dataType": "Bool", "address": "%Q0.1" }
]
}'{
"tagTable": "Motors",
"importedCount": 5,
"tags": [
{ "name": "Motor1_Start", "dataType": "Bool", "address": "%I0.0" },
{ "name": "Motor1_Stop", "dataType": "Bool", "address": "%I0.1" },
{ "name": "Motor1_Running", "dataType": "Bool", "address": "%Q0.0" },
{ "name": "Motor1_Speed", "dataType": "Real", "address": "%QD4" },
{ "name": "Motor1_Fault", "dataType": "Bool", "address": "%Q0.1" }
]
}Step 6: Compile the Project
Trigger a compilation and track its progress via the Jobs API. The compilation runs asynchronously — poll the job status until it completes.
# Start compilation curl -X POST http://localhost:9000/api/devices/PLC_1/actions/compile # Poll the job status (replace <jobId>) curl http://localhost:9000/api/jobs/<jobId>
// Compilation started
{ "jobId": "c7f3a1b2-...", "status": "running" }
// Job completed
{
"jobId": "c7f3a1b2-...",
"status": "completed",
"errors": [],
"warnings": 2
}Step 7: Export to XML
Export your blocks to SimaticML (XML) format for version control with Git. This is the key to treating PLC code like any other source code.
curl -X POST http://localhost:9000/api/devices/PLC_1/blocks/actions/export \
-H "Content-Type: application/json" \
-d '{
"blocks": ["FB_MotorControl"],
"exportPath": "C:\\TIA_Projects\\Export"
}'{
"exportedCount": 1,
"exportPath": "C:\\TIA_Projects\\Export",
"files": ["FB_MotorControl.xml"]
}Step 8: Save & Close
Save the project and close it cleanly. The TIA Portal instance is released and ready for the next automated run.
curl -X POST http://localhost:9000/api/projects/actions/save curl -X POST http://localhost:9000/api/projects/actions/close
{ "saved": true }
{ "closed": true }