Add Automation Scenes

Last Updated on : 2023-12-07 03:33:57download

Add automation scenes to the specified home.

API address

POST: /v1.0/homes/{home_id}/automations

Request parameter

Parameter nameTypeINRequiredDescription
home_idStringuritrueThe home ID.

Description of body

Parameter nameTypeINRequiredDescription
automation_idStringbodyfalseThe ID of the automation.
nameStringbodytrueThe name of the automation.
match_typeIntegerbodytrueMatching type.
  • 1: Any condition meets trigger.
  • 2: Trigger when all conditions are met.
backgroundStringbodytrueBackground picture.
conditionsListbodytrueThe collection of conditions.
actionsListbodytrueThe collection of actions.

Description of conditions

Parameter nameTypeINRequiredDescription
entity_idStringbodytrueID of the entity. This could be device ID, weather, temperature.
entity_typeIntegerbodytrueCondition object type.
  • 1: Device report
  • 3: Weather
  • 6: Timing trigger
  • 15: External common event trigger
order_numIntegerbodytrueThe sequence code cannot be repeated.
displayExprbodytrueThe calculation expression.

Description of actions

Parameter nameTypeINRequiredDescription
entity_idStringbodytrueThe object ID of the specified action.
action_executorStringbodytrueThe object type of the specified action. Valid values:
  • delay: Delayed an action.
  • device_issue: Send an instruction to a device.
  • device_group_issue: Send an instruction to a device group.
executor_propertyExecutorPropertybodytrueThe details of the specified action.

Description of display

Parameter nameTypeINRequiredDescription
codeStringbodyfalseThe code of the specified status. This parameter is required when entity_type is 1 or 3.If 'entity_type' is' 3 ', the value needs to be defined as one of the following values: $temp, $humidity, $condition, $pm25, $aqi, $windSpeed, $sunsetrise. For more detailed weather content, please check the weather code API
operatorStringbodyfalseThe comparison expression. This parameter is required when entity_type is 1 or 3. Valid values:
  • ==: equal to.
  • >: greater than.
  • <: less than.
valueObjectbodyfalseThe value of the specified status. This parameter is required when entity_type is 1 or 3.
dateStringbodyfalseThe date when the specified linkage rule is triggered.
timeStringbodyfalseThe time when the specified linkage rule is triggered.
loopsStringbodyfalseThe cycle when the specified linkage rule is triggered. The value is a seven-digit number consisting of 0 and 1. 0 means disabled and 1 means enabled. The first digit represents Sunday and the other digits represent Monday to Saturday sequentially. For example, 0011000 represents a scheduled task is executed every Tuesday and Wednesday.
timezone_idStringbodyfalseThe ID of the specified time zone.

Description of executor_property

Parameter nameTypeINRequiredDescription
$function_codeStringbodyfalseInstruction code. This parameter is required when 'action_executor' is' dpIssue 'or' deviceGroupDpIssue '. This parameter is a variable. The specific name should be the standard command code, such as switch_1, and the value value should be the standard command value, such as true.
hoursIntegerbodyfalseDelay time, unit: hour. This parameter is required when 'action_executor' is' delay '.
minutesIntegerbodyfalseDelay time, unit: minute. This parameter is required when 'action_executor' is' delay '.
secondsIntegerbodyfalseDelay time, in seconds. This parameter is required when 'action_executor' is' delay '.

Return parameter

Parameter nameTypeDescription
resultStringThe returned result automation ID.

Request example

POST: /v1.0/homes/242****/automations
{
  "conditions": [
    {
      "display": {
        "code": "switch_1",
        "operator": "==",
        "value": true,
        "time": "14:00",
        "timezone_id": "Asia/Shanghai"
      },
      "entity_id": "vdevo15725982542****",
      "entity_type": 1,
      "order_num": 1
    }
  ],
  "actions": [
    {
      "action_executor": "delay",
      "executor_property": {
        "hours": "0",
        "minutes": "0",
        "seconds": "5"
      }
    },
    {
      "action_executor": "dpIssue",
      "entity_id": "vdevo15725982542****",
      "executor_property": {
        "switch_1": true
      }
    }
  ],
  "background": "https://images.tuyacn.com/smart/rule/cover/bedr***.png",
  "match_type": 1,
  "name": "Automation Test"
}

Return example

{
    "tid": "2c1fc5cf7f4511ee82774ab24801****",
    "result": "ALAuMez3r2JM****",
    "t": 1699564556521,
    "success": true
}

Error code

For more information, see error code.