Update a specified automation based on the automation ID. The maximum number of conditions: 10, and the maximum number of actions: 50.
API address
PUT: /v2.0/iot-03/automations/{automation_id}
Request parameter
| Parameter name | Type | IN | Required | Description |
| automation_id | String | uri | true | The automation ID. |
Description of body
| Parameter name | Type | IN | Required | Description |
| name | String | | true | The name of a specified automation. |
| dsl | AutomationDsl | | true | The language of automation rules. |
| preconditions | Preconditions | | false | The preconditions for a specified automation execution. |
Description of preconditions
| Parameter name | Type | IN | Required | Description |
| trigger_type | String | | false | The type of trigger. Valid value: timeCheck. |
| precondition_trigger_rule | PreconditionTriggerRule | | false | The precondition trigger rule. See the details of precondition_trigger_rule. |
Description of dsl
| Parameter name | Type | IN | Required | Description |
| conditions | List | | true | The list of automation conditions. |
| conditions_rule | String | | true | The automation condition matching rules. Valid values:and: All conditions are met.or: Any condition is met.
|
| actions | List | | true | The list of automation actions. |
Description of conditions
| Parameter name | Type | IN | Required | Description |
| trigger_type | String | | true | The condition trigger type. Valid values:deviceReport: It is triggered when a device reports data.timer: It is triggered at the scheduled time.weather: It is triggered by the specified weather condition.
|
| trigger_id | String | | true | The condition trigger ID. When trigger_type is deviceReport, trigger_id is the device ID. When trigger_type is timer, trigger_id is set to timer. When trigger_type is weather, trigger_id is set to the city ID. |
| trigger_rule | Object | | true | The condition trigger rule. See the details of trigger_rule. |
| rule_num | Integer | | true | The trigger condition number, used for custom condition calculation of the matching rule. The value ranges from 1 to the number of conditions, and cannot be repeated. |
Description of actions
| Parameter name | Type | IN | Required | Description |
| execution_type | String | | true | The execution type.deviceIssue: sent by a device.deviceGroupIssue: sent by a device group.delay: delay action.
|
| execution_rule | Object | | true | The execution rule. See the details of execution_rule. |
Return parameter
| Parameter name | Type | Description |
| result | Boolean | The returned result. Valid values:true: Updated successfully.false: Failed to update it.
|
Request example
PUT: /v2.0/iot-03/automations/XeSHHn7BR0FW****
{
"name": "This is an automation scene",
"dsl": {
"conditions": [
{
"trigger_type": "deviceReport",
"trigger_id": "vdevo16292691746****",
"trigger_rule": {
"status_code": "switch_led",
"comparator": "==",
"status_value": true
},
"rule_num": 1
},
{
"trigger_type": "timer",
"trigger_id": "timer",
"trigger_rule": {
"timer_format": "18:00 11 09 * 2021"
},
"rule_num": 2
},
{
"trigger_type": "weather",
"trigger_id": "101069444120988****",
"trigger_rule": {
"weather_code": "temp",
"comparator": "==",
"weather_value": 20
},
"rule_num": 3
}
],
"conditions_rule": "or",
"actions": [
{
"execution_type": "delay",
"execution_rule": {
"delay_seconds": 60
}
},
{
"execution_type": "deviceIssue",
"execution_rule": {
"execution_id": "vdevo16292691746****",
"function_code": "bright_value",
"function_value": 20
}
},
{
"execution_type": "deviceGroupIssue",
"execution_rule": {
"execution_id": "144790134147200****",
"function_code": "switch_1",
"function_value": true
}
}
]
},
"preconditions": {
"trigger_type": "timeCheck",
"precondition_trigger_rule": {
"timer_format": "09:00-23:00 * * 0,1,2,3 *"
}
}
}
Return example
{
"result": true,
"t": 1635844703309,
"success": true
}
Error code
For more information, see error code.
Details of trigger_rule
- When
trigger_type is deviceReport:
| Parameter name | Type | Description | Required |
| status_code | String | The device instruction. | Yes |
| comparator | String | The comparator. | Yes |
| status_value | Object | The device instruction value. | Yes |
- When
trigger_type is timer:
| Parameter name | Type | Description | Required |
| timer_format | String | The scheduled trigger time. Two formats are supported.- Specify the scheduled date in the format such as: [hour:min] [day of month] [month] [day of week] [year]. For example, 20:00 20 10 * 2021 (October 20, 2021, 8:00 pm).
- Specify the weekly cycle timer in the format such as: [hour:min] [day of month] [month] [day of week] [year]. For example, 20:00 * * 0,1,2,3 * (every Sunday, Monday, Tuesday, and Wednesday at 8:00 pm).
| Yes |
- When
trigger_type is weather:
| Parameter name | Type | Description | Required |
| weather_code | String | The weather code. | Yes |
| comparator | String | The comparator. | Yes |
| weather_value | Object | The value of the weather code. | Yes |
Details of execution_rule
- When
execution_type is delay:
| Parameter name | Type | Description | Required |
| delay_seconds | Long | The delay time. The value range is 1 to 5 × 60 × 60. Unit: second. | Yes |
- When
execution_type is deviceIssue or deviceGroupIssue:
| Parameter name | Type | Description | Required |
| execution_id | String | The ID of a specified device or device group. | Yes |
| function_code | String | The instruction code of a device or device group. | Yes |
| function_value | Object | The instruction value of a device or device group. | Yes |
Details of precondition_trigger_rule
| Parameter name | Type | Description | Required |
| timer_format | String | The timer format. The format is: [hour:min]-[hour:min] [day of month] [month] [day of week] [year]. For example, 9:30-18:00 * * 0,1,2,3,4,5,6 * (9:30 am to 6:00 pm every week) | No |