更新时间:2024-06-28 22:29:35下载pdf
本文介绍新增联动规则的 API。
根据传入的条件和动作等参数,创建联动规则。
POST: /v2.0/cloud/scene/rule
body 说明
| 参数名 | 类型 | 参数位置 | 是否必填 | 说明 | 
|---|---|---|---|---|
| space_id | String | body | true | 联动关联的空间 ID。 | 
| name | String | body | true | 联动规则的名称。 | 
| type | String | body | true | 联动类型。
  | 
| decision_expr | String | body | true | 条件表达式。
  | 
| conditions | List | body | false | 条件集合。联动类型为一键执行时不填,联动类型为自动化时必填。 | 
| actions | List | body | true | 动作集合。 | 
| effective_time | EffectiveTime | body | false | 联动规则生效时间。 | 
effective_time 说明
| 参数名 | 类型 | 参数位置 | 是否必填 | 说明 | 
|---|---|---|---|---|
| start | String | body | true | 开始时间。 | 
| end | String | body | true | 结束时间。 | 
| loops | String | body | true | 触发周期,由 0 和 1 组成的 7 位数字。0 表示不执行,1 表示执行。第 1 位为周日,依次表示周一至周六。例如,0011000 表示每周二,周三执行。 | 
| time_zone_id | String | body | true | 时区 ID。 | 
conditions 说明
| 参数名 | 类型 | 参数位置 | 是否必填 | 说明 | 
|---|---|---|---|---|
| entity_id | String | body | true | 条件对象 ID。 | 
| entity_type | String | body | true | 条件对象类型。
  | 
| code | Integer | body | true | 条件编码,不可重复。 | 
| expr | Expr | body | true | 计算表达式。 | 
actions 说明
| 参数名 | 类型 | 参数位置 | 是否必填 | 说明 | 
|---|---|---|---|---|
| entity_id | String | body | true | 动作对象 ID。 | 
| action_executor | String | body | true | 动作对象类型。
  | 
| executor_property | ExecutorProperty | body | true | 动作明细。 | 
expr 说明
| 参数名 | 类型 | 参数位置 | 是否必填 | 说明 | 
|---|---|---|---|---|
| status_code | String | body | true | 状态集 code。当 entity_type 是 device_report 时,此参数必填。 | 
| comparator | String | body | true | 比较表达式。当 entity_type 是 device_report 和 weather 时,此参数必填。
  | 
| status_value | Object | body | true | 状态集 value。当 entity_type 是 device_report 时,此参数必填。 | 
| date | String | body | false | 联动规则触发日期。 | 
| time | String | body | true | 联动规则触发时间。 | 
| loops | String | body | false | 触发周期,由 0 和 1 组成的 7 位数字。0 表示不执行,1 表示执行。第 1 位为周日,依次表示周一至周六。例如,0011000 表示每周二,周三执行。 | 
| time_zone_id | String | body | true | 时区 ID。 | 
| weather_code | String | body | true | 状态集 code。当 entity_type 是 weather 时,此参数必填。 | 
| weather_value | Object | body | true | 状态集 value。当 entity_type 是 weather 时,此参数必填。 | 
executor_property 说明
| 参数名 | 类型 | 参数位置 | 是否必填 | 说明 | 
|---|---|---|---|---|
| function_code | String | body | true | 指令 code。当 action_executor 是 device_issue 或 device_group_issue 时,此参数必填。 | 
| function_value | Object | body | true | 指令 value。当 action_executor 是 device_issue 或 device_group_issue 时,此参数必填。 | 
| delay_seconds | Integer | body | true | 延时时间。当 action_executor 是 delay 时,此参数必填。 | 
| 参数名 | 类型 | 说明 | 
|---|---|---|
| result | LinkageAddResponse | 返回结果。 | 
result 说明
| 参数名 | 类型 | 说明 | 
|---|---|---|
| id | String | 联动规则 ID。 | 
POST: /v2.0/cloud/scene/rule
{
  "space_id": "150***",
  "name": "测试场景",
  "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
      }
    }
  ]
}
{
    "tid": "***",
    "result": {
        "id": "***"
    },
    "t": 1677742076308,
    "success": true
}
参考 错误码。
参考 调用频率限制。
该内容对您有帮助吗?
是意见反馈该内容对您有帮助吗?
是意见反馈