Loading...
Loading...
Orchestrates access to the Home Assistant REST API for programmatic control of smart home devices. Routes requests to specialized resource files based on task type - authentication, state management, service calls, entity types, or advanced queries. Provides intelligent decision tables for selecting appropriate endpoints and managing integrations.
npx skill4agent add markpitt/claude-skills home-assistant-api| Task | Load Resource |
|---|---|
| Setting up authentication, understanding API basics, HTTP methods | |
| Querying entity states, updating states, monitoring changes | |
| Controlling lights, climate, locks, and other devices | |
| Understanding light, switch, sensor, climate entity types | |
| Server-side template queries, complex filters, aggregations | |
| System configuration, component discovery, error logs | |
| Complete code examples, client libraries, patterns | |
resources/core-concepts.mdresources/state-management.mdresources/service-reference.mdresources/entity-types.mdresources/entity-types.mdresources/templates.mdresources/system-config.mdresources/examples.mdDo 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# 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."))resources/state-management.mdresources/core-concepts.md# 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"}resources/service-reference.mdresources/entity-types.mdGET /api/states/light.kitchen
GET /api/states/light.living_room
GET /api/states/light.bedroomGET /api/states
# Filter in client: select by entity_id prefixPOST /api/template
{"template": "{{ states.light | selectattr('state', 'eq', 'on') | list | length }}"}resources/templates.md# 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"}resources/examples.mdsensor.*binary_sensor.*camera.*resources/entity-types.mdlight.*switch.*climate.*cover.*lock.*fan.*media_player.*resources/entity-types.mdresources/service-reference.mdautomation.*script.*scene.*group.*person.*device_tracker.*input_*person.*device_tracker.*sun.sunweather.*| 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 |
resources/service-reference.md{
"entity_id": "light.kitchen",
"state": "on",
"attributes": {...},
"last_changed": "...",
"last_updated": "...",
"context": {...}
}{
"error": "Unauthorized",
"message": "Invalid authentication provided"
}{
"error": "Entity not found",
"message": "No entity found for domain 'light' and name 'nonexistent'"
}{
"error": "Invalid JSON",
"message": "..."
}resources/core-concepts.mdimport 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")resources/examples.md| 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 |
resources/core-concepts.mdresources/state-management.mdresources/service-reference.mdresources/examples.mdresources/core-concepts.mdresources/examples.mdresources/service-reference.mdresources/templates.mdresources/templates.mdresources/system-config.mdresources/examples.md