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 QueryAutomationCapabilitiesRequest.
versionStringAPI version, must be v1.
msgIdStringRequest ID defined by you.
dataObjectPass an empty object here.

Example Request

Below is a sample request body for QueryAutomationCapabilitiesRequest:

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

Response Parameters

ParameterTypeDescription
typeStringThe message type of the response, always QueryAutomationCapabilitiesResponse.
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 QueryAutomationCapabilitiesResponse:

{
"type": "QueryAutomationCapabilitiesResponse",
"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 a flow automation.

Once created successfully, you can view and manage this flow in the automation list on Aqara Studio.

Request Parameters

ParameterTypeRequiredDescription
typeStringMessage type, must be CreateAutomationRequest.
versionStringAPI version, must be v1.
msgIdStringCustom request ID defined by you.
dataObjectRequest data.
data.definitionTypeStringAutomation type. Currently, only "SCRIPT_JSON" is supported.
data.configObjectJSON automation script. For details, see JSON Automation Script.

Example Request

Below is a sample request body for CreateAutomationRequest:

{
"type": "CreateAutomationRequest",
"version": "v1",
"msgId": "1751609244328",
"data": {
"definitionType": "SCRIPT_JSON",
"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 CreateAutomationResponse.
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 automatin ID of the created automation.

Example Response

Below is an example response for CreateAutomationResponse:

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

Edit Automation

By calling this API, you can modify the name and enabled status of an existing automation. If the automation's definitionType is "SCRIPT_JSON", you can also update its automation script content at the same time.

Request Parameters

ParameterTypeRequiredDescription
typeStringMessage type, must be UpdateAutomationRequest.
versionStringAPI version, must be v1.
msgIdStringCustom request ID defined by you.
dataObjectRequest data.
data.automationIdStringThe target automation ID.
data.definitionTypeStringThe definition type of the target automation to be edited.
data.nameStringThe new name.
data.enabledBooleanThe new enabled status. true means enabled. false means disabled.
data.configObjectThe new JSON automation script.
data.updateMaskArray of StringList of parameter names to be updated. Only the following fields are supported:
  • "name"
  • "enabled"
  • "config"
Please make sure each item in updateMask has a corresponding new value provided in the data object.

Example Request

Below is an example of the request body for UpdateAutomationRequest:

{
"type": "UpdateAutomationRequest",
"version": "v1",
"msgId": "1751609244328",
"data": {
"automationId":"auto_15b0cde_127312348967862272",
"definitionType": "SCRIPT_JSON",
"name": "New Name",
"updateMask": [
"name"
]
}
}

Response Parameters

ParameterTypeDescription
typeStringThe type of message in the response. Always set to UpdateAutomationResponse.
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 UpdateAutomationResponse:

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

Batch Update Automation Status

By calling this API, you can update the enable status of multiple automations at once.

Request Parameters

ParameterTypeRequiredDescription
typeStringType of request message, must be UpdateAutomationStatusRequest.
versionStringAPI version, must be v1.
msgIdStringCustom request ID defined by you.
dataObjectRequest data object.
data.automationIdsArray of StringList of automation IDs to update the status for.
data.enabledBooleanThe status to set: true to enable, false to disable.

Example Request

Below is a example request body for UpdateAutomationStatusRequest:

{
"type": "UpdateAutomationStatusRequest",
"version": "v1",
"msgId": "1751609244328",
"data": {
"automationIds": [
"auto_15b0cde_127312348967862272"
],
"enabled": false
}
}

Response Parameters

ParameterTypeDescription
typeStringResponse message type, always UpdateAutomationStatusResponse.
versionStringAPI version in the response, always v1.
msgIdStringThe msgId you provided in the request.
codeNumberIndicates whether the request was successful: 0 for success, non-zero for failure.
messageStringDescription of the request result.
dataObjectResponse data object.
data.successIdsArray of StringList of successfully updated automation IDs.
data.failedItemsArray of ObjectList of failed automation update objects.
data.failedItems.automationIdStringAutomation ID.
data.failedItems.codeNumberError code.
data.failedItems.messageStringFailure description.

Example Response

The following is an example response for UpdateAutomationStatusResponse:

{
"type": "UpdateAutomationStatusResponse",
"version": "v1",
"msgId": "1751609244328",
"data": {
"successIds": [
"auto_15b0cde_127312348967862272"
]
}
}

Query Automation List

By calling this API, you can get a paginated list of automation summaries, including each automation's ID, name, enable status, and creation time.

Request Parameters

ParameterTypeRequiredDescription
typeStringMessage type, must be GetAutomationListRequest.
versionStringAPI version, must be v1.
msgIdStringCustom request ID defined by you.
dataObjectRequest data.
data.definitionTypesArray of StringTarget types to query. Optional values: "SCRIPT_JSON", "SCRIPT_TEXT", "WHEN_IF_THEN". If not provided or empty, queries all types.
data.orderByStringSorting field.
  • "createTime asc": (default) sort by creation time in ascending order
  • "createTime desc": sort by creation time in descending order
data.pageNumNumberPage number, starting from 1.
data.pageSizeNumberNumber of items per page.

Example Request

Below is a sample request body for GetAutomationListRequest:

{
"type": "GetAutomationListRequest",
"version": "v1",
"msgId": "1751609244328",
"data": {
"definitionTypes": ["SCRIPT_JSON"],
"pageNum":1,
"pageSize":2
}
}

Response Parameters

ParameterTypeDescription
typeStringResponse message type, always GetAutomationListResponse.
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[].automationIdStringAutomation ID.
data.data[].definitionTypeStringAutomation type.
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 GetAutomationListResponse:

{
"type": "GetAutomationListResponse",
"version": "v1",
"msgId": "1751609244328",
"data": {
"totalCount": 6,
"pageNum": 1,
"pageSize": 2,
"data": [
{
"automationId": "auto_15b0cde_127312348967862272",
"definitionType": "SCRIPT_JSON",
"name": "a3-1",
"enabled": false,
"createTime": 1766043229326
},
{
"automationId": "auto_15b0ceb_127312523723538432",
"definitionType": "SCRIPT_JSON",
"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).

tip

Only automations with definitionType equal to "SCRIPT_JSON" are supported for querying details.

Request Parameters

ParameterTypeRequiredDescription
typeStringRequest message type, must be GetAutomationDetailsRequest.
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 GetAutomationDetailsRequest:

{
"type": "GetAutomationDetailsRequest",
"version": "v1",
"msgId": "1751609244328",
"data": "auto_15b0cde_127312348967862272"
}

Response Parameters

ParameterTypeDescription
typeStringThe type of response message. Always set to GetAutomationDetailsResponse.
versionStringAPI version. Always v1.
msgIdStringThe msgId provided in your request.
dataObjectThe returned object containing the automation's detailed information.
data.automationIdStringThe automation ID.
data.definitionTypeStringAutomation type. Currently always "SCRIPT_JSON".
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 GetAutomationDetailsResponse:

{
"type": "GetAutomationDetailsResponse",
"version": "v1",
"msgId": "1751609244328",
"data": {
"automationId": "auto_15b0cde_127312348967862272",
"definitionType": "SCRIPT_JSON",
"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 to be deleted.

Example Request

Below is an example request body for DeleteAutomationRequest:

{
"type": "DeleteAutomationRequest",
"version": "v1",
"msgId": "1751609244328",
"data": ["auto_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.
dataObjectResponse object.
data.successIdsArray of StringIDs of automations deleted successfully.
data.failedItemsArray of ObjectObjects representing failed deletions.
data.failedItems.automationIdStringAutomation ID.
data.failedItems.codeNumberError code.
data.failedItems.messageStringFailure description.

Example Response

{
"type": "DeleteAutomationResponse",
"version": "v1",
"msgId": "1751609244328",
"code": 0,
"message": "",
"data": {
"successIds": [
"auto_15b0b4d_1273030749213163"
]
}
}