Home Assistant Control
Use Home Assistant REST API with a long-lived access token.
Requirements
For skill users (runtime)
bashcurljq- Home Assistant long-lived token (
HA_TOKEN) - Home Assistant public base URL (
HA_URL_PUBLIC)
For skill maintainers (packaging/validation)
python3pyyaml(required byskill-creatorvalidator/packager scripts)
Required environment variables
HA_TOKEN(required)HA_URL_PUBLIC(required; canonical target and fallback)- Optional URL behavior:
- if
HA_URL_LOCALis set (and noHA_URLoverride), local is tried first, then fallback toHA_URL_PUBLIC HA_URLis an explicit override (if set, used directly)
- if
Secrets handling (publish-safe)
- Keep keys/URLs in an external file, not in the skill folder.
- Set
HA_ENV_FILE=/absolute/path/to/file.envwhen you want file-based secret loading. - If
HA_ENV_FILEis not set, scripts only use environment variables already present in the shell. scripts/ha_call.shandscripts/self_check.shload env file only whenHA_ENV_FILEis provided.
Core workflow
- Parse the user request into target entity/service + desired action.
- Check
references/naming-context.mdfor manual alias mappings first. - Verify entity exists before changing state.
- Execute service call.
- Re-check state and report outcome clearly.
Useful endpoints
- List states:
GET /api/states - Single state:
GET /api/states/{entity_id} - Call service:
POST /api/services/{domain}/{service}
Headers:
Authorization: Bearer $HA_TOKENContent-Type: application/json
Scripts
scripts/ha_env.sh— loads env file only whenHA_ENV_FILEis explicitly set, using safe KEY=VALUE parsing (nosource/eval).scripts/ha_call.sh— generic API caller for Home Assistant.scripts/fill_entities_md.sh— generatereferences/entities.mdfromGET /api/states.- Full map:
./scripts/fill_entities_md.sh - Filter domains:
./scripts/fill_entities_md.sh --domains light,switch,climate,sensor
- Full map:
scripts/save_naming_context.sh— refreshreferences/naming-context.mdfor user-specific naming../scripts/save_naming_context.sh
scripts/ha_entity_find.sh— search entities by partial entity id or friendly name../scripts/ha_entity_find.sh kitchen./scripts/ha_entity_find.sh temp --domains sensor,climate --limit 30
scripts/ha_safe_action.sh— execute service actions with safety checks and risk confirmation../scripts/ha_safe_action.sh light turn_on light.kitchen '{"brightness_pct":60}'./scripts/ha_safe_action.sh lock unlock lock.front_door --dry-run- Add
--yesto bypass interactive confirmation for risky domains.
scripts/self_check.sh— verify prerequisites and API connectivity/auth before running actions../scripts/self_check.sh
Safety
- Confirm before high-impact actions (locks, alarms, garage/doors, heating shutdown).
- Do not print raw token values.
- If target entity is ambiguous, ask a follow-up question.
- Keep API paths scoped to Home Assistant endpoints only (
/api/...). - Use only HTTP(S) Home Assistant base URLs (
HA_URL*), prefer HTTPS for public access. - Avoid code execution when loading env files: parse key/value pairs, do not use
sourceon untrusted paths.
Reference files
references/entities.md— entity inventoryreferences/naming-context.md— user alias memory for natural names (e.g. "living room light")
Publishing notes
- Keep examples generic (
example_*IDs), no personal hostnames/tokens. - Do not commit
.envor any private env file with real tokens. - Keep the skill focused: API workflow + reusable scripts + entity reference.