Add Scene Template

Last Updated on : 2023-06-15 05:07:48

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

API address

POST: /v1.0/iot-03/scene-templates

Request parameter

Description of body

Parameter nameTypeINRequiredDescription
nameString trueThe name of a specified scene template.
descString trueThe description of a specified scene template.
dslObject trueThe rule language of a specified scene template.
preconditionsObject falseThe preconditions of a specified scene template.

Description of preconditions

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

Description of dsl

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

Description of conditions

Parameter nameTypeINRequiredDescription
trigger_typeString trueThe condition trigger type. Valid values:
  • categoryReport: It is triggered when a specified category 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 categoryReport, trigger_id is the category 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 in conditions.
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. Valid values:
  • categoryIssue: sent by a specified category.
  • delay: delay action.
execution_ruleObject trueThe execution rule. See the details of execution_rule.

Return parameter

Parameter nameTypeDescription
resultLongThe ID of a specified scene template.

Request example

POST: /v1.0/iot-03/scene-templates
{
  "dsl": {
    "actions": [
      {
        "execution_rule": {
          "execution_id": "fskg",
          "function_code": "switch_fan",
          "function_value": true
        },
        "execution_type": "categoryIssue"
      }
    ],
    "conditions": [
      {
        "rule_num": 1,
        "trigger_id": "dj",
        "trigger_rule": {
          "comparator": "==",
          "status_code": "switch_led",
          "status_value": true
        },
        "trigger_type": "categoryReport"
      },
      {
        "rule_num": 2,
        "trigger_id": "793409547065757***",
        "trigger_rule": {
          "comparator": "<",
          "weather_code": "temp",
          "weather_value": 20
        },
        "trigger_type": "weather"
      },
      {
        "rule_num": 3,
        "trigger_id": "timer",
        "trigger_rule": {
          "timer_format": "20:59 5 5 * 2021"
        },
        "trigger_type": "timer"
      }
    ],
    "conditions_rule": "or"
  },
  "name": "Test 1",
  "desc": "The first weather timer template",
  "preconditions": {
    "trigger_rule": {
      "timer_format": "00:00-23:59 * * 0,1,2,3,4,5,6 *"
    },
    "trigger_type": "timeCheck"
  }
}

Return example

{
    "result": "19**1007",
    "t": 1636546481484,
    "success": true
}

Error code

For more information, see error code.

Details of trigger_rule in conditions

  1. When trigger_type is categoryReport:
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 categoryIssue:
Parameter nameTypeDescriptionRequired
execution_idStringThe ID of a specified category.Yes
function_codeStringThe instruction code of a category.Yes
function_valueObjectThe instruction value of a category.Yes

Details of trigger_rule in preconditions

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)Yes