ha-api

Integrate external applications with Home Assistant REST and WebSocket APIs.

Updated Jun 11, 2026
One-click install
npx skills add https://github.com/brillianodhiya/VisionScript --skill ha-api-brillianodhiya
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: ha-api
Source: https://github.com/brillianodhiya/VisionScript/tree/main/.agents/skills/ha-api
Command: npx skills add https://github.com/brillianodhiya/VisionScript --skill ha-api-brillianodhiya

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires requests, aiohttp, and includes references (resource) and assets (resource) components.

What problem does it solve? Integrating external applications with Home Assistant requires navigating authentication tokens, REST endpoint schemas, and WebSocket handshake lifecycles, where small mistakes like a missing Bearer prefix or a missed auth_required response cause silent failures and cryptic 401 or 404 errors. ## Core Features & Use Cases - REST API Integration: Query and update entity states, call services, fire events, retrieve history, and render templates through documented HTTP endpoints. - WebSocket Real-Time Communication: Establish persistent connections with proper auth handshake handling, subscribe to state_changed events, and call services with low latency. - Error Handling Patterns: Diagnose and recover from common failures including 401 token errors, 404 missing entities, 502 unavailable servers, and WebSocket auth timeouts. - Use Case: You are writing a Python script that turns on lights when your CI build fails. Use this Skill to set up a Long-Lived Access Token, call the light/turn_on service via the REST API, and subscribe to sensor events over WebSocket for real-time monitoring. ## Quick Start Ask the AI to write a Python script that authenticates with your Home Assistant instance and calls a service to turn on a specific light entity.

Frequently Asked Questions about ha-api

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I call a Home Assistant service from Python?▼

Call a Home Assistant service by sending a POST request to /api/services/{domain}/{service} with a Bearer token header and a JSON body containing entity_id and service parameters. The requests library handles this with response.raise_for_status() for error checking.

How to authenticate with the Home Assistant API?▼

Authenticate by creating a Long-Lived Access Token in Home Assistant under Settings, then include it in every request as an Authorization header with the exact prefix "Bearer ". For WebSocket connections, respond to the auth_required message within 10 seconds with an auth message containing the token.

Home Assistant REST API vs WebSocket API, which should I use?▼

Use the REST API for one-time requests, state queries, and occasional service calls since it is simpler over HTTP. Use the WebSocket API for real-time event subscriptions and continuous monitoring, where it offers lower latency around 50ms versus seconds for polling.

Why does my Home Assistant API request return 401 Unauthorized?▼

A 401 error means the access token is invalid, expired, or the Authorization header is missing the "Bearer " prefix with exact spacing. Create a new Long-Lived Access Token in Home Assistant Settings and verify the HA_TOKEN environment variable is set correctly.

Why does my Home Assistant WebSocket connection close immediately?▼

The connection closes when the client fails to respond to the auth_required message within 10 seconds or uses an incorrect path like /api/websocket/ with a trailing slash. Send the auth message with your token immediately upon receiving auth_required.

Can I use this approach to build Home Assistant automations or custom integrations?▼

No, this Skill covers external API integration only, not building automations inside Home Assistant or developing custom integrations. It is meant for external scripts and applications communicating with a running Home Assistant instance over HTTP or WebSocket.