场景管理

更新时间:2025-05-30 01:56:03下载pdf

API List

请求方式 API 描述
GET /v1.0/osaas/rooms/{room_id}/scenes 获取房屋下的场景列表
POST /v1.0/osaas/rooms/{room_id}/scenes/{scene_id}/trigger 触发场景
GET /v1.0/osaas/rooms/{room_id}/scene/devices 获取房屋下支持场景的设备列表
POST /v1.0/osaas/rooms/{room_id}/scene 创建场景
PUT /v1.0/osaas/rooms/{room_id}/scenes/{scene_id} 修改场景
DELETE /v1.0/osaas/rooms/{room_id}/scenes/{scene_id} 删除场景

获取房屋下的场景列表

接口描述

调用该接口获取房屋下的场景列表

接口地址

GET /v1.0/osaas/rooms/{room_id}/scenes

请求参数

参数名 类型 参数类型 说明 是否必需
room_id String URI 房屋唯一标识

响应参数

参数名 类型 说明
code Integer 响应码(详情见错误码章节),成功时为空
success Boolean 是否成功:(true:成功,false:失败)
msg String 请求失败的信息,成功时为空
t Long 返回时间戳,13位
result Array 场景列表

result参数说明

参数名 类型 说明
scene_id String 场景唯一标识
scene_name String 场景名称
actions Array 动作列表

actions参数说明

参数名 类型 说明
entity_id String 执行动作实体
executor_property Object 执行动作参数
action_executor String 执⾏动作类别

action_executor 参数说明
action_executor 目前共支持5种动作,分别是 dpIssue、delay、ruleTrigger、ruleEnable、ruleDisable。其中delay不能作为最后一个动作,动作列表不能有两个以上delay动作。

action_executor executor_property entity_id 说明
dpIssue {dpCode: dpValue} 设备唯一标识 设备动作
delay {“hours”: “1”,“minutes”: “15”,“seconds”: “0”} delay 延迟动作。0<=hours<=4, 0<=minutes<=59, 0<=seconds<=59
ruleTrigger {} 场景实例唯一标识 场景触发动作
ruleEnable {} 自动化实例唯一标识 自动化启用动作
ruleDisable {} 自动化实例唯一标识 自动化禁用动作

请求示例

GET {url}/v1.0/osaas/rooms/12223333******/scenes

响应成功示例

{
    "result": [
        {
            "actions": [
                {
                    "action_executor": "delay",
                    "entity_id": "delay",
                    "executor_property": {
                        "hours": "1",
                        "minutes": "15",
                        "seconds": "0"
                    }
                },
                {
                    "action_executor": "ruleTrigger",
                    "entity_id": "rpdpIdoAFaRxxxx",
                    "executor_property": {}
                }
            ],
            "scene_id": "4UVVGIZl3C0xxxx",
            "scene_name": "场景1"
        },
        {
            "actions": [
                {
                    "action_executor": "delay",
                    "entity_id": "delay",
                    "executor_property": {
                        "hours": "1",
                        "minutes": "15",
                        "seconds": "0"
                    }
                },
                {
                    "action_executor": "ruleTrigger",
                    "entity_id": "QYrTIqDSs9xxxxxx",
                    "executor_property": {}
                }
            ],
            "scene_id": "rpdpIxxxxxRg2f53",
            "scene_name": "场景2"
        },
        {
            "actions": [
                {
                    "action_executor": "ruleTrigger",
                    "entity_id": "QYrTIqDxxxxx75B",
                    "executor_property": {}
                },
                {
                    "action_executor": "ruleEnable",
                    "entity_id": "twTwDL0xkP2QKxxx",
                    "executor_property": {}
                },
                {
                    "action_executor": "ruleDisable",
                    "entity_id": "RKWvgqpi7GRxxxx",
                    "executor_property": {}
                }
            ],
            "scene_id": "P1f2CDm5eYglgYnx",
            "scene_name": "场景,场景动作、自动化禁用"
        },
        {
            "actions": [
                {
                    "action_executor": "dpIssue",
                    "entity_id": "6c98351aa94de2xxxxx",
                    "executor_property": {
                        "switch_1": true
                    }
                }
            ],
            "scene_id": "QYrTIqDSs9xxxxx",
            "scene_name": "场景4"
        }
    ],
    "success": true,
    "t": 1641953957828
}

响应失败示例

{
  "code": 500,
  "msg": "system error,please contact the admin",
  "success": false,
  "t": 1561378856383
}

触发场景

接口描述

调用该接口触发场景

接口地址

POST /v1.0/osaas/rooms/{room_id}/scenes/{scene_id}/trigger

请求参数

参数名 类型 参数类型 说明 是否必需
room_id String URI 房屋唯一标识
scene_id String URI 场景唯一标识

响应参数

参数名 类型 说明
code Integer 响应码(详情见错误码章节),成功时为空
success Boolean 是否成功:(true:成功,false:失败)
msg String 请求失败的信息,成功时为空
t Long 返回时间戳,13位
result Boolean 返回结果

请求示例

POST {url}/v1.0/osaas/rooms/12223******/scenes/53IY3gE******/trigger

响应成功示例

{
  "success": true,
  "result": true,
  "t": 1566053034624
}

响应失败示例

{
  "code": 500,
  "msg": "system error,please contact the admin",
  "success": false,
  "t": 1561378856383
}

获取房屋下支持场景的设备列表

接口描述

调用该接口获取房屋下支持场景的设备列表

接口地址

GET /v1.0/osaas/rooms/{room_id}/scene/devices

请求参数

参数名 类型 参数类型 说明 是否必需
room_id String URI 房屋唯一标识
page_no Integer URL 页码(page_no>0)(默认为1)
page_size Integer URL 页条数(0<page_size<100)(默认为20)

响应参数

参数名 类型 说明
code Integer 响应码(详情见错误码章节),成功时为空
success Boolean 是否成功:(true:成功,false:失败)
msg String 请求失败的信息,成功时为空
t Long 返回时间戳,13位
result Object 设备分页结果

result参数说明

参数名 类型 说明
total Integer 总条数
page_no Integer 页码
page_size Integer 页条数
devices Arrays 设备列表

devices参数说明

参数名 类型 说明
device_id String 设备唯一标识
device_name String 设备名称
product_id String 产品唯一标识

请求示例

GET {url}/v1.0/osaas/rooms/12223******/scene/devices?page_no=1&page_size=20

响应成功示例

{
  "result": {
    "total": 1,
    "page_no": 1,
    "page_size": 20,
    "devices": [
      {
        "device_id": "vedo1234456",
        "device_name": "测试设备",
        "product_id": "r4567543dvbn"
      }
    ]
  },
  "success": true,
  "t": 1572936751228
}

响应失败示例

{
  "code": 500,
  "msg": "system error,please contact the admin",
  "success": false,
  "t": 1561378856383
}

创建场景

接口描述

调用该接口创建场景

接口地址

POST /v1.0/osaas/rooms/{room_id}/scene

请求参数

参数名 类型 参数类型 说明 是否必需
room_id String URI 房屋唯一标识
scene_name String BODY 场景名称
actions Arrays BODY 动作列表

actions 参数说明

参数名 类型 参数类型 说明 是否必需
entity_id String BODY 执行动作实体
executor_property Object BODY 执行动作参数
action_executor String BODY 执⾏动作类别

action_executor 参数说明
action_executor 目前共支持5种动作,分别是 dpIssue、delay、ruleTrigger、ruleEnable、ruleDisable。其中delay不能作为最后一个动作,动作列表不能有两个以上delay动作。

action_executor executor_property entity_id 说明
dpIssue {dpCode: dpValue} 设备唯一标识 设备动作
delay {“hours”: “1”,“minutes”: “15”,“seconds”: “0”} delay 延迟动作。0<=hours<=4, 0<=minutes<=59, 0<=seconds<=59
ruleTrigger {} 场景实例唯一标识 场景触发动作
ruleEnable {} 自动化实例唯一标识 自动化启用动作
ruleDisable {} 自动化实例唯一标识 自动化禁用动作

响应参数

参数名 类型 说明
code Integer 响应码(详情见错误码章节),成功时为空
success Boolean 是否成功:(true:成功,false:失败)
msg String 请求失败的信息,成功时为空
t Long 返回时间戳,13位
result String 场景唯一标识

请求示例

POST {url}/v1.0/osaas/rooms/1222333******/scene
{
  "scene_name": "添加场景测试",
  "actions": [
    {
      "executor_property": {
        "work_mode": "auto"
      },
      "action_executor": "dpIssue",
      "entity_id": "0120090568c63******"
    }
  ]
}

响应成功示例

{
  "success": true,
  "result": "11123823965053******",
  "t": 1566053034624
}

响应失败示例

{
  "code": 500,
  "msg": "system error,please contact the admin",
  "success": false,
  "t": 1561378856383
}

修改场景

接口描述

调用该接口修改场景

接口地址

PUT /v1.0/osaas/rooms/{room_id}/scenes/{scene_id}

请求参数

参数名 类型 参数类型 说明 是否必需
room_id String URI 房屋唯一标识
scene_id String URI 场景唯一标识
scene_name String BODY 场景名称
actions Arrays BODY 动作列表

actions 参数说明

参数名 类型 参数类型 说明 是否必需
entity_id String BODY 执行动作实体
executor_property Object BODY 执行动作参数
action_executor String BODY 执⾏动作类别

action_executor 参数说明
action_executor 目前共支持5种动作,分别是 dpIssue、delay、ruleTrigger、ruleEnable、ruleDisable。其中delay不能作为最后一个动作,动作列表不能有两个以上delay动作。

action_executor executor_property entity_id 说明
dpIssue {dpCode: dpValue} 设备唯一标识 设备动作
delay {“hours”: “1”,“minutes”: “15”,“seconds”: “0”} delay 延迟动作。0<=hours<=4, 0<=minutes<=59, 0<=seconds<=59
ruleTrigger {} 场景实例唯一标识 场景触发动作
ruleEnable {} 自动化实例唯一标识 自动化启用动作
ruleDisable {} 自动化实例唯一标识 自动化禁用动作

响应参数

参数名 类型 说明
code Integer 响应码(详情见错误码章节),成功时为空
success Boolean 是否成功:(true:成功,false:失败)
msg String 请求失败的信息,成功时为空
t Long 返回时间戳,13位
result Boolean 返回结果

请求示例

PUT {url}/v1.0/osaas/rooms/1222333******/scenes/53IY3gE******
{
  "scene_name": "修改场景测试",
  "actions": [
    {
      "executor_property": {
        "work_mode": "auto"
      },
      "action_executor": "dpIssue",
      "entity_id": "0120090568c6******"
    }
  ]
}

响应成功示例

{
  "success": true,
  "result": true,
  "t": 1566053034624
}

响应失败示例

{
  "code": 500,
  "msg": "system error,please contact the admin",
  "success": false,
  "t": 1561378856383
}

删除场景

接口描述

调用该接口删除场景

接口地址

DELETE /v1.0/osaas/rooms/{room_id}/scenes/{scene_id}

请求参数

参数名 类型 参数类型 说明 是否必需
room_id String URI 房屋唯一标识
scene_id String URI 场景唯一标识

响应参数

参数名 类型 说明
code Integer 响应码(详情见错误码章节),成功时为空
success Boolean 是否成功:(true:成功,false:失败)
msg String 请求失败的信息,成功时为空
t Long 返回时间戳,13位
result Boolean 返回结果

请求示例

DELETE {url}/v1.0/osaas/rooms/12223******/scenes/53IY3gE******

响应成功示例

{
  "success": true,
  "result": true,
  "t": 1566053034624
}

响应失败示例

{
  "code": 500,
  "msg": "system error,please contact the admin",
  "success": false,
  "t": 1561378856383
}

错误码

以下为该接口常见的业务异常,更多的异常错误,请参见全局错误码。

错误码 说明
500 系统错误