名称: homebridge
描述: "通过 Homebridge Config UI X 的 REST API 控制智能家居设备。可用于列出、开关、调节亮度、颜色或色温等 HomeKit 兼容配件。支持灯、开关、温控器、风扇及其他由 Homebridge 管理的设备。"
主页: https://github.com/homebridge/homebridge-config-ui-x
元数据: { "clawdbot": { "emoji": "🏠" } }
通过 Homebridge Config UI X 的 REST API 控制智能家居设备。
~/.clawdbot/credentials/homebridge.json:json
{
"url": "https://homebridge.local:8581",
"username": "admin",
"password": "your-password"
}Homebridge Config UI X 提供 REST API。完整文档可在 {HOMEBRIDGE_URL}/swagger 查看。
所有 API 调用都需要 Bearer 令牌。请先获取令牌:
# 获取认证令牌
TOKEN=$(curl -s -X POST "${HOMEBRIDGE_URL}/api/auth/login" \
-H "Content-Type: application/json" \
-d "{\"username\":\"${HOMEBRIDGE_USERNAME}\",\"password\":\"${HOMEBRIDGE_PASSWORD}\"}" \
| jq -r '.access_token')
curl -s "${HOMEBRIDGE_URL}/api/accessories" \
-H "Authorization: Bearer ${TOKEN}" | jq
响应包含配件的 uniqueId、serviceName、type 及当前 values。
curl -s "${HOMEBRIDGE_URL}/api/accessories/layout" \
-H "Authorization: Bearer ${TOKEN}" | jq
使用 PUT 方法更新配件特性:
# 打开灯/开关
curl -s -X PUT "${HOMEBRIDGE_URL}/api/accessories/{uniqueId}" \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" \
-d '{"characteristicType": "On", "value": true}'
# 关闭
curl -s -X PUT "${HOMEBRIDGE_URL}/api/accessories/{uniqueId}" \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" \
-d '{"characteristicType": "On", "value": false}'
# 设置亮度 (0-100)
curl -s -X PUT "${HOMEBRIDGE_URL}/api/accessories/{uniqueId}" \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" \
-d '{"characteristicType": "Brightness", "value": 50}'
# 设置颜色 (色相: 0-360, 饱和度: 0-100)
curl -s -X PUT "${HOMEBRIDGE_URL}/api/accessories/{uniqueId}" \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" \
-d '{"characteristicType": "Hue", "value": 240}'
# 设置温控器目标温度
curl -s -X PUT "${HOMEBRIDGE_URL}/api/accessories/{uniqueId}" \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" \
-d '{"characteristicType": "TargetTemperature", "value": 22}'
| 类型 | 值范围 | 描述 |
|---|---|---|
On |
true/false |
电源状态 |
Brightness |
0-100 |
灯光亮度百分比 |
Hue |
0-360 |
色相角度 |
Saturation |
0-100 |
颜色饱和度百分比 |
ColorTemperature |
140-500 |
色温(Mired 值) |
TargetTemperature |
10-38 |
温控器目标温度(摄氏度) |
TargetHeatingCoolingState |
0-3 |
0=关, 1=加热, 2=制冷, 3=自动 |
RotationSpeed |
0-100 |
风扇速度百分比 |
Active |
0/1 |
激活状态(风扇等) |
为方便起见,可使用提供的脚本:
scripts/homebridge_api.py list
scripts/homebridge_api.py list --room "Living Room"
scripts/homebridge_api.py list --type Lightbulb
# 开关
scripts/homebridge_api.py set <uniqueId> On true
scripts/homebridge_api.py set <uniqueId> On false
# 调节亮度
scripts/homebridge_api.py set <uniqueId> Brightness 75
# 设置颜色
scripts/homebridge_api.py set <uniqueId> Hue 120
scripts/homebridge_api.py set <uniqueId> Saturation 100
scripts/homebridge_api.py get <uniqueId>
uniqueId/swagger 处的 API 文档展示了所有可用端点On 而非 on)