Unofficial Home Assistant Integration for OpenCode
Note: This is an unofficial community project and is not affiliated with, endorsed by, or supported by OpenCode or Anomaly. OpenCode branding is used in accordance with their brand guidelines.
A native Home Assistant integration for OpenCode, the AI coding assistant. Monitor and control your OpenCode sessions directly from Home Assistant.
Full Documentation | OpenCode Plugin
- Native Integration: Direct WebSocket connection to OpenCode - no MQTT broker required
- Secure Pairing: Simple pairing flow with one-time codes
- Session Monitoring: Track session state, model, tokens, cost, and activity
- Permission Handling: Approve or reject permission requests from Home Assistant
- Send Prompts: Send prompts to OpenCode from automations or the Lovelace card
- Auto-reconnect: Persistent connection with automatic reconnection
- Lovelace Card: Beautiful card for viewing and interacting with sessions
- Blueprints: Ready-to-use automations for mobile notifications
- Home Assistant 2024.1 or later
- OpenCode with the opencode-homeassistant plugin installed
- Open HACS in Home Assistant
- Go to "Integrations" section
- Click the three dots menu > "Custom repositories"
- Add
https://github.com/stephengolub/ha-opencodeas "Integration" - Search for "OpenCode" and install
- Restart Home Assistant
- Download the latest release
- Extract
custom_components/opencodeto your Home Assistantconfig/custom_components/folder - Copy
frontend/dist/opencode-card.jstoconfig/www/ - Restart Home Assistant
- Go to Settings > Devices & Services
- Click "Add Integration"
- Search for "OpenCode"
- A pairing code will be displayed (e.g.,
ABC12DEF)
In your OpenCode session, use the ha_pair tool:
Pair with Home Assistant using:
- URL: http://homeassistant.local:8123
- Access Token: <your long-lived access token>
- Code: ABC12DEF
To create a long-lived access token:
- Go to your Home Assistant profile (click your name in the sidebar)
- Scroll to "Long-Lived Access Tokens"
- Click "Create Token"
Add the card resource:
Via UI:
- Go to Settings > Dashboards
- Click the three dots menu > Resources
- Click "Add Resource"
- URL:
/local/opencode-card.js - Type: JavaScript Module
Via YAML (in configuration.yaml):
lovelace:
resources:
- url: /local/opencode-card.js
type: moduleCopy the blueprints to your Home Assistant config:
mkdir -p config/blueprints/automation/opencode
cp blueprints/automation/*.yaml config/blueprints/automation/opencode/Then reload automations in Developer Tools > YAML > Reload Automations.
The integration creates these entities for each OpenCode session:
| Entity | Type | Description |
|---|---|---|
sensor.*_state |
Sensor | Session state (idle, working, waiting_permission, error) |
sensor.*_session |
Sensor | Session title |
sensor.*_model |
Sensor | Current AI model |
sensor.*_current_tool |
Sensor | Currently executing tool |
sensor.*_input_tokens |
Sensor | Total input tokens used |
sensor.*_output_tokens |
Sensor | Total output tokens used |
sensor.*_cost |
Sensor | Total session cost |
sensor.*_last_activity |
Sensor | Last activity timestamp |
binary_sensor.*_permission_pending |
Binary Sensor | Permission request pending |
Send a prompt to an OpenCode session.
service: opencode.send_prompt
data:
session_id: ses_abc123
text: "Fix the bug in main.py"
agent: code # optionalRespond to a permission request.
service: opencode.respond_permission
data:
session_id: ses_abc123
permission_id: perm_xyz789
response: once # once, always, or rejectRequest session history (response sent via event).
service: opencode.get_history
data:
session_id: ses_abc123Request available agents (response sent via event).
service: opencode.get_agents
data:
session_id: ses_abc123The integration includes ready-to-use blueprints for common automations.
File: blueprints/automation/opencode_state_notifications.yaml
Sends mobile notifications when:
- A task completes (idle after working)
- Permission is required (with approve/reject buttons)
- An error occurs
Features:
- Configurable notification service
- Toggle notifications by type
- Detailed permission info (type, title, pattern)
- Android and iOS support
File: blueprints/automation/opencode_permission_response.yaml
Handles taps on notification action buttons:
- Extracts session and permission IDs
- Calls
opencode.respond_permissionservice - Works with both iOS and Android
Usage:
- Install both blueprints
- Create an automation from "State Notifications" blueprint
- Create an automation from "Permission Response" blueprint
- Configure your mobile notification service
Add the card to a dashboard:
type: custom:opencode-card
title: OpenCode Sessions| Option | Type | Default | Description |
|---|---|---|---|
title |
string | "OpenCode Sessions" | Card title |
device |
string | - | Device ID to pin to (shows detail view only) |
working_refresh_interval |
number | 10 | Auto-refresh interval when working |
Basic card:
type: custom:opencode-cardPinned to specific device:
type: custom:opencode-card
device: opencode_abc123def456The integration fires these events for automations:
| Event | Description |
|---|---|
opencode_state_change |
Session state changed |
opencode_permission_request |
New permission request (detailed info) |
opencode_history_response |
History response received |
opencode_agents_response |
Agents response received |
automation:
- alias: "OpenCode Permission Alert"
trigger:
- platform: event
event_type: opencode_permission_request
action:
- service: notify.mobile_app
data:
title: "{{ trigger.event.data.title }}"
message: >
Type: {{ trigger.event.data.type }}
Pattern: {{ trigger.event.data.pattern }}| State | Description |
|---|---|
idle |
Session is idle, waiting for input |
working |
AI is actively working |
waiting_permission |
Waiting for permission approval |
error |
An error occurred |
- Check that OpenCode is running with the plugin installed
- Verify your access token is valid
- Check Home Assistant logs for connection errors
- Verify the WebSocket connection is active (check integration status)
- Look for errors in Home Assistant logs
- Try restarting OpenCode and re-pairing
- Verify the resource is loaded (Developer Tools > Network)
- Check browser console for JavaScript errors
- Clear browser cache and reload
- Ensure both blueprints are installed
- Check that the notification service is correct
- Verify mobile app is connected to HA
# Frontend (Lovelace card)
npm install
npm run build
# Development with auto-rebuild
npm run devFull documentation is available at stephengolub.github.io/ha-opencode
- Installation
- Setup Guide
- Entities Reference
- Services Reference
- Lovelace Card
- Blueprints
- Automations
- Troubleshooting
- opencode-homeassistant - OpenCode plugin (required) (docs)
- OpenCode - AI coding assistant
MIT