Setup¶
Add the Integration¶
- Go to Settings > Devices & Services
- Click Add Integration
- Search for "OpenCode"
- A pairing code will be displayed (e.g.,
ABC12DEF)
The code is valid for 5 minutes.
Create Access Token¶
The OpenCode plugin needs a long-lived access token to connect.
- Click your profile name in the Home Assistant sidebar
- Scroll to "Long-Lived Access Tokens"
- Click "Create Token"
- Give it a name (e.g., "OpenCode")
- Copy the token immediately - it won't be shown again!
Pair from OpenCode¶
In your OpenCode session, use the ha_pair tool:
Pair with Home Assistant:
- URL: http://homeassistant.local:8123
- Access Token: <paste your token>
- Code: ABC12DEF
URL Options¶
You can use various URL formats:
| Type | Example |
|---|---|
| mDNS | http://homeassistant.local:8123 |
| IP Address | http://192.168.1.100:8123 |
| External (SSL) | https://your-ha.duckdns.org |
After Pairing¶
Once paired:
- Home Assistant shows the OpenCode instance as connected
- OpenCode displays a success notification
- Session entities appear automatically
The plugin stores credentials and will reconnect automatically in future sessions.
Re-pairing¶
If you need to re-pair (new token, different HA instance):
- In OpenCode, delete
~/.config/opencode/ha-config.json - In HA, remove the OpenCode integration
- Add the integration again to get a new pairing code
- Pair from OpenCode