Connect Claude Desktop to Home Assistant through the Home Assistant REST API.
This project includes:
- An MCP server in Python.
- A Python setup helper that updates Claude Desktop MCP config.
- A PowerShell setup helper that does the same.
| Tool | Description |
|---|---|
ha_get_config |
Get Home Assistant server details such as version, location, and units. |
ha_list_states |
List entity states, optionally filtered by domain. |
ha_get_state |
Get state and attributes for one entity. |
ha_call_service |
Call any Home Assistant service. |
ha_list_services |
List service definitions, optionally filtered by domain. |
ha_trigger_automation |
Trigger an automation by entity id. |
ha_get_history |
Get state history for an entity from 1 to 168 hours. |
ha_render_template |
Render Jinja2 templates through Home Assistant. |
ha_check_config |
Run Home Assistant configuration check. |
- Python 3.10 or newer.
- Home Assistant reachable from your machine.
- A Home Assistant Long Lived Access Token.
- Claude Desktop installed.
Install dependencies:
bash
pip install -r requirements.txt
OR
bash one-liner
pip install "mcp[cli]>=1.0.0" "httpx>=0.27.0" "pydantic>=2.0.0"
In Home Assistant:
- Click on Profile in lower left
- Click Security tab at the top
- Scroll to the bottom to 'Go to Long Lived Access Tokens'.
- Create a token and copy it. (Once you click ok, it can never been seen again)
You can use either helper script.
Script: setup_mcp.py
python setup_mcp.py --ha-token YOUR_TOKENOverride Home Assistant URL:
python setup_mcp.py --ha-url http://192.168.1.100:8123 --ha-token YOUR_TOKENPreview changes without writing:
python setup_mcp.py --ha-token YOUR_TOKEN --dry-runScript: Set-ClaudeMcp.ps1
.\Set-ClaudeMcp.ps1 -HaToken "YOUR_TOKEN"Override Home Assistant URL:
.\Set-ClaudeMcp.ps1 -HaUrl "http://192.168.1.100:8123" -HaToken "YOUR_TOKEN"Preview changes without writing:
.\Set-ClaudeMcp.ps1 -HaToken "YOUR_TOKEN" -WhatIfBoth setup scripts now use the same defaults:
HA_URLdefault ishttp://homeassistant.local:8123.- MCP server name default is
homeassistant. - Script path selection order:
./server.pyfrom the current working directory where setup is executed.server.pyin the same directory as the setup script.
- If
server.pyis still not found, you are prompted for a full path. - Existing Claude config is backed up before write.
Python setup helper:
--ha-urloverride Home Assistant URL.--ha-tokenpass token directly.--script-pathoverride detected server path.--server-nameset MCP server key in config.--dry-runpreview only.
PowerShell setup helper:
-HaUrloverride Home Assistant URL.-HaTokenpass token directly.-ServerScriptPathoverride detected server path.-McpServerNameset MCP server key in config.-WhatIfpreview only.
If you prefer to update Claude Desktop config manually:
{
"mcpServers": {
"homeassistant": {
"command": "python",
"args": ["C:/path/to/homeassistant-mcp/server.py"],
"env": {
"HA_URL": "http://homeassistant.local:8123",
"HA_TOKEN": "your_long_lived_token_here"
}
}
}
}On Windows, using a full Python executable path is also valid:
"command": "C:\\Python312\\python.exe"Set environment variables first.
Bash:
export HA_URL="http://homeassistant.local:8123"
export HA_TOKEN="your_long_lived_token_here"PowerShell:
$env:HA_URL = "http://homeassistant.local:8123"
$env:HA_TOKEN = "your_long_lived_token_here"Then run:
python server.pyDefault mode is stdio, which is what Claude Desktop expects.
If you need streamable HTTP transport, change the entry point in server.py:
mcp.run(transport="streamable_http", port=8001)Then expose it through your preferred reverse proxy or tunnel.
- Unauthorized 401:
- Regenerate a Home Assistant Long Lived Access Token.
- Make sure token value has no extra spaces.
- Connection refused:
- Verify
HA_URLpoints to a reachable host. - Confirm Home Assistant is running on that address and port.
- Verify
- Server script not found:
- Run setup from repo root so
./server.pyresolves. - Pass explicit path with
--script-pathor-ServerScriptPath.
- Run setup from repo root so
- Claude does not show the server:
- Restart Claude Desktop after setup.
- Confirm the config file includes
mcpServers.homeassistant.
- Treat Home Assistant token as a secret.
- Do not commit tokens to source control.
- Prefer local environment variables or local config only.
- Turn off all lights in the living room.
- What is the current state of
sensor.outdoor_temp. - Set thermostat to 70.
- Show front door sensor history for the last 6 hours.
- Trigger morning routine automation.