- Gateway platform — subscribes to real-time state changes via WebSocket and responds to events
- Smart home tools — four LLM-callable tools for querying and controlling devices via the REST API
Setup
1. Create a Long-Lived Access Token
- Open your Home Assistant instance
- Go to your Profile (click your name in the sidebar)
- Scroll to Long-Lived Access Tokens
- Click Create Token, give it a name like “Mibyan”
- Copy the token
2. Configure Environment Variables
The
homeassistant toolset is automatically enabled when HASS_TOKEN is set. Both the gateway platform and the device control tools activate from this single token.3. Start the Gateway
Available Tools
Mibyan registers four tools for smart home control:ha_list_entities
List Home Assistant entities, optionally filtered by domain or area.
Parameters:
domain(optional) — Filter by entity domain:light,switch,climate,sensor,binary_sensor,cover,fan,media_player, etc.area(optional) — Filter by area/room name (matches against friendly names):living room,kitchen,bedroom, etc.
ha_get_state
Get detailed state of a single entity, including all attributes (brightness, color, temperature setpoint, sensor readings, etc.).
Parameters:
entity_id(required) — The entity to query, e.g.,light.living_room,climate.thermostat,sensor.temperature
ha_list_services
List available services (actions) for device control. Shows what actions can be performed on each device type and what parameters they accept.
Parameters:
domain(optional) — Filter by domain, e.g.,light,climate,switch
ha_call_service
Call a Home Assistant service to control a device.
Parameters:
domain(required) — Service domain:light,switch,climate,cover,media_player,fan,scene,scriptservice(required) — Service name:turn_on,turn_off,toggle,set_temperature,set_hvac_mode,open_cover,close_cover,set_volume_levelentity_id(optional) — Target entity, e.g.,light.living_roomdata(optional) — Additional parameters as a JSON object
Gateway Platform: Real-Time Events
The Home Assistant gateway adapter connects via WebSocket and subscribes tostate_changed events. When a device state changes and matches your filters, it’s forwarded to the agent as a message.
Event Filtering
Configure which events the agent sees in~/.mibyan/config.yaml under the Home Assistant platform’s extra section:
Event Formatting
State changes are formatted as human-readable messages based on domain:Agent Responses
Outbound messages from the agent are delivered as Home Assistant persistent notifications (viapersistent_notification.create). These appear in the HA notification panel with the title “Mibyan”.
Connection Management
- WebSocket with 30-second heartbeat for real-time events
- Automatic reconnection with backoff: 5s → 10s → 30s → 60s
- REST API for outbound notifications (separate session to avoid WebSocket conflicts)
- Authorization — HA events are always authorized (no user allowlist needed, since the
HASS_TOKENauthenticates the connection)
Security
The Home Assistant tools enforce security restrictions: Entity IDs are validated against the pattern^[a-z_][a-z0-9_]*\.[a-z0-9_]+$ to prevent injection attacks.
Example Automations
Morning Routine
Security Check
Reactive Automation (via Gateway Events)
When connected as a gateway platform, the agent can react to events:Troubleshooting
Environment variables not picked up. The adapter reads credentials from~/.mibyan/.env (auto-merged at startup) or
from config.yaml. Double-check the file lives under the active Mibyan profile
home and that there’s no stray quoting around the URL/token. Restart the gateway
after editing — env changes are only applied on process start.
REST auth failing (401 Unauthorized).
The token must be a Long-Lived Access Token created from your HA user profile
page (Profile → Security → Long-lived access tokens). Short-lived UI
session tokens won’t work. Also verify the base URL includes the scheme and
port (e.g. http://homeassistant.local:8123) and is reachable from the host
running Mibyan — curl -H "Authorization: Bearer <token>" <url>/api/ should
return {"message": "API running."}.
