homeassistant-mcp
Model Context Protocol Server for Home Assistant
The server uses the MCP protocol to share access to a local Home Assistant instance with an LLM application.
A powerful bridge between your Home Assistant instance and Language Learning Models (LLMs), enabling natural language control and monitoring of your smart home devices through the Model Context Protocol (MCP). This server provides a comprehensive API for managing your entire Home Assistant ecosystem, from device control to system administration.
Features
- ๐ฎ Device Control: Control any Home Assistant device through natural language
- ๐ Real-time Updates: Get instant updates through Server-Sent Events (SSE)
- ๐ค Automation Management: Create, update, and manage automations
- ๐ State Monitoring: Track and query device states
- ๐ Secure: Token-based authentication and rate limiting
- ๐ฑ Mobile Ready: Works with any HTTP-capable client
Real-time Updates with SSE
The server includes a powerful Server-Sent Events (SSE) system that provides real-time updates from your Home Assistant instance. This allows you to:
- ๐ Get instant state changes for any device
- ๐ก Monitor automation triggers and executions
- ๐ฏ Subscribe to specific domains or entities
- ๐ Track service calls and script executions
Quick SSE Example
See SSE_API.md for complete documentation of the SSE system.
Table of Contents
- Key Features
- Prerequisites
- Installation
- Configuration
- Development
- API Reference
- Natural Language Integration
- Troubleshooting
- Project Status
- Contributing
- Resources
- License
Key Features
Core Functionality ๐ฎ
- Smart Device Control
- ๐ก Lights: Brightness, color temperature, RGB color
- ๐ก๏ธ Climate: Temperature, HVAC modes, fan modes, humidity
- ๐ช Covers: Position and tilt control
- ๐ Switches: On/off control
- ๐จ Sensors & Contacts: State monitoring
- ๐ต Media Players: Playback control, volume, source selection
- ๐ช๏ธ Fans: Speed, oscillation, direction
- ๐ Locks: Lock/unlock control
- ๐งน Vacuums: Start, stop, return to base
- ๐น Cameras: Motion detection, snapshots
System Management ๐ ๏ธ
- Add-on Management
- Browse available add-ons
- Install/uninstall add-ons
- Start/stop/restart add-ons
- Version management
- Configuration access
- Package Management (HACS)
- Integration with Home Assistant Community Store
- Multiple package types support:
- Custom integrations
- Frontend themes
- Python scripts
- AppDaemon apps
- NetDaemon apps
- Version control and updates
- Repository management
- Automation Management
- Create and edit automations
- Advanced configuration options:
- Multiple trigger types
- Complex conditions
- Action sequences
- Execution modes
- Duplicate and modify existing automations
- Enable/disable automation rules
- Trigger automation manually
Architecture Features ๐๏ธ
- Intelligent Organization
- Area and floor-based device grouping
- State monitoring and querying
- Smart context awareness
- Historical data access
- Robust Architecture
- Comprehensive error handling
- State validation
- Secure API integration
- TypeScript type safety
- Extensive test coverage
Prerequisites
- Node.js 20.10.0 or higher
- NPM package manager
- Docker Compose for containerization
- Running Home Assistant instance
- Home Assistant long-lived access token (How to get token)
- HACS installed for package management features
- Supervisor access for add-on management
Installation
Basic Setup
Docker Setup (Recommended)
The project includes Docker support for easy deployment and consistent environments across different platforms.
- Clone the repository:Copy
- Configure environment:Edit theCopy
.env
file with your Home Assistant configuration:Copy - Build and run with Docker Compose:Copy
- Verify the installation:
The server should now be running at
http://localhost:3000
. You can check the health endpoint athttp://localhost:3000/health
. - Update the application:Copy
Docker Configuration
The Docker setup includes:
- Multi-stage build for optimal image size
- Health checks for container monitoring
- Volume mounting for environment configuration
- Automatic container restart on failure
- Exposed port 3000 for API access
Docker Compose Environment Variables
All environment variables can be configured in the .env
file. The following variables are supported:
HASS_HOST
: Your Home Assistant instance URLHASS_TOKEN
: Long-lived access token for Home AssistantHASS_SOCKET_URL
: WebSocket URL for Home AssistantPORT
: Server port (default: 3000)NODE_ENV
: Environment (production/development)DEBUG
: Enable debug mode (true/false)
Configuration
Environment Variables
Configuration Files
- Development: Copy
.env.example
to.env.development
- Production: Copy
.env.example
to.env.production
- Testing: Copy
.env.example
to.env.test
Adding to Claude Desktop (or other clients)
To use your new Home Assistant MCP server, you can add Claude Desktop as a client. Add the following to the configuration. Note this will run the MCP within claude and does not work with the Docker method.
API Reference
Device Control
Common Entity Controls
Light Control
Add-on Management
List Available Add-ons
Install Add-on
Manage Add-on State
Package Management
List HACS Packages
Install Package
Automation Management
Create Automation
Duplicate Automation
Core Functions
State Management
Manages the current state of the system.
Example Request:
Context Updates
Updates the current context with new information.
Example Request:
Action Endpoints
Execute Action
Executes a specified action with given parameters.
Example Request:
Batch Actions
Executes multiple actions in sequence.
Example Request:
Query Functions
Get Available Actions
Returns a list of all available actions.
Example Response:
Context Query
Retrieves context information.
Example Response:
WebSocket Events
The server supports real-time updates via WebSocket connections.
Supported Events
state_change
: Emitted when system state changescontext_update
: Emitted when context is updatedaction_executed
: Emitted when an action is completederror
: Emitted when an error occurs
Example Event Data:
Error Handling
All endpoints return standard HTTP status codes:
- 200: Success
- 400: Bad Request
- 401: Unauthorized
- 403: Forbidden
- 404: Not Found
- 500: Internal Server Error
Error Response Format:
Rate Limiting
The API implements rate limiting to prevent abuse:
- 100 requests per minute per IP for regular endpoints
- 1000 requests per minute per IP for WebSocket connections
When rate limit is exceeded, the server returns:
Example Usage
Using curl
Using JavaScript
Development
Troubleshooting
Common Issues
- Node.js Version (
toSorted is not a function
)- Solution: Update to Node.js 20.10.0+
Copy - Connection Issues
- Verify Home Assistant is running
- Check
HASS_HOST
accessibility - Validate token permissions
- Ensure WebSocket connection for real-time updates
- Add-on Management Issues
- Verify Supervisor access
- Check add-on compatibility
- Validate system resources
- HACS Integration Issues
- Verify HACS installation
- Check HACS integration status
- Validate repository access
- Automation Issues
- Verify entity availability
- Check trigger conditions
- Validate service calls
- Monitor execution logs
Project Status
โ Complete
- Entity, Floor, and Area access
- Device control (Lights, Climate, Covers, Switches, Contacts)
- Add-on management system
- Package management through HACS
- Advanced automation configuration
- Basic state management
- Error handling and validation
- Docker containerization
- Jest testing setup
- TypeScript integration
- Environment variable management
- Home Assistant API integration
- Project documentation
๐ง In Progress
- WebSocket implementation for real-time updates
- Enhanced security features
- Tool organization optimization
- Performance optimization
- Resource context integration
- API documentation generation
- Multi-platform desktop integration
- Advanced error recovery
- Custom prompt testing
- Enhanced macOS integration
- Type safety improvements
- Testing coverage expansion
Contributing
- Fork the repository
- Create a feature branch
- Implement your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
Resources
License
MIT License - See LICENSE file
This server cannot be installed
Access Home Assistant data and control devices (lights, switches, thermostats, etc).
- Features
- Real-time Updates with SSE
- Table of Contents
- Key Features
- Prerequisites
- Installation
- Configuration
- API Reference
- Development
- Troubleshooting
- Project Status
- Contributing
- Resources
- License