本文介绍新增场景联动的 API。
接口描述
新增场景联动,满足条件时可以触发执行设备、设备群的动作,达到场景下的联动效果。
接口地址
POST: /v1.0/iot-03/automations
请求参数
body 说明
| 参数名 |
类型 |
参数位置 |
是否必填 |
说明 |
| name |
String |
|
true |
场景联动名称 |
| conditions |
List |
|
true |
触发条件 |
| actions |
List |
|
true |
执行动作 |
| match_type |
Integer |
|
true |
匹配类型:- 1:任意条件满足触发
- 2:全部条件满足触发
- 3:自定义条件触发,需设定相关逻辑运算参数condition_rule
|
| condition_rule |
String |
|
false |
自定义条件规则,当匹配类型 match_type=3,该参数必填。自定义条件规则遵从与或运算公式。每个自动化条件以其order_num为标识码。例如:c1 && c2 的表达式, c1, c2 分别表示 conditions 中 order_num 为 1 和 2 表达式的计算结果 |
| preconditions |
List |
|
false |
前置条件,优先级最高 |
preconditions 说明
| 参数名 |
类型 |
参数位置 |
是否必填 |
说明 |
| cond_type |
String |
|
true |
前置条件类型,当前仅支持时间段限制,固定为 timeCheck |
| display |
JSONObject |
|
true |
条件展示,参见 请求参数详细说明 |
conditions 说明
| 参数名 |
类型 |
参数位置 |
是否必填 |
说明 |
| entity_type |
Integer |
|
true |
条件类型: |
| display |
JSONObject |
|
true |
条件展示 |
| order_num |
Integer |
|
true |
条件排序,从 1 开始 |
| entity_id |
String |
|
true |
执行动作实体:- entity_type=1 时,entity_id 取值为设备 ID,必填
- entity_type=3 时,entity_id 取值为对应城市的 ID
- entity_type=6 时,entity_id 取值固定为 timer
|
actions 说明
| 参数名 |
类型 |
参数位置 |
是否必填 |
说明 |
| entity_id |
String |
|
true |
目标 ID:- action_executor=dpIssue 时,entity_id取值设备ID
- action_executor=deviceGroupDpIssue 时,entity_id取值群组ID
- action_executor=warnReport时,entity_id取值linkage_alarm
|
| executor_property |
List |
|
true |
执行动作参数,当action_executor=warnReport时,不用传 |
| action_executor |
String |
|
true |
执行动作类别:- dpIssue:设备动作
- deviceGroupDpIssue:设备群组动作
- warnReport:告警通知动作
|
executor_property 说明
| 参数名 |
类型 |
参数位置 |
是否必填 |
说明 |
| code |
String |
|
true |
指令 Code |
| value |
Object |
|
true |
指令 Value |
返回参数
| 参数名 |
类型 |
说明 |
| result |
String |
场景联动 ID |
请求示例
POST: /v1.0/iot-03/automations
{
"name": "xxx",
"match_type": 3,
"condition_rule": "c1||c2||c3",
"preconditions": [
{
"cond_type": "timeCheck",
"display": {
"start": "01:00",
"end": "23:00",
"time_interval": "custom",
"loops": "1111111",
"time_zone_id": "Asia/Shanghai"
}
}
],
"conditions": [
{
"entity_id": "vdevo33333333333333",
"entity_type": 1,
"order_num": 1,
"display": {
"code": "switch_led",
"operator": "==",
"value": true
}
},
{
"entity_id": "1001803662567473213",
"entity_type": 3,
"order_num": 2,
"display": {
"code": "sunsetrise",
"operator": "==",
"value": "sunset"
}
},
{
"entity_id": "timer",
"entity_type": 6,
"order_num": 3,
"display": {
"date": "20210616",
"loops": "1111111",
"time": "16:16",
"time_zone_id": "Asia/Shanghai"
}
}
],
"actions": [
{
"entity_id": "140433911111111111",
"action_executor": "deviceGroupDpIssue",
"executor_property": [
{
"code": "switch_led",
"value": true
}
]
},
{
"entity_id": "vdevo33333333333333",
"action_executor": "dpIssue",
"executor_property": [
{
"code": "bright_value",
"value": 50
}
]
}
]
}
返回示例
{
"result": "xxxxxx",
"t": 1111111111111,
"success": true
}
错误码
参考 错误码。
请求参数详细说明
Conditions 设备状态条件的 Display 说明
| 参数名 |
类型 |
说明 |
必填 |
| code |
String |
设备的 statusCode |
是 |
| operator |
String |
操作符,参见 Code的数据类型和操作符的映射说明 |
是 |
| value |
Object |
Code 的取值 |
是 |
Conditions 天气条件的 Display 说明
| 参数名 |
类型 |
说明 |
必填 |
| code |
String |
天气条件对应的 Key,例如温度 temp |
是 |
| operator |
String |
操作符,参见 Code的数据类型和操作符的映射说明 |
是 |
| value |
String |
天气条件对应的 Key 对应 Code 的取值 |
是 |
Conditions定时条件的 Display 说明
| 参数名 |
类型 |
说明 |
必填 |
| date |
String |
触发日期,格式为yyyyMMdd,例如20191125 |
是 |
| loops |
String |
由 0 和 1 组成的 7 位数字。0 表示不执行,1 表示执行。第 1 位为周日,依次表示周一至周六。例如,0011000表示每周二,周三执行 |
是 |
| time |
String |
触发时间,24 小时制,示例:14:00 |
是 |
| timezone_id |
String |
时区 ID,示例:Asia/Shanghai |
是 |
Preconditions 的 Display 说明
| 参数名 |
类型 |
说明 |
必填 |
| start |
String |
开始时间,time_interval=custom时自定义,其余默认00:00,24小时制 |
否 |
| end |
String |
结束时间,time_interval=custom时自定义,其余默认23:59,24小时制 |
否 |
| time_interval |
String |
custom:自定义;allDay:全天;daytime:白天;night:夜间 |
是 |
| loops |
String |
由 0 和 1 组成的 7 位数字。0 表示不执行,1 表示执行。第 1 位为周日,依次表示周一至周六。例如,0011000表示每周二,周三执行 |
是 |
| time_zone_id |
String |
时区 ID,示例:Asia/Shanghai |
是 |
Code 的数据类型和操作符的映射说明
| type |
operator |
| Boolean |
"==" |
| Integer |
">","==","<" |
| Enum |
"==" |