home-assistant
Home Assistant Control
This skill enables Claude to interact with a Home Assistant instance via its REST API — querying device states, controlling smart home devices, reviewing history, and working with automations.
Slash Command
When invoked via /home-assistant, ensure authentication is set up (see below), then ask the user what they'd like to do — for example: check device status, control lights, adjust the thermostat, view history, or manage automations.
Setup & Authentication
Configuration lives in ~/.config/home-assistant/.env. On first use, check if this file exists:
cat ~/.config/home-assistant/.env 2>/dev/null || echo "NOT_FOUND"
If the file exists, source it to load HA_URL and HA_TOKEN:
source ~/.config/home-assistant/.env
If the file doesn't exist, walk the user through setup:
- Explain what's needed: a Home Assistant URL and a Long-Lived Access Token
- Ask for their HA URL (e.g.,
http://192.168.1.100:8123orhttps://home.example.com) - Guide them to create a token: Go to their HA instance → Profile (bottom-left) → Security tab → scroll to "Long-Lived Access Tokens" → click "Create Token" → give it a name like "Claude" → copy the token
- Create the config:
mkdir -p ~/.config/home-assistant
cat > ~/.config/home-assistant/.env << 'EOF'
HA_URL="http://your-ha-address:8123"
HA_TOKEN="your_token_here"
EOF
chmod 600 ~/.config/home-assistant/.env
Replace the placeholder values with what the user provides. The chmod 600 ensures only the user can read the token.
After sourcing, verify connectivity:
source ~/.config/home-assistant/.env
curl -s -H "Authorization: Bearer $HA_TOKEN" "$HA_URL/api/"
Expected response: {"message": "API running."}. If it fails, check the URL and token with the user.
Workflow
Follow this general approach for any Home Assistant task:
1. Discover what's available
Before trying to control or query specific devices, find out what entities exist. Run the discovery script to get a formatted overview:
bash <skill-path>/scripts/discover_entities.sh
This lists all entities grouped by domain (lights, switches, sensors, etc.) with their current states. Use this output to map the user's natural language ("the kitchen light") to actual entity IDs (light.kitchen_ceiling).
If the user asks about a specific type of device, you can filter:
bash <skill-path>/scripts/discover_entities.sh light
bash <skill-path>/scripts/discover_entities.sh sensor
bash <skill-path>/scripts/discover_entities.sh climate
2. Query state
To check the current state of a specific entity:
curl -s -H "Authorization: Bearer $HA_TOKEN" \
-H "Content-Type: application/json" \
"$HA_URL/api/states/<entity_id>"
The response includes state (the primary value) and attributes (detailed properties like brightness, temperature, friendly name, etc.).
3. Take action (with confirmation)
Before performing any action that changes device state, describe what you're about to do and ask the user to confirm. This applies to all service calls — turning things on/off, locking/unlocking, adjusting temperatures, triggering scenes, etc. The reason: smart home actions affect the physical world and can't be undone with ctrl-z.
To call a service:
curl -s -X POST \
-H "Authorization: Bearer $HA_TOKEN" \
-H "Content-Type: application/json" \
-d '{"entity_id": "<entity_id>"}' \
"$HA_URL/api/services/<domain>/<service>"
Common examples:
- Turn on a light:
domain=light,service=turn_on, data can includebrightness(0-255),color_temp,rgb_color - Turn off a light:
domain=light,service=turn_off - Toggle a switch:
domain=switch,service=toggle - Set thermostat:
domain=climate,service=set_temperature, data includestemperature - Lock/unlock:
domain=lock,service=lockorunlock - Trigger a scene:
domain=scene,service=turn_on - Run a script:
domain=script,service=turn_on(or the script's entity name)
4. Review history
To see what happened with an entity over time:
curl -s -H "Authorization: Bearer $HA_TOKEN" \
"$HA_URL/api/history/period/<timestamp>?filter_entity_id=<entity_id>&end_time=<end_timestamp>&minimal_response"
Timestamps use ISO 8601 format (e.g., 2025-01-15T08:00:00+00:00). The minimal_response flag reduces payload size.
For the logbook (human-readable event log):
curl -s -H "Authorization: Bearer $HA_TOKEN" \
"$HA_URL/api/logbook/<timestamp>?entity=<entity_id>"
Working with automations
Home Assistant automations are entities in the automation domain. You can:
- List automations: Filter discovery output or query
/api/statesfor entities starting withautomation. - Trigger an automation: Call
automation/triggerservice - Enable/disable: Call
automation/turn_onorautomation/turn_off - View automation config: The entity's attributes contain the automation's configuration
To create or modify automations, you'd need to edit the HA configuration files directly (typically automations.yaml), which is outside the scope of the REST API. If the user asks for this, let them know and offer to help draft the YAML instead.
Rendering templates
Home Assistant supports Jinja2 templates for dynamic values. To evaluate a template:
curl -s -X POST \
-H "Authorization: Bearer $HA_TOKEN" \
-H "Content-Type: application/json" \
-d '{"template": "{{ states(\"sensor.temperature\") }}"}' \
"$HA_URL/api/template"
This is useful when the user wants computed values or complex state queries.
Error handling
- 401 Unauthorized: Token is invalid or expired. Ask the user to regenerate it.
- 404 Not Found: Entity doesn't exist. Run discovery to find the correct entity_id.
- 400 Bad Request: Usually means malformed service data. Check the service's expected parameters by querying
/api/services.
When a call fails, show the user the error response and suggest what to fix. Don't silently retry.
Tips for natural language mapping
Users will say things like "turn off the bedroom light" rather than giving you entity IDs. To handle this:
- Run discovery to get all entities
- Look at
friendly_nameattributes to match natural language to entity IDs - If ambiguous (multiple "bedroom" lights), ask the user which one they mean
- Cache the entity list mentally within the conversation — no need to re-discover every time
Reference
For the complete REST API endpoint reference (all endpoints, parameters, and response formats), read references/rest-api.md.
More from trtmn/agent-skills
self-improvement
Run the self-improvement agent to review this session and the ~/.learnings/ log files. Use this skill whenever the user explicitly asks to review learnings, promote entries to CLAUDE.md, do an end-of-session review, or analyze GitHub PRs/issues for recurring patterns. Also use when the user says "promote", "review learnings", "what have we learned", or "self-improvement". Do NOT use this skill just for logging — logging happens automatically without the skill (see Passive Logging below). This skill is specifically for the *review and promotion* workflow.
20cowsay
Generates an ASCII cow saying custom text. Use when the user wants "cowsay", "cow say", or a cow to say something.
12unifi-api
Query and control a UniFi network using the `unifi` CLI (a restish wrapper with 1Password auth) or the REST API as fallback. Use this skill whenever the user wants to manage their UniFi network — listing connected clients, blocking/unblocking devices, managing firewall policies, checking WAN health and speed test results, rebooting devices, managing VLANs or SSIDs, reading traffic stats, port forwarding, or any other UniFi network management task. Prefer the `unifi` CLI for Integration API endpoints; fall back to raw curl/python for legacy API endpoints. Trigger even if the user doesn't say "API" or "UniFi" — phrases like "check my network", "block that device", "show me who's connected", "add a firewall rule", "what's my WAN IP", "how's my internet speed", or "what's on the guest network" are all good triggers.
5homebrew-dev
Package and distribute macOS apps, fonts, CLI tools, and arbitrary files using Homebrew formulas and casks. Use this skill whenever the user wants to create a Homebrew formula or cask, set up a personal tap, package a macOS .app bundle, distribute fonts or pre-built binaries via brew, use `brew create`, bump a formula or cask to a new version, submit a package to homebrew-core or homebrew-cask, or publish anything with Homebrew — even if they just ask how to "make something installable with brew", "share my app through Homebrew", "update my formula", or "get my package into Homebrew".
5tailscale-policy-manager
>
5obsidian-cli
>
4