Orchestrates access to the Home Assistant REST API for programmatic control of smart home devices...
This skill provides access to the Home Assistant REST API for building integrations, automating smart home devices, and managing Home Assistant instances programmatically.
| Task | Load Resource |
|---|---|
| Setting up authentication, understanding API basics, HTTP methods | resources/core-concepts.md |
| Querying entity states, updating states, monitoring changes | resources/state-management.md |
| Controlling lights, climate, locks, and other devices | resources/service-reference.md |
| Understanding light, switch, sensor, climate entity types | resources/entity-types.md |
| Server-side template queries, complex filters, aggregations | resources/templates.md |
| System configuration, component discovery, error logs | resources/system-config.md |
| Complete code examples, client libraries, patterns | resources/examples.md |
Identify what the user needs to accomplish:
Authentication & Setup?
resources/core-concepts.mdQuery or Monitor State?
resources/state-management.mdControl a Device?
resources/service-reference.md (then find entity type in resources/entity-types.md)Understand Entity Types?
resources/entity-types.mdComplex Query or Data Aggregation?
resources/templates.mdSystem Management or Discovery?
resources/system-config.mdPractical Working Example?
resources/examples.mdUse this decision tree to select the right API endpoint:
Do you need to...
โ
โโ GET INFORMATION?
โ โโ Get one entity's state? โ GET /api/states/{entity_id}
โ โโ Get all entity states? โ GET /api/states (then filter)
โ โโ Get configuration? โ GET /api/config
โ โโ List available services? โ GET /api/services
โ โโ Discover event types? โ GET /api/events
โ โโ Query historical data? โ GET /api/history/period/{timestamp}
โ โโ Get error log? โ GET /api/error_log
โ โโ Complex query/computation? โ POST /api/template
โ โโ Check system status? โ GET /api/
โ
โโ CONTROL A DEVICE?
โ โโ Light (on/off/brightness)? โ POST /api/services/light/{service}
โ โโ Switch? โ POST /api/services/switch/{service}
โ โโ Climate/thermostat? โ POST /api/services/climate/{service}
โ โโ Lock? โ POST /api/services/lock/{service}
โ โโ Cover/blinds? โ POST /api/services/cover/{service}
โ โโ Media player? โ POST /api/services/media_player/{service}
โ โโ Fan? โ POST /api/services/fan/{service}
โ โโ Camera? โ POST /api/services/camera/{service}
โ โโ Any service? โ POST /api/services/{domain}/{service}
โ
โโ MODIFY STATE (NOT FOR DEVICE CONTROL)?
โ โโ Create/update state? โ POST /api/states/{entity_id}
โ โโ Delete state? โ DELETE /api/states/{entity_id}
โ โโ Fire custom event? โ POST /api/events/{event_type}
โ
โโ MANAGE SYSTEM?
โโ Validate config? โ POST /api/config/core/check_config
โโ Reload config? โ POST /api/services/homeassistant/reload_core_config
โโ Restart Home Assistant? โ POST /api/services/homeassistant/restart
โโ Get components list? โ GET /api/components
โโ Update entity metadata? โ POST /api/services/homeassistant/update_entity
โโ Check error log? โ GET /api/error_log
Before Calling API:
During Execution:
After Execution:
# Get one light's state
GET /api/states/light.kitchen
# Get temperature reading
GET /api/states/sensor.temperature
# Get all lights
GET /api/states
# Then filter: .[] | select(.entity_id | startswith("light."))
Load: resources/state-management.md then resources/core-concepts.md for HTTP details
# Turn on light with brightness
POST /api/services/light/turn_on
{"entity_id": "light.kitchen", "brightness": 200}
# Turn off all lights
POST /api/services/light/turn_off
{"entity_id": "all"}
# Toggle switch
POST /api/services/switch/toggle
{"entity_id": "switch.coffee_maker"}
Load: resources/service-reference.md + resources/entity-types.md for specific parameters
Option 1: Multiple API calls (simple, high bandwidth)
GET /api/states/light.kitchen
GET /api/states/light.living_room
GET /api/states/light.bedroom
Option 2: Get all and filter (one call, parse locally)
GET /api/states
# Filter in client: select by entity_id prefix
Option 3: Server-side template (most efficient)
POST /api/template
{"template": "{{ states.light | selectattr('state', 'eq', 'on') | list | length }}"}
Load: resources/templates.md for advanced queries
# Bad: Multiple sequential API calls
POST /api/services/light/turn_on {"entity_id": "light.kitchen"}
POST /api/services/light/turn_on {"entity_id": "light.living_room"}
POST /api/services/light/turn_on {"entity_id": "light.bedroom"}
# Better: Array of entities in one call
POST /api/services/light/turn_on
{"entity_id": ["light.kitchen", "light.living_room", "light.bedroom"]}
# Best: Use Home Assistant script (for complex multi-step)
POST /api/services/script/turn_on
{"entity_id": "script.my_scene"}
Load: resources/examples.md for working code patterns
sensor.* - Numeric/text readingsbinary_sensor.* - On/off detectioncamera.* - Camera snapshotsLoad: resources/entity-types.md for attributes
light.* - Lights (on/off, brightness, color)switch.* - Switches (on/off)climate.* - Thermostats (temperature, mode)cover.* - Blinds, doors (open/close, position)lock.* - Locks (lock/unlock)fan.* - Fans (on/off, speed, oscillate)media_player.* - Media devices (play/pause, volume)Load: resources/entity-types.md then resources/service-reference.md
automation.* - Automations (trigger, turn on/off)script.* - Scripts (turn on/off)scene.* - Scenes (activate)group.* - Entity groupsperson.* - Location trackingdevice_tracker.* - Device trackinginput_* - Input helpersperson.* - "home" or "not_home"device_tracker.* - Location statesun.sun - "above_horizon" or "below_horizon"weather.* - Weather conditions| Domain | Service | Key Parameters |
|---|---|---|
| light | turn_on | entity_id, brightness, rgb_color, transition |
| light | turn_off | entity_id, transition |
| switch | turn_on | entity_id |
| switch | turn_off | entity_id |
| climate | set_temperature | entity_id, temperature, hvac_mode |
| climate | set_hvac_mode | entity_id, hvac_mode |
| cover | open_cover | entity_id |
| cover | set_cover_position | entity_id, position (0-100) |
| lock | lock | entity_id, code (optional) |
| lock | unlock | entity_id, code (optional) |
| fan | turn_on | entity_id, percentage, preset_mode |
| media_player | play_media | entity_id, media_content_id, media_content_type |
| notify | mobile_app_* | message, title, data |
| automation | trigger | entity_id |
| script | turn_on | entity_id |
| scene | turn_on | entity_id, transition |
Load: resources/service-reference.md for complete reference
{
"entity_id": "light.kitchen",
"state": "on",
"attributes": {...},
"last_changed": "...",
"last_updated": "...",
"context": {...}
}
{
"error": "Unauthorized",
"message": "Invalid authentication provided"
}
Solution: Check token, regenerate if needed
{
"error": "Entity not found",
"message": "No entity found for domain 'light' and name 'nonexistent'"
}
Solution: Verify entity_id exists, check spelling
{
"error": "Invalid JSON",
"message": "..."
}
Solution: Validate JSON syntax, required fields
Solution: Check HA error log, restart if needed
Load: resources/core-concepts.md for detailed error handling
import requests
class HomeAssistant:
def __init__(self, url, token):
self.url = url
self.headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
# State queries
def get_state(self, entity_id):
"""Load: state-management.md"""
return requests.get(f"{self.url}/api/states/{entity_id}",
headers=self.headers).json()
# Service calls
def turn_on_light(self, entity_id, brightness=None):
"""Load: service-reference.md + entity-types.md"""
data = {"entity_id": entity_id}
if brightness:
data["brightness"] = brightness
return requests.post(
f"{self.url}/api/services/light/turn_on",
headers=self.headers,
json=data
).json()
# Complex queries
def count_on_lights(self):
"""Load: templates.md"""
template = "{{ states.light | selectattr('state', 'eq', 'on') | list | length }}"
resp = requests.post(
f"{self.url}/api/template",
headers=self.headers,
json={"template": template}
)
return int(resp.json()['result'])
# Usage
ha = HomeAssistant("http://localhost:8123", "YOUR_TOKEN")
# Query state
kitchen = ha.get_state("light.kitchen")
print(f"Kitchen light: {kitchen['state']}")
# Control device
ha.turn_on_light("light.kitchen", brightness=200)
# Complex query
count = ha.count_on_lights()
print(f"{count} lights are on")
Load: resources/examples.md for complete working examples
| I want to... | Load Resource | Example |
|---|---|---|
| Understand how to authenticate | core-concepts.md | Getting access token |
| Query temperature or sensor value | state-management.md | GET /api/states/sensor.temp |
| Turn on a light | service-reference.md โ entity-types.md | POST /api/services/light/turn_on |
| Find devices with low battery | templates.md | Server-side template query |
| Understand light color options | entity-types.md | Brightness, RGB, HS color |
| Count how many lights are on | templates.md | selectattr filter |
| Check if config is valid | system-config.md | POST /api/config/core/check_config |
| Write working Python code | examples.md | Complete client implementation |
| Handle errors properly | core-concepts.md โ examples.md | Retry logic, error codes |
| Batch control multiple devices | service-reference.md โ examples.md | Array of entity_ids |
New to Home Assistant API?
resources/core-concepts.md - Understand authentication and basicsresources/state-management.md - Learn to query stateresources/service-reference.md - Learn to control devicesresources/examples.md - See working codeBuilding an integration?
resources/core-concepts.md - Error handling, timeoutsresources/examples.md - Client setup, retry logicresources/service-reference.md - Available operationsresources/templates.md - Complex queriesPower user optimizations?
resources/templates.md - Server-side queriesresources/system-config.md - Discovery, cachingresources/examples.md - Performance patternsNext Step: Identify your task above, load the appropriate resource file, and proceed with implementation.