1
0
Fork
You've already forked hass-mcp
0
No description
Python 99.7%
Dockerfile 0.3%
Find a file
Tim Stoop df8b5e9163
All checks were successful
Docker Build & Push / Run Tests (push) Successful in 30s
Docker Build & Push / docker (push) Successful in 4m18s
Optimize Docker image with multi-stage build
- Switch from UV/Debian bookworm to python:3.12-slim base
- Use multi-stage build to exclude build tools from final image
- Pre-compile Python bytecode for faster container startup
- Add read-only filesystem support with PYTHONDONTWRITEBYTECODE
- Document read-only mode in README with example config
Reduces image size from 1.11GB to 180MB (84% reduction)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025年12月29日 10:37:45 +01:00
.forgejo/workflows Inline test steps in release workflow instead of workflow_call 2025年10月04日 23:51:27 +02:00
app Condense MCP tool docstrings and add timezone notes 2025年12月29日 09:42:06 +01:00
tests Add WebSocket fallback for error log search on HA 2025.11+ 2025年12月29日 09:19:16 +01:00
.dockerignore Migrate from GitHub to Codeberg 2025年09月25日 19:14:58 +02:00
.env.example Initial commit. 2025年03月16日 15:29:28 -03:00
.gitignore Add coverage files to .gitignore 2025年10月14日 13:53:14 +02:00
.pre-commit-config.yaml Fix call_service_tool pydantic validation error and add pre-commit hooks 2025年09月25日 18:39:46 +02:00
.python-version Initial commit. 2025年03月16日 15:29:28 -03:00
bandit-report.json Update dev dependencies and modernize code quality 2025年12月28日 11:50:15 +01:00
CLAUDE.md Add pagination support for history and error log commands 2025年10月14日 10:42:02 +02:00
docker-compose.yml Migrate from GitHub to Codeberg 2025年09月25日 19:14:58 +02:00
Dockerfile Optimize Docker image with multi-stage build 2025年12月29日 10:37:45 +01:00
LICENSE Initial commit. 2025年03月16日 15:29:28 -03:00
pyproject.toml Add WebSocket API support for error logs (HA 2025.11+ fix) 2025年12月28日 14:19:48 +01:00
README.md Optimize Docker image with multi-stage build 2025年12月29日 10:37:45 +01:00
requirements-lock.txt Upgrade transitive dependencies for security patches 2025年12月28日 12:01:51 +01:00
Taskfile.yml Migrate from GitHub to Codeberg 2025年09月25日 19:14:58 +02:00
uv.lock feat: add comprehensive CI/CD pipeline with test gates 2025年07月13日 10:50:46 -03:00

Hass-MCP

A Model Context Protocol (MCP) server for Home Assistant integration with Claude and other LLMs.

Note

: This is a fork of voska/hass-mcp originally created by Voska.

Overview

Hass-MCP enables AI assistants like Claude to interact directly with your Home Assistant instance, allowing them to:

  • Query the state of devices and sensors
  • Control lights, switches, and other entities
  • Get summaries of your smart home
  • Troubleshoot automations and entities
  • Search for specific entities
  • Create guided conversations for common tasks

Screenshots

Screenshot 2025年03月16日 at 15 48 01 Screenshot 2025年03月16日 at 15 50 59 Screenshot 2025年03月16日 at 15 49 26

Features

  • Entity Management: Get states, control devices, and search for entities
  • Domain Summaries: Get high-level information about entity types
  • Automation Support: List and control automations
  • Guided Conversations: Use prompts for common tasks like creating automations
  • Smart Search: Find entities by name, type, or state
  • Token Efficiency: Lean JSON responses to minimize token usage

Installation

Prerequisites

  • Home Assistant instance with Long-Lived Access Token
  • One of the following:
    • Docker (recommended)
    • Python 3.13+ and uv

Setting Up With Claude Desktop

  1. Pull the Docker image:

    docker pull codeberg.org/timstoop/hass-mcp:latest
    
  2. Add the MCP server to Claude Desktop:

    a. Open Claude Desktop and go to Settings b. Navigate to Developer > Edit Config c. Add the following configuration to your claude_desktop_config.json file:

    {
     "mcpServers": {
     "hass-mcp": {
     "command": "docker",
     "args": [
     "run",
     "-i",
     "--rm",
     "-e",
     "HA_URL",
     "-e",
     "HA_TOKEN",
     "codeberg.org/timstoop/hass-mcp"
     ],
     "env": {
     "HA_URL": "http://homeassistant.local:8123",
     "HA_TOKEN": "YOUR_LONG_LIVED_TOKEN"
     }
     }
     }
    }
    

    d. Replace YOUR_LONG_LIVED_TOKEN with your actual Home Assistant long-lived access token e. Update the HA_URL:

    • If running Home Assistant on the same machine: use http://host.docker.internal:8123 (Docker Desktop on Mac/Windows)
    • If running Home Assistant on another machine: use the actual IP or hostname

    f. Save the file and restart Claude Desktop

  3. The "Hass-MCP" tool should now appear in your Claude Desktop tools menu

Note

: If you're running Home Assistant in Docker on the same machine, you may need to add --network host to the Docker args for the container to access Home Assistant. Alternatively, use the IP address of your machine instead of host.docker.internal.

Running with Read-Only Filesystem (Security Hardening)

The container supports running with a read-only filesystem for improved security. Add these flags to your Docker args:

{
 "mcpServers": {
 "hass-mcp": {
 "command": "docker",
 "args": [
 "run",
 "-i",
 "--rm",
 "--read-only",
 "--tmpfs",
 "/tmp",
 "-e",
 "HA_URL",
 "-e",
 "HA_TOKEN",
 "codeberg.org/timstoop/hass-mcp"
 ],
 "env": {
 "HA_URL": "http://homeassistant.local:8123",
 "HA_TOKEN": "YOUR_LONG_LIVED_TOKEN"
 }
 }
 }
}

This prevents any runtime modifications to the container filesystem, as all Python bytecode is pre-compiled during the build.

uv/uvx

  1. Install uv on your system.

  2. Add the MCP server to Claude Desktop:

    a. Open Claude Desktop and go to Settings b. Navigate to Developer > Edit Config c. Add the following configuration to your claude_desktop_config.json file:

    {
     "mcpServers": {
     "hass-mcp": {
     "command": "uvx",
     "args": ["hass-mcp"],
     "env": {
     "HA_URL": "http://homeassistant.local:8123",
     "HA_TOKEN": "YOUR_LONG_LIVED_TOKEN"
     }
     }
     }
    }
    

    d. Replace YOUR_LONG_LIVED_TOKEN with your actual Home Assistant long-lived access token e. Update the HA_URL:

    • If running Home Assistant on the same machine: use http://host.docker.internal:8123 (Docker Desktop on Mac/Windows)
    • If running Home Assistant on another machine: use the actual IP or hostname

    f. Save the file and restart Claude Desktop

  3. The "Hass-MCP" tool should now appear in your Claude Desktop tools menu

Other MCP Clients

Cursor

  1. Go to Cursor Settings > MCP > Add New MCP Server
  2. Fill in the form:
    • Name: Hass-MCP
    • Type: command
    • Command:
      docker run -i --rm -e HA_URL=http://homeassistant.local:8123 -e HA_TOKEN=YOUR_LONG_LIVED_TOKEN codeberg.org/timstoop/hass-mcp
      
    • Replace YOUR_LONG_LIVED_TOKEN with your actual Home Assistant token
    • Update the HA_URL to match your Home Assistant instance address
  3. Click "Add" to save

Claude Code (CLI)

To use with Claude Code CLI, you can add the MCP server directly using the mcp add command:

Using Docker (recommended):

claude mcp add hass-mcp -e HA_URL=http://homeassistant.local:8123 -e HA_TOKEN=YOUR_LONG_LIVED_TOKEN -- docker run -i --rm -e HA_URL -e HA_TOKEN codeberg.org/timstoop/hass-mcp

Replace YOUR_LONG_LIVED_TOKEN with your actual Home Assistant token and update the HA_URL to match your Home Assistant instance address.

Usage Examples

Here are some examples of prompts you can use with Claude once Hass-MCP is set up:

  • "What's the current state of my living room lights?"
  • "Turn off all the lights in the kitchen"
  • "List all my sensors that contain temperature data"
  • "Give me a summary of my climate entities"
  • "Create an automation that turns on the lights at sunset"
  • "Help me troubleshoot why my bedroom motion sensor automation isn't working"
  • "Search for entities related to my living room"

Available Tools

Hass-MCP provides several tools for interacting with Home Assistant:

  • get_version: Get the Home Assistant version
  • get_entity: Get the state of a specific entity with optional field filtering
  • entity_action: Perform actions on entities (turn on, off, toggle)
  • list_entities: Get a list of entities with optional domain filtering and search
  • search_entities_tool: Search for entities matching a query
  • domain_summary_tool: Get a summary of a domain's entities
  • list_automations: Get a list of all automations
  • call_service_tool: Call any Home Assistant service
  • restart_ha: Restart Home Assistant
  • get_history: Get the state history of an entity
  • get_error_log: Get the Home Assistant error log

Prompts for Guided Conversations

Hass-MCP includes several prompts for guided conversations:

  • create_automation: Guide for creating Home Assistant automations based on trigger type
  • debug_automation: Troubleshooting help for automations that aren't working
  • troubleshoot_entity: Diagnose issues with entities
  • routine_optimizer: Analyze usage patterns and suggest optimized routines based on actual behavior
  • automation_health_check: Review all automations, find conflicts, redundancies, or improvement opportunities
  • entity_naming_consistency: Audit entity names and suggest standardization improvements
  • dashboard_layout_generator: Create optimized dashboards based on user preferences and usage patterns

Available Resources

Hass-MCP provides the following resource endpoints:

  • hass://entities/{entity_id}: Get the state of a specific entity
  • hass://entities/{entity_id}/detailed: Get detailed information about an entity with all attributes
  • hass://entities: List all Home Assistant entities grouped by domain
  • hass://entities/domain/{domain}: Get a list of entities for a specific domain
  • hass://search/{query}/{limit}: Search for entities matching a query with custom result limit

Development

Running Tests

uv run pytest tests/

License

MIT License