適用於 OpenClaw v2026.2 | 需要 Home Assistant 實例或智慧裝置,安裝
home-assistant技能。
TL;DR: 安裝技能 openclaw skill install home-assistant。設定連線:"url": "http://homeassistant.local:8123", "token": "..."。控制裝置:"開燈" → light.living_room.on。自動化場景:"scenes": [{"id": "morning", "schedule": "0 7 * * *"}]。能耗監控:查詢用電統計。安全監控:門窗感測器 + 移動偵測 + 異常告警。
實戰目標
建構一個能夠:
- 控制智慧家居裝置
- 建立自動化場景
- 語音控制家電
- 能耗監控與最佳化
- 安全監控提醒
的智慧家居控制中心。
安裝必要技能
# Home Assistant 技能
openclaw skill install home-assistant
# 智慧家居技能
openclaw skill install smart-home-io
# 天氣技能
openclaw skill install weather-api
Home Assistant 整合
設定連線
{
"skills": {
"home-assistant": {
"url": "http://homeassistant.local:8123",
"token": "${HOME_ASSISTANT_TOKEN}",
"entities": {
"lights": ["light.living_room", "light.bedroom"],
"climate": ["climate.living_room"],
"sensors": ["sensor.temperature", "sensor.humidity"],
"switches": ["switch.tv", "switch.air_purifier"]
}
}
}
}
裝置控制場景
使用者:打開客廳的燈
Agent:好的,正在打開客廳的燈...
[呼叫 Home Assistant API]
light.living_room → on
客廳的燈已打開。目前亮度 80%。
需要調整亮度嗎?
使用者:把冷氣調到 25 度
Agent:正在設定冷氣溫度...
[呼叫 climate API]
climate.living_room → 25°C
冷氣已設定為 25 度,模式:製冷。
目前室溫:28°C,預計 20 分鐘後達到目標溫度。
批次控制
使用者:我要睡覺了,把所有燈關掉
Agent:好的,晚安!
[批次控制裝置]
light.living_room → off
light.bedroom → off
light.kitchen → off
switch.tv → off
已關閉所有燈和電視。冷氣已調至睡眠模式(26°C)。
需要我設定明早的鬧鐘嗎?
自動化場景
場景設定
{
"scenes": [
{
"id": "morning",
"name": "早安模式",
"trigger": {
"type": "time",
"time": "07:00"
},
"actions": [
{ "entity": "light.bedroom", "action": "turn_on", "brightness": 30 },
{ "entity": "switch.coffee_machine", "action": "turn_on" },
{ "entity": "climate.living_room", "action": "set_temperature", "value": 22 }
]
},
{
"id": "leave_home",
"name": "離家模式",
"trigger": {
"type": "location",
"condition": "leave_home"
},
"actions": [
{ "entity": "group.all_lights", "action": "turn_off" },
{ "entity": "switch.tv", "action": "turn_off" },
{ "entity": "climate.home", "action": "turn_off" }
]
}
]
}
場景觸發
使用者:我出門了
Agent:啟動離家模式...
[觸發場景:leave_home]
離家模式已啟動:
- ✅ 關閉所有燈
- ✅ 關閉電視
- ✅ 關閉冷氣
- ✅ 啟動安防監控
預計回家時間?我可以幫你準備回家模式。
智慧場景
使用者:設定一個晚上回家的場景
Agent:好的,我來建立回家場景...
場景「回家模式」已建立:
- 觸發條件:位置到家 + 時間 18:00-23:00
- 動作:
1. 打開客廳燈(亮度 50%)
2. 打開冷氣(根據目前溫度自動選擇模式)
3. 播放歡迎語音
4. 啟動熱水器
還需要新增其他裝置嗎?
語音控制
語音指令對應
{
"voiceCommands": {
"開燈": { "action": "light.turn_on" },
"關燈": { "action": "light.turn_off" },
"調亮": { "action": "light.brightness_up" },
"調暗": { "action": "light.brightness_down" },
"打開冷氣": { "action": "climate.turn_on" },
"關閉冷氣": { "action": "climate.turn_off" }
}
}
自然語言控制
使用者:有點冷,把溫度調高一點
Agent:目前室溫 22°C,冷氣已關閉。
要打開冷氣並設定到幾度?
- 建議:24-25°C
- 舒適範圍:23-26°C
使用者:打開冷氣,設為 25 度
Agent:好的...
[climate.living_room → on, temperature: 25]
冷氣已打開,設定為 25°C 暖氣模式。
預計 15 分鐘後達到目標溫度。
能耗監控
能耗統計
使用者:今天的用電情況怎麼樣?
Agent:讓我查詢今天的能耗資料...
[取得能耗資料]
[分析使用情況]
## 今日能耗報告
### 總用電量
- 今日:12.5 kWh
- 昨日:14.2 kWh
- 節省:1.7 kWh (-12%)
### 裝置用電排行
1. 冷氣:5.2 kWh (42%)
2. 熱水器:3.1 kWh (25%)
3. 照明:1.8 kWh (14%)
4. 電視:1.2 kWh (10%)
5. 其他:1.2 kWh (9%)
### 用電建議
- 💡 冷氣溫度可調至 26°C,可節省約 20%
- 💡 熱水器可設定定時關閉
- 💡 使用 LED 燈替代傳統燈泡
### 尖峰時段
- 18:00-21:00 用電最高,建議錯峰使用大功率電器
需要我設定自動化節能場景嗎?
節能場景
{
"scenes": [
{
"id": "energy_saving",
"name": "節能模式",
"actions": [
{ "entity": "climate.home", "action": "set_temperature", "value": 26 },
{ "entity": "light.*", "action": "set_brightness", "value": 50 },
{ "entity": "switch.standby_devices", "action": "turn_off" }
]
}
]
}
安全監控
安全設定
{
"security": {
"sensors": {
"motion": ["binary_sensor.motion_living_room", "binary_sensor.motion_bedroom"],
"door": ["binary_sensor.door_main", "binary_sensor.door_back"],
"window": ["binary_sensor.window_bedroom", "binary_sensor.window_living"],
"camera": ["camera.living_room", "camera.door"]
},
"alerts": {
"motion_detected": {
"enabled": true,
"notify": true,
"record": true
},
"door_opened": {
"enabled": true,
"notify": true
}
}
}
}
安全提醒
使用者:我出門了,開啟安防模式
Agent:啟動安防模式...
[安防模式已啟動]
安防狀態:
- ✅ 門窗感測器:已啟用
- ✅ 移動偵測:已啟用
- ✅ 攝影機錄影:已啟用
- ✅ 異常通知:已啟用
我將監控以下內容:
- 門窗開關狀態
- 室內移動偵測
- 異常聲音偵測
如果偵測到異常,我會立即通知你。
異常處理
[告警觸發]
Agent:🚨 安全警報!
偵測到異常:
- 時間:2026-02-26 14:30:25
- 類型:門口移動偵測
- 裝置:camera.door
[附上門口攝影機截圖]
是否需要我:
1. 查看即時畫面
2. 報警
3. 通知家人
4. 開啟警示燈
請立即回覆!
自動化規則
規則設定
{
"automations": [
{
"id": "auto_lights_sunset",
"name": "日落自動開燈",
"trigger": {
"type": "sun",
"event": "sunset"
},
"actions": [
{ "entity": "light.living_room", "action": "turn_on", "brightness": 70 },
{ "entity": "light.hallway", "action": "turn_on", "brightness": 50 }
]
},
{
"id": "auto_climate_temp",
"name": "自動溫控",
"trigger": {
"type": "sensor",
"entity": "sensor.temperature",
"above": 28
},
"actions": [
{ "entity": "climate.living_room", "action": "turn_on" },
{ "entity": "climate.living_room", "action": "set_temperature", "value": 25 }
]
}
]
}
規則管理
使用者:建立一個規則:溫度超過 28 度自動開冷氣
Agent:好的,我來建立這個規則...
[建立自動化規則]
規則已建立:
- 名稱:自動溫控
- 觸發:溫度感測器 > 28°C
- 動作:打開冷氣,設定 25°C
是否還需要新增其他條件?
例如:
- 只在有人在時觸發
- 只在特定時段生效
- 傳送通知提醒
整合體驗
一天智慧生活
{
"dailyAutomations": [
{
"time": "07:00",
"name": "早安",
"actions": ["開燈 30%", "開冷氣 22°C", "開咖啡機"]
},
{
"time": "08:30",
"name": "離家",
"condition": "位置離家",
"actions": ["關所有燈", "關冷氣", "開啟安防"]
},
{
"time": "18:00",
"name": "回家準備",
"condition": "位置到家前 15 分鐘",
"actions": ["開客廳燈", "開冷氣", "啟動熱水器"]
},
{
"time": "22:00",
"name": "睡眠準備",
"actions": ["關客廳燈", "臥室燈 30%", "冷氣 26°C"]
},
{
"time": "23:00",
"name": "晚安",
"actions": ["關所有燈", "冷氣睡眠模式", "開啟安防"]
}
]
}
一鍵場景
使用者:我要看電影
Agent:啟動電影模式...
[電影模式已啟動]
- ✅ 客廳燈:調暗至 20%
- ✅ 窗簾:關閉
- ✅ 電視:打開
- ✅ 音響:切換到電影模式
- ✅ 冷氣:舒適溫度 24°C
需要我推薦電影嗎?
小結
透過 OpenClaw 建構智慧家居控制中心:
- 裝置控制:燈光、冷氣、家電
- 自動化場景:早安、離家、回家、睡眠
- 語音控制:自然語言指令
- 能耗監控:用電統計、節能建議
- 安全監控:門窗感測、移動偵測、異常告警
更新記錄:
- 2026-02-26:初版發布
系列導航:
- ← 上一篇:實戰:建構程式開發助手
- → 下一篇:實戰:建構團隊協作 Agent