Add Automation Scene

Last Updated on : 2023-07-14 03:01:27download

Add automation scenes that are triggered by different conditions or actions. The maximum number of conditions: 10, and the maximum number of actions: 50.

API address

POST: /v2.0/iot-03/automations

Request parameter

Description of body

Parameter nameTypeINRequiredDescription
nameString trueThe name of the specified automation scene.
dslAutomationDsl trueThe language of automation rules.
preconditionsPreconditions falseThe preconditions for the specified automation execution.

Description of preconditions

Parameter nameTypeINRequiredDescription
trigger_typeString falseThe type of trigger. Valid value: timeCheck.
precondition_trigger_ruleObject falseThe precondition trigger rule. See the details of precondition_trigger_rule.

Description of dsl

Parameter nameTypeINRequiredDescription
conditionsList trueThe list of automation conditions.
conditions_ruleString trueThe matching rules of automation conditions. Valid values:
  • all: All conditions are met.
  • or: Any condition is met.
actionsList trueThe list of automation actions.

Description of conditions

Parameter nameTypeINRequiredDescription
trigger_typeString trueThe type of trigger. 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_idString trueThe ID of the specified triggering condition.
When the value of trigger_type is deviceReport, trigger_id is the device ID.
When the value of trigger_type is timer, trigger_id is fixed to timer.
When the value of trigger_type is weather, trigger_id is fixed to the city ID.
trigger_ruleObject trueThe rule of the specified triggering condition. For more information, see details of trigger_rule.
rule_numInteger trueThe serial number of the specified triggering condition, 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 nameTypeINRequiredDescription
execution_typeString trueType of execution. Valid values:
  • deviceIssue: Send an instruction to a device.
  • deviceGroupIssue: Send an instruction to a device group.
  • delay: Delay an action.
execution_ruleObject trueThe execution rule. See the details of execution_rule.

Return parameter

Parameter nameTypeDescription
resultStringThe ID of the specified automation scene.

Request example

POST: /v2.0/iot-03/automations
{
  "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": "WeapZf6D1qI6****",
    "t": 1635426480637,
    "success": true
}

Error code

For more information, see error code.

Details of trigger_rule

When trigger_type is deviceReport:

Parameter nameTypeDescriptionRequired
status_codeStringThe device instruction.Yes
comparatorStringThe comparator.Yes
status_valueObjectThe device instruction value.Yes

When trigger_type is timer:

Parameter nameTypeDescriptionRequired
timer_formatStringThe scheduled trigger time. Two formats are supported.
  • Specify the scheduled date in the format of [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 cyclic schedule in the format of [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 nameTypeDescriptionRequired
weather_codeStringThe weather code.Yes
comparatorStringThe comparator.Yes
weather_valueObjectThe value of the weather code.Yes

Details of execution_rule

When execution_type is delay:

Parameter nameTypeDescriptionRequired
delay_secondsLongThe delay time. The value range is 1 to 5 × 60 × 60. Unit: second.Yes

When execution_type is deviceIssue or deviceGroupIssue:

Parameter nameTypeDescriptionRequired
execution_idStringThe ID of the specified device or device group.Yes
function_codeStringThe instruction code of the specified device or device group.Yes
function_valueObjectThe instruction value of the specified device or device group.Yes

Details of precondition_trigger_rule

Parameter nameTypeDescriptionRequired
timer_formatStringThe timer format. The format is: [hour:min]-[hour:min] [day of month] [month] [day of week] [year]. For example, 09:30-18:00 * * 0,1,2,3,4,5,6 * (9:30 am to 6:00 pm every week)No