概述#
将 PocketHook 用作聊天界面来控制您的智能家居设备。您的服务器根据您的消息决定控制哪些设备,并触发相应的 iOS Shortcut。
服务器命令#
向您的服务器发送 lights on 或 lights off。
服务器响应#
{
"msg": "Turning on lights...",
"shortcut": "ToggleLights",
"data": { "state": "on" }
}
所需的 iOS Shortcut#
ToggleLights#
- Shortcut 输入 — 从 PocketHook 接收数据
- 获取字典值 — 提取
state键 - 如果 state 等于 “on”:
- 控制家居 → 开灯
- 否则:
- 控制家居 → 关灯
服务器代码 (router.ts)#
case "lights on":
return toResponse(
shortcut("Turning on lights...", "ToggleLights", { state: "on" })
);
case "lights off":
return toResponse(
shortcut("Turning off lights...", "ToggleLights", { state: "off" })
);
进阶:按房间控制#
使用房间参数扩展:
case "bedroom lights":
return toResponse(
shortcut("Bedroom lights...", "ToggleLights", {
state: "on",
room: "bedroom"
})
);
在 Shortcut 中,提取 room 值并与控制家居操作一起使用,以针对特定房间。