Add Linkage Rule

Last Updated on : 2023-11-23 06:37:48download

Create a linkage rule based on conditions and actions that are passed in.

API address

POST: /v2.0/cloud/scene/rule

Request parameter

Description of body

Parameter nameTypeINRequiredDescription
space_idStringbodytrueThe ID of the specified space that is associated with the linkage rule.
nameStringbodytrueThe name of the specified linkage rule.
typeStringbodytrueThe type of linkage. Valid values:
  • scene: tap-to-run.
  • automation: automation.
decision_exprStringbodytrueThe condition expression. Valid values:
  • and: AND.
  • or: OR.
  • c1&c2: custom expression.
conditionsListbodyfalseThe collection of conditions. This parameter is optional when the linkage type is tap-to-run, and required when the linkage type is automation.
actionsListbodytrueThe collection of actions.
effective_timeEffectiveTimebodyfalseThe time when the specified linkage rule takes effect.

Description of effective_time

Parameter nameTypeINRequiredDescription
startStringbodytrueThe start time.
endStringbodytrueThe end time.
loopsStringbodytrueThe 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.
time_zone_idStringbodytrueThe ID of the specified time zone.

Description of conditions

Parameter nameTypeINRequiredDescription
entity_idStringbodytrueThe object ID of the specified condition.
entity_typeStringbodytrueThe object type of the specified condition. Valid values:
  • timer: timer.
  • weather: weather condition.
  • device_report: data reporting by a device.
codeIntegerbodytrueThe unique code of the specified condition.
exprExprbodytrueThe 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 expr

Parameter nameTypeINRequiredDescription
status_codeStringbodytrueThe code of the specified status. This parameter is required when entity_type is device_report.
comparatorStringbodytrueThe comparison expression. This parameter is required when entity_type is device_report and weather. Valid values:
  • ==: equal to.
  • >: greater than.
  • <: less than.
status_valueObjectbodytrueThe value of the specified status. This parameter is required when entity_type is device_report.
dateStringbodyfalseThe date when the specified linkage rule is triggered.
timeStringbodytrueThe 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.
time_zone_idStringbodytrueThe ID of the specified time zone.
weather_codeStringbodytrueThe code of the specified status. This parameter is required when entity_type is weather.
weather_valueObjectbodytrueThe value of the specified status. This parameter is required when entity_type is weather.

Description of executor_property

Parameter nameTypeINRequiredDescription
function_codeStringbodytrueThe code of the specified instruction. This parameter is required when action_executor is device_issue or device_group_issue.
function_valueObjectbodytrueThe value of the specified instruction. This parameter is required when action_executor is device_issue or device_group_issue.
delay_secondsIntegerbodytrueThe delay time. This parameter is required when action_executor is delay.

Return parameter

Parameter nameTypeDescription
resultLinkageAddResponseThe returned result.

Description of result

Parameter nameTypeDescription
idStringThe ID of the specified linkage rule.

Request example

POST: /v2.0/cloud/scene/rule
{
  "space_id": "150***",
  "name": "Test Scene",
  "type": "automation",
  "decision_expr": "or",
  "effective_time": {
    "start": "00:00",
    "end": "23:00",
    "loops": "1111111",
    "timezone_id": "Asia/Shanghai"
  },
  "conditions": [
    {
      "code": 1,
      "entity_id": "****",
      "entity_type": "device_report",
      "expr": {
        "status_code": "switch_1",
        "comparator": "==",
        "status_value": true
      }
    }
  ],
  "actions": [
    {
      "entity_id": "****",
      "action_executor": "device_issue",
      "executor_property": {
        "function_code": "switch_1",
        "function_value": true
      }
    }
  ]
}

Return example

{
    "tid": "***",
    "result": {
        "id": "***"
    },
    "t": 1677742076308,
    "success": true
}

Error code

For more information, see error code.

Limits on API Request Frequency

For more information, see Limits on API Request Frequency.