设备控制
接口
POST https://hotel.chintiot.com/client/room/control
Content-Type: application/json
Authorization: Bearer <token>请求体
json
{
"ci": { "room_id": 123 },
"action": "turn_on",
"mac": "001122334455",
"payload": { "index": 0 },
"_ip": "1.2.3.4",
"ts": 1693900000000
}| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
ci.room_id | number | 是 | 房间 ID |
action | string | 是 | 动作类型(见下表) |
mac | string | 条件 | 设备 MAC(12 位 hex),passthrough/execute_scene/control_lock 不需要 |
payload | object | 条件 | 动作参数(见下表) |
_ip | string | 否 | 调用方 IP(写入 InfluxDB 日志) |
ts | number | 否 | 时间戳(control_lock 必填) |
action + payload 完整对照表
开关类
| action | 适用设备 type | payload | 说明 |
|---|---|---|---|
turn_on | 1/2/4/9/22 | { index: 0 } | 开。subtype>0 时 index 指定子按键 |
turn_on | 5(窗帘) | { deltaValue: { value: 50 } } | 开到指定位置(可选) |
turn_on | 10(温控) | — | 开空调 |
turn_on | 10(红外) | { type: "infrared_tv" } | 红外开电视/机顶盒 |
turn_off | 同上 | 同上 | 关 |
窗帘
| action | payload | 说明 |
|---|---|---|
open_curtain | { position: 50 } | 开窗帘,position 可选(0-100) |
close_curtain | { position: 50 } | 关窗帘 |
stop_curtain | — | 停止窗帘 |
调光灯
| action | payload | 说明 |
|---|---|---|
set_brightness | { brightness: 80 } | 设置亮度百分比(0-100) |
increase_brightness | { brightness: 10 } | 增加亮度 |
decrease_brightness | { brightness: 10 } | 降低亮度 |
set_sub_brightness | { index: 1, brightness: 80 } | 设置子灯亮度 |
increase_sub_brightness | { index: 1, brightness: 10 } | 增加子灯亮度 |
decrease_sub_brightness | { index: 1, brightness: 10 } | 降低子灯亮度 |
色温
| action | payload | 说明 |
|---|---|---|
set_colour_temperature | { value: 50 } | 设置色温 |
increase_colour_temperature | { value: 10 } | 增加色温 |
decrease_colour_temperature | { value: 10 } | 降低色温 |
温控器
| action | payload | 说明 |
|---|---|---|
set_ac_temperature | { temperature: 26 } | 设置空调温度 |
increase_ac_temperature | { temperature: 1 } | 增加温度 |
decrease_ac_temperature | { temperature: 1 } | 降低温度 |
set_ac_mode | { mode: "cold" } | 模式: cold/warm/fan/auto |
set_fan_speed | { speed: "high" } | 风速: high/middle/low/auto |
红外(电视/机顶盒)
| action | payload | 说明 |
|---|---|---|
increase_volume | { type: "infrared_tv" } | 音量+ |
decrease_volume | { type: "infrared_tv" } | 音量- |
increase_channel | { type: "infrared_tv" } | 频道+ |
decrease_channel | { type: "infrared_tv" } | 频道- |
set_volume_mute | { type: "infrared_tv" } | 静音 |
type 可选值: infrared_tv(电视)、infrared_box(机顶盒)
场景与透传
| action | payload | 说明 |
|---|---|---|
execute_scene | { scene_id: 5 } | 执行场景 |
passthrough | { message: "533004..." } | 直接发送 hex 指令 |
门锁
| action | payload | 说明 |
|---|---|---|
control_lock | { index: 0, action: "open" } | 开门锁。index 指定门锁序号,ts 必填 |
设备 type 数字代码
| type | 设备 | 说明 |
|---|---|---|
| 1 | 零火开关 | |
| 2 | 单火开关 | |
| 4 | 智能灯 | |
| 5 | 窗帘电机 | |
| 9 | 插卡取电 | |
| 10 | 温控器/红外 | payload.type 区分子类型 |
| 22 | 插卡 |
响应
json
{
"code": 0,
"data": {}
}处理流程
- 根据
ci.room_id查房间,获取room_token - 根据
room_token查网关设备,获取server_id、api_version、module_code - 从房间
device_info中按mac查找目标设备 - 根据
action+ 设备type调用genCommand()生成 BLE Mesh hex 指令 - 通过 MQTT 发布到
{topicL1}/{room_token}/ble_in - 网关执行 BLE Mesh 指令,上报状态到
ble_out - hapi 解析状态,更新 Redis
