Skip to content

设备控制 ​

接口 ​

POST https://hotel.chintiot.com/client/room/control
Content-Type: application/json
X-Beancomm-Client-Token: <房间控制 token>
X-Beancomm-Client-Unionid: <用户 unionid>

/client/* 接口使用房间控制凭证(非 Authorization: Bearer)。缺少任一头部返回 LACK_OF_HEADERS。依据 service-lightsmart-hapi/src/utils/auth.js:93-112(app.js:38 将 auth.client 挂载到 /client)。

请求体 ​

json
{
  "ci": { "room_id": 123 },
  "action": "turn_on",
  "mac": "001122334455",
  "payload": { "index": 0 },
  "_ip": "1.2.3.4",
  "ts": 1693900000000
}
字段类型必填说明
ci.room_idnumber是房间 ID
actionstring是动作类型(见下表)
macstring条件设备 MAC(12 位 hex),passthrough/execute_scene/control_lock 不需要
payloadobject条件动作参数(见下表)
_ipstring否调用方 IP(写入 InfluxDB 日志)
tsnumber否时间戳(control_lock 必填)

action + payload 完整对照表 ​

开关类 ​

action适用设备 typepayload说明
turn_on1/2/4/9/22{ index: 0 }开。subtype>0 时 index 指定子按键
turn_on5(窗帘){ deltaValue: { value: 50 } }开到指定位置(可选)
turn_on10(温控)—开空调
turn_on10(红外){ type: "infrared_tv" }红外开电视/机顶盒
turn_off同上同上关

窗帘 ​

actionpayload说明
open_curtain{ position: 50 }开窗帘,position 可选(0-100)
close_curtain{ position: 50 }关窗帘
stop_curtain—停止窗帘

调光灯 ​

actionpayload说明
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 }降低子灯亮度

色温 ​

actionpayload说明
set_colour_temperature{ value: 50 }设置色温
increase_colour_temperature{ value: 10 }增加色温
decrease_colour_temperature{ value: 10 }降低色温

温控器 ​

actionpayload说明
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

红外(电视/机顶盒) ​

actionpayload说明
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(机顶盒)

场景与透传 ​

actionpayload说明
execute_scene{ scene_id: 5 }执行场景
passthrough{ message: "533004..." }直接发送 hex 指令

门锁 ​

actionpayload说明
control_lock{ index: 0, action: "open" }开门锁。index 指定门锁序号,ts 必填

设备 type 数字代码 ​

type设备说明
1零火开关
2单火开关
4智能灯
5窗帘电机
9插卡取电
10温控器/红外payload.type 区分子类型
22集控亮度灯hapi deviceTypeArr[22]='smart_light_c';「插卡取电」为 type 9

响应 ​

json
{
  "code": 0,
  "data": {}
}

处理流程 ​

  1. 根据 ci.room_id 查房间,获取 room_token
  2. 根据 room_token 查网关设备,获取 server_id、api_version、module_code
  3. 从房间 device_info 中按 mac 查找目标设备
  4. 根据 action + 设备 type 调用 genCommand() 生成 BLE Mesh hex 指令
  5. 通过 MQTT 发布到 {topicL1}/{room_token}/ble_in
  6. 网关执行 BLE Mesh 指令,上报状态到 ble_out
  7. hapi 解析状态,更新 Redis

修订记录 ​

  • 2026-09-26 代码回源修正:
    • 认证头:Authorization: Bearer <token> → X-Beancomm-Client-Token + X-Beancomm-Client-Unionid(依据 hapi/src/utils/auth.js:93-112)。Bearer / X-SH-* 属用户态接口。
    • type 22:「插卡」→ 集控亮度灯(smart_light_c)(依据 hapi/src/common/device.js:2、ztutil/src/protocol.js:20-40)。
  • 说明(未改):本接口(hapi /client/room/control)的窗帘 action 确实只有 open_curtain / close_curtain / stop_curtain(依据 hapi/src/controller/client/room.js:289-316)。reverse_curtain / clear_curtain / turn_on_all / turn_off_all 仅存在于 ztUtil SDK(controlDevice),不属于本 REST 接口,故未添加。