Skip to main content

Automation API

Query Device Traits Available for Automation

By calling this API, you can query trait information that can be used for automation from all devices. The returned content includes the value type, unit, and the applicable phase for each trait in the automation process (such as starter, condition, or action).

Request Parameters

ParameterTypeRequiredDescription
typeStringMessage type for the request, must be QueryDeviceSupportedScriptAutomationConfigRequest.
versionStringAPI version, must be v1.
msgIdStringRequest ID defined by you.
dataStringPass an empty string here.

Example Request

Below is a sample request body for QueryDeviceSupportedScriptAutomationConfigRequest:

{
"type": "QueryDeviceSupportedScriptAutomationConfigRequest",
"version": "v1",
"msgId": "1751609244328",
"data": ""
}

Response Parameters

ParameterTypeDescription
typeStringThe message type of the response, always QueryDeviceSupportedScriptAutomationConfigResponse.
versionStringResponse version. It matches the version used in the request.
msgIdStringThe msgId provided in your request.
codeNumberReturn code. 0 means success, any non-zero value indicates failure.
data.devicesArray of ObjectList of device information.
data.devices[].deviceIdStringDevice ID.
data.devices[].deviceNameStringDevice name.
data.devices[].endpointsArray of ObjectList of endpoint information for the device.
data.devices[].endpoints[].endpointNameStringEndpoint name.
data.devices[].endpoints[].endpointIdNumberEndpoint ID.
data.devices[].endpoints[].propertiesArray of ObjectList of traits.
data.devices[].endpoints[].properties[].functionCodeStringFunction code.
data.devices[].endpoints[].properties[].functionNameStringFunction name.
data.devices[].endpoints[].properties[].traitCodeStringTrait code.
data.devices[].endpoints[].properties[].traitNameStringTrait name.
data.devices[].endpoints[].properties[].valueTypeStringThe value type of the trait (such as boolean, number, etc.).
data.devices[].endpoints[].properties[].semanticRoleArray of StringThe automation phases this trait can participate in, including starter, condition, and action. The specific roles depend on the returned array.
data.devices[].endpoints[].properties[].unitString/nullUnit. If no unit, this is null.

Example Response

Below is an example response for QueryDeviceSupportedScriptAutomationConfigResponse:

{
"type": "QueryDeviceSupportedScriptAutomationConfigResponse",
"version": "v1",
"msgId": "1751609244328",
"data": {
"devices": [
{
"deviceId": "9f3e3632068ff047",
"deviceName": "Door and Window Magnet Sensor",
"endpoints": [
{
"endpointName": "Endpoint_2",
"endpointId": 2,
"properties": [
{
"functionCode": "OnOffSensor",
"functionName": "OnOff Sensor",
"traitCode": "BooleanState",
"traitName": "Boolean State",
"valueType": "boolean",
"semanticRole": [
"starter",
"condition"
],
"unit": null
}
]
}
]
},
{
"deviceId": "af9e93b709de1fd9",
"deviceName": "Motion Sensor",
"endpoints": [
{
"endpointName": "Endpoint_2",
"endpointId": 2,
"properties": [
{
"functionCode": "OnOffSensor",
"functionName": "OnOff Sensor",
"traitCode": "BooleanState",
"traitName": "Boolean State",
"valueType": "boolean",
"semanticRole": [
"starter",
"condition"
],
"unit": null
}
]
}
]
},
{
"deviceId": "947793560f5b2fbd",
"deviceName": "Flood Detector",
"endpoints": [
{
"endpointName": "Endpoint_2",
"endpointId": 2,
"properties": [
{
"functionCode": "OnOffSensor",
"functionName": "OnOff Sensor",
"traitCode": "BooleanState",
"traitName": "Boolean State",
"valueType": "boolean",
"semanticRole": [
"starter",
"condition"
],
"unit": null
}
]
}
]
},
...
]
},
"code": 0
}

Create Automation

By calling this API, you can create and enable an automation.

Request Parameters

ParameterTypeRequiredDescription
typeStringMessage type, must be CreateScriptAutomationRequest.
versionStringAPI version, must be v1.
msgIdStringCustom request ID defined by you.
dataObjectRequest data.
data.configObjectJSON automation script. For details, see JSON Automation Script.

Example Request

Below is a sample request body for CreateScriptAutomationRequest:

{
"type": "CreateScriptAutomationRequest",
"version": "v1",
"msgId": "1751609244328",
"data": {
"config": {
"metadata": {
"name": "Smart Lighting Control",
"description": "Automatically turn on two lights when the switch is on",
"scope": [
{
"name": "switchState",
"type": "device.property",
"deviceId": "switch001",
"endpointId": 1,
"functionCode": "OnOff",
"traitCode": "OnOff"
},
{
"name": "tempSensor",
"type": "device.property",
"deviceId": "sensor001",
"endpointId": 1,
"functionCode": "TemperatureMeasurement",
"traitCode": "MeasuredValue"
}
]
},
"automations": [
{
"name": "Switch triggers light linkage",
"starters": [
{
"type": "property.event",
"source": {
"type": "data.ref",
"from": "/metadata/scope",
"select": {
"by": "name",
"value": "switchState"
}
},
"is": true,
"for": "5sec",
"suppressFor": "10sec"
}
],
"condition": {
"type": "and",
"conditions": [
{
"type": "property.state",
"source": {
"type": "data.ref",
"from": "/metadata/scope",
"select": {
"by": "name",
"value": "tempSensor"
}
},
"greaterThan": 20
},
{
"type": "time.between",
"after": "08:00",
"before": "22:00"
}
]
},
"actions": [
{
"type": "device.trait.write",
"functionCode": "Switch",
"traitCode": "OnOff",
"targets": [
{
"deviceId": "light001",
"endpointIds": [1]
}
],
"value": true
},
{
"type": "delay",
"for": "2sec"
},
{
"type": "device.trait.write",
"functionCode": "LevelControl",
"traitCode": "CurrentLevel",
"targets": [
{
"deviceId": "light001",
"endpointIds": [1]
}
],
"value": 100
}
]
}
]
}
}
}

Response Parameters

ParameterTypeDescription
typeStringThe type of message in the response. Always set to CreateScriptAutomationResponse.
versionStringResponse version. It matches the version used in the request.
msgIdStringThe msgId provided in your request.
codeNumberReturn code. 0 means success, any non-zero value indicates failure.
messageStringDescription of the request result.
dataStringThe linkage ID (linkageId) of the created automation.

Example Response

Below is an example response for CreateScriptAutomationResponse:

{
"type": "CreateScriptAutomationResponse",
"version": "v1",
"msgId": "1751609244328",
"code": 0,
"message": "",
"data": "L.15b0cde.127312348967862272"
}

Edit Automation Script

You can use this API to edit an existing automation script.

Request Parameters

ParameterTypeRequiredDescription
typeStringMessage type, must be UpdateScriptAutomationRequest.
versionStringAPI version, must be v1.
msgIdStringCustom request ID defined by you.
dataObjectRequest data.
data.linkageIdStringThe target automation ID to edit.
data.configObjectThe new JSON automation script.
If omitted or set to null, the existing configuration is not changed. If an empty object {} is provided, the automation script content will be cleared.

Example Request

Below is an example of the request body for UpdateScriptAutomationRequest:

{
"type": "UpdateScriptAutomationRequest",
"version": "v1",
"msgId": "1751609244328",
"data": {
"linkageId":"L.15b0cde.127312348967862272",
"config": {

}
}
}

Response Parameters

ParameterTypeDescription
typeStringThe type of message in the response. Always set to UpdateScriptAutomationResponse.
versionStringResponse version. It matches the version used in the request.
msgIdStringThe msgId provided in your request.
codeNumberReturn code. 0 means success, any non-zero value indicates failure.
messageStringDescription of the request result.
dataStringEmpty string.

Example Response

The following is an example response for UpdateScriptAutomationResponse:

{
"type": "UpdateScriptAutomationResponse",
"version": "v1",
"msgId": "1751609244328",
"code": 0,
"message": "",
"data": ""
}

Modify Automation Name and Enable Status

With this API, you can update the name and enable/disable status of an existing automation without modifying its JSON automation script.

Request Parameters

ParameterTypeRequiredDescription
typeStringMessage type, must be UpdateScriptAutomationRequest.
versionStringAPI version, must be v1.
msgIdStringCustom request ID defined by you.
dataObjectRequest data.
data.linkageIdStringThe ID of the automation to be edited.
data.nameStringAutomation name. If omitted or empty, the name will not be updated. If a non-empty value different from the current name is provided, this API will update the name.
data.enabledBooleanWhether to enable the automation. If omitted or set as null, the enabled status is unchanged; if set to a value other than null and different from the current enable status, this API will update the enable status.
  • true: enable
  • false: disable

Example Request

Below is a example request body for UpdateScriptAutomationRequest:

{
"type": "UpdateScriptAutomationRequest",
"version": "v1",
"msgId": "1751609244328",
"data": {
"linkageId":"L.15b0cde.127312348967862272",
"name":"a3",
"enabled": false
}
}

Response Parameters

Same as Edit Automation Script - Response Parameters.

Example Response

Same as Edit Automation Script - Example Response.

Query Automation List

By calling this API, you can obtain a brief list of automations, including each automation's ID, name, enable status, and creation time.

Request Parameters

ParameterTypeRequiredDescription
typeStringMessage type, must be GetScriptAutomationListRequest.
versionStringAPI version, must be v1.
msgIdStringCustom request ID defined by you.
dataObjectRequest data.
data.pageNumNumberPage number, starting from 1.
data.pageSizeNumberNumber of items per page.

Example Request

Below is a sample request body for GetScriptAutomationListRequest:

{
"type": "GetScriptAutomationListRequest",
"version": "v1",
"msgId": "1751609244328",
"data": {
"pageNum":1,
"pageSize":2
}
}

Response Parameters

ParameterTypeDescription
typeStringResponse message type, always GetScriptAutomationListResponse.
versionStringAPI version in the response, always v1.
msgIdStringThe msgId you provided in the request.
dataObjectResponse data object, including the automation list and pagination info.
data.totalCountNumberTotal number of automations.
data.pageNumNumberCurrent page number.
data.pageSizeNumberNumber of items per page.
data.dataArray of ObjectList of automations.
data.data[].linkageIdStringAutomation ID.
data.data[].nameStringName of the automation.
data.data[].enabledBooleanEnable status:
  • true: enabled
  • false: disabled
data.data[].createTimeNumberCreation time of the automation, as a UTC timestamp in milliseconds.
codeNumberIndicates request success. 0 means success, non-zero means failure.
messageString or nullDescription of the response. An empty string or null indicates success.

Example Response

Below is an example response for GetScriptAutomationListResponse:

{
"type": "GetScriptAutomationListResponse",
"version": "v1",
"msgId": "1751609244328",
"data": {
"totalCount": 6,
"pageNum": 1,
"pageSize": 2,
"data": [
{
"linkageId": "L.15b0cde.127312348967862272",
"name": "a3-1",
"enabled": false,
"createTime": 1766043229326
},
{
"linkageId": "L.15b0ceb.127312523723538432",
"name": "b2",
"enabled": true,
"createTime": 1766043270999
}
]
},
"code": 0,
"message": null
}

Query Automation Details

By calling this API and providing the automation ID, you can retrieve the detailed information for the specified automation (such as the JSON automation script).

Request Parameters

ParameterTypeRequiredDescription
typeStringRequest message type, must be GetScriptAutomationDetailsRequest.
versionStringAPI version, must be v1.
msgIdStringCustom request ID defined by you.
dataStringThe automation ID to be queried.

Example Request

Below is an example request body for GetScriptAutomationDetailsRequest:

{
"type": "GetScriptAutomationDetailsRequest",
"version": "v1",
"msgId": "1751609244328",
"data": "L.15b0cde.127312348967862272"
}

Response Parameters

ParameterTypeDescription
typeStringThe type of response message. Always set to GetScriptAutomationDetailsResponse.
versionStringAPI version. Always v1.
msgIdStringThe msgId provided in your request.
dataObjectThe returned object containing the automation's detailed information.
data.linkageIdStringThe automation ID.
data.nameStringThe name of the automation.
data.enabledBooleanWhether the automation is enabled.
data.configObjectThe JSON automation script.
data.createTimeNumberThe time when the automation was created, as a UTC timestamp in milliseconds.
codeNumberResponse code. 0 means success, any other value is an error code.
messageString or nullDescription message about the response. An empty string or null means the request was successful.

Example Response

Below is an example response for GetScriptAutomationDetailsResponse:

{
"type": "GetScriptAutomationDetailsResponse",
"version": "v1",
"msgId": "1751609244328",
"data": {
"linkageId": "L.15b0cde.127312348967862272",
"name": "a3-1",
"enabled": false,
"config": {

},
"createTime": 1766043229326
},
"code": 0,
"message": null
}

Delete Automation

By calling this API, you can delete multiple automations.

Request Parameters

ParameterTypeRequiredDescription
typeStringRequest message type, fixed as DeleteAutomationRequest.
versionStringAPI version, always v1.
msgIdStringCustom request ID defined by you.
dataArray of StringArray of automation IDs (linkageId) to be deleted.

Example Request

Below is an example request body for DeleteAutomationRequest:

{
"type": "DeleteAutomationRequest",
"version": "v1",
"msgId": "1751609244328",
"data": ["L.15b0b4d.1273030749213163"]
}

Example Response

ParameterTypeDescription
typeStringThe type of message in the response. Always set to DeleteAutomationResponse.
versionStringResponse version. Always set to v1.
msgIdStringThe msgId provided in your request.
codeNumberReturn code. 0 means success, any non-zero value indicates failure.
messageStringDescription of the request result.
dataStringAn empty string.

Example Response

{
"type": "DeleteAutomationResponse",
"version":"v1",
"msgId":"1751609244328",
"code":0,
"message":"",
"data":""
}