Smart Home (Home Assistant) Integration
Role
You help the user control their smart home devices through Home Assistant's REST API. Turn lights on/off, adjust thermostats, check sensor states, and run automations. Keywords: "turn on light", "turn off light", "smart home", "home assistant", "開燈", "關燈", "關冷氣", "開冷氣", "set temperature", "溫度", "device", "sensor"
Setup
The user needs:
- A running Home Assistant instance (local or Nabu Casa cloud)
- A long-lived access token: HA > Profile > Long-Lived Access Tokens > Create Token
- Configure in MobileClaw Settings:
- HA URL: e.g.,
http://192.168.1.100:8123orhttps://xxxxx.ui.nabu.casa - HA Token: the long-lived access token
- HA URL: e.g.,
API Configuration
- Base URL:
{HA_URL}/api - Required headers on every request:
Authorization: Bearer {HA_TOKEN}Content-Type: application/json
Standard Workflows
Check API Connection
Verify Home Assistant is reachable.
- Use http tool:
http GET {HA_URL}/api/ Headers: Authorization: Bearer {HA_TOKEN} - Should return
{"message": "API running."}
List All Devices and States
Get current state of all entities.
- Use http tool:
http GET {HA_URL}/api/states Headers: Authorization: Bearer {HA_TOKEN} - Response is an array of entity objects, each with:
entity_id: e.g.,light.living_room,switch.fan,climate.bedroomstate: e.g., "on", "off", "21.5", "unavailable"attributes: brightness, color_temp, friendly_name, etc.
- Filter by domain prefix to find specific device types:
- Lights:
light.* - Switches:
switch.* - Climate/AC:
climate.* - Sensors:
sensor.* - Covers/blinds:
cover.* - Media players:
media_player.*
- Lights:
- Present a summary: device name, current state, key attributes
Get Single Device State
- Use http tool:
Example:http GET {HA_URL}/api/states/{entity_id} Headers: Authorization: Bearer {HA_TOKEN}http GET {HA_URL}/api/states/light.living_room - Returns full state object with attributes
Turn On a Light
- Use http tool:
http POST {HA_URL}/api/services/light/turn_on Headers: Authorization: Bearer {HA_TOKEN}, Content-Type: application/json Body: {"entity_id": "light.living_room"} - With brightness (0-255) and color:
http POST {HA_URL}/api/services/light/turn_on Headers: Authorization: Bearer {HA_TOKEN}, Content-Type: application/json Body: { "entity_id": "light.living_room", "brightness": 200, "color_temp": 350 } - With RGB color:
Body: { "entity_id": "light.bedroom_strip", "rgb_color": [255, 150, 50], "brightness": 180 }
Turn Off a Light
- Use http tool:
http POST {HA_URL}/api/services/light/turn_off Headers: Authorization: Bearer {HA_TOKEN}, Content-Type: application/json Body: {"entity_id": "light.living_room"}
Toggle a Switch
- Turn on:
http POST {HA_URL}/api/services/switch/turn_on Headers: Authorization: Bearer {HA_TOKEN}, Content-Type: application/json Body: {"entity_id": "switch.bedroom_fan"} - Turn off:
http POST {HA_URL}/api/services/switch/turn_off Headers: Authorization: Bearer {HA_TOKEN}, Content-Type: application/json Body: {"entity_id": "switch.bedroom_fan"} - Toggle (flip current state):
http POST {HA_URL}/api/services/switch/toggle Headers: Authorization: Bearer {HA_TOKEN}, Content-Type: application/json Body: {"entity_id": "switch.bedroom_fan"}
Set Air Conditioner / Climate Temperature
- Set target temperature:
http POST {HA_URL}/api/services/climate/set_temperature Headers: Authorization: Bearer {HA_TOKEN}, Content-Type: application/json Body: { "entity_id": "climate.living_room_ac", "temperature": 24 } - Set HVAC mode (cool, heat, auto, off):
http POST {HA_URL}/api/services/climate/set_hvac_mode Headers: Authorization: Bearer {HA_TOKEN}, Content-Type: application/json Body: { "entity_id": "climate.living_room_ac", "hvac_mode": "cool" } - Turn off AC:
http POST {HA_URL}/api/services/climate/set_hvac_mode Headers: Authorization: Bearer {HA_TOKEN}, Content-Type: application/json Body: { "entity_id": "climate.living_room_ac", "hvac_mode": "off" }
Control Covers (Blinds/Curtains)
- Open:
http POST {HA_URL}/api/services/cover/open_cover Headers: Authorization: Bearer {HA_TOKEN}, Content-Type: application/json Body: {"entity_id": "cover.living_room_blinds"} - Close:
http POST {HA_URL}/api/services/cover/close_cover Headers: Authorization: Bearer {HA_TOKEN}, Content-Type: application/json Body: {"entity_id": "cover.living_room_blinds"} - Set position (0=closed, 100=open):
http POST {HA_URL}/api/services/cover/set_cover_position Headers: Authorization: Bearer {HA_TOKEN}, Content-Type: application/json Body: {"entity_id": "cover.living_room_blinds", "position": 50}
Run an Automation or Script
- Trigger automation:
http POST {HA_URL}/api/services/automation/trigger Headers: Authorization: Bearer {HA_TOKEN}, Content-Type: application/json Body: {"entity_id": "automation.good_night_routine"} - Run script:
http POST {HA_URL}/api/services/script/turn_on Headers: Authorization: Bearer {HA_TOKEN}, Content-Type: application/json Body: {"entity_id": "script.movie_mode"}
Read Sensor Data
- Get a sensor value (temperature, humidity, power, etc.):
http GET {HA_URL}/api/states/sensor.living_room_temperature Headers: Authorization: Bearer {HA_TOKEN} - Response
statefield contains the value,attributes.unit_of_measurementhas the unit - Common sensors: temperature, humidity, power_consumption, door/window (binary_sensor), motion (binary_sensor)
Guidelines
- Entity IDs follow the pattern
{domain}.{object_id}, e.g.,light.kitchen,climate.bedroom_ac - If the user says a device name like "living room light", search the states list for matching friendly_name
- Always confirm destructive actions (e.g., turning off all lights, locking doors)
- If HA is unreachable, check if the user is on the same network (for local installs)
- Common entity_id prefixes to know: light, switch, climate, cover, media_player, sensor, binary_sensor, automation, script, fan, lock, vacuum
- Temperature units depend on HA config (Celsius or Fahrenheit) — check
attributes.unit_of_measurement - If an entity is "unavailable", the device may be offline or disconnected