概覽#
將 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 值並與控制家居操作一起使用,以針對特定房間。