Add Automation Scenes

Last Updated on : 2023-06-15 05:04:34

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 a specified automation.
dslAutomationDsl trueThe language of automation rules.
preconditionsPreconditions falseThe preconditions for a 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 automation condition matching rules. Valid values:
  • and: All conditions are met.
  • or: Any condition is met.
actionsList trueThe list of automation actions.

Description of conditions

Parameter nameTypeINRequiredDescription
trigger_typeString trueThe 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_idString trueThe 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_ruleObject trueThe condition trigger rule. See the details of trigger_rule.
rule_numInteger trueThe 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 nameTypeINRequiredDescription
execution_typeString trueThe execution type.
  • deviceIssue: sent by a device.
  • deviceGroupIssue: sent by a device group.
  • delay: delay action.
execution_ruleObject trueThe execution rule. See the details of execution_rule.

Return parameter

Parameter nameTypeDescription
resultStringThe automation ID.

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

  1. When trigger_type is deviceReport:
Parameter nameTypeDescriptionRequired
status_codeStringThe device instruction.Yes
comparatorStringThe comparator.Yes
status_valueObjectThe device instruction value.Yes
  1. When trigger_type is timer:
Parameter nameTypeDescriptionRequired
timer_formatStringThe 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
  1. 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

  1. When execution_type is delay:
Parameter nameTypeDescriptionRequired
delay_secondsLongThe delay time. The value range is 1 to 5 × 60 × 60. Unit: second.Yes
  1. When execution_type is deviceIssue or deviceGroupIssue:
Parameter nameTypeDescriptionRequired
execution_idStringThe ID of a specified device or device group.Yes
function_codeStringThe instruction code of a device or device group.Yes
function_valueObjectThe instruction value of a 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, 9:30-18:00 * * 0,1,2,3,4,5,6 * (9:30 am to 6:00 pm every week)No