# Model Context Protocol Server for Home Assistant *Forked from [tevonsb/homeassistant-mcp](https://github.com/tevonsb/homeassistant-mcp)* 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. ![License](https://img.shields.io/badge/license-MIT-blue.svg) ![Node.js](https://img.shields.io/badge/node-%3E%3D20.10.0-green.svg) ![Docker Compose](https://img.shields.io/badge/docker-compose-%3E%3D1.27.0-blue.svg) ![NPM](https://img.shields.io/badge/npm-%3E%3D7.0.0-orange.svg) ![TypeScript](https://img.shields.io/badge/typescript-%5E5.0.0-blue.svg) ![Test Coverage](https://img.shields.io/badge/coverage-95%25-brightgreen.svg) ## Table of Contents - [Key Features](#key-features) - [Prerequisites](#prerequisites) - [Installation](#installation) - [Basic Setup](#basic-setup) - [Docker Setup (Recommended)](#docker-setup-recommended) - [Configuration](#configuration) - [Development](#development) - [API Reference](#api-reference) - [Device Control](#device-control) - [Add-on Management](#add-on-management) - [Package Management](#package-management) - [Automation Management](#automation-management) - [Natural Language Integration](#natural-language-integration) - [Troubleshooting](#troubleshooting) - [Project Status](#project-status) - [Contributing](#contributing) - [Resources](#resources) - [License](#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](https://community.home-assistant.io/t/how-to-get-long-lived-access-token/162159)) - **HACS** installed for package management features - **Supervisor** access for add-on management ## Installation ### Basic Setup ```bash # Clone the repository git clone https://github.com/jango-blockchained/homeassistant-mcp.git cd homeassistant-mcp # Install dependencies npm install # Build the project npm run build ``` ### Docker Setup (Recommended) 1. **Clone and prepare:** ```bash git clone -b docker https://github.com/jango-blockchained/homeassistant-mcp.git cd homeassistant-mcp cp .env.example .env ``` 2. **Configure environment `.env` file:** ```env # Home Assistant Configuration HASS_HOST=http://homeassistant.local:8123 HASS_TOKEN=your_home_assistant_token HASS_SOCKET_URL=ws://homeassistant.local:8123/api/websocket # Server Configuration PORT=3000 NODE_ENV=production ``` 3. **Launch with Docker Compose:** ```bash docker-compose up -d ``` ## API Reference ### Device Control #### Common Entity Controls ```json { "tool": "control", "command": "turn_on", // or "turn_off", "toggle" "entity_id": "light.living_room" } ``` #### Light Control ```json { "tool": "control", "command": "turn_on", "entity_id": "light.living_room", "brightness": 128, "color_temp": 4000, "rgb_color": [255, 0, 0] } ``` ### Add-on Management #### List Available Add-ons ```json { "tool": "addon", "action": "list" } ``` #### Install Add-on ```json { "tool": "addon", "action": "install", "slug": "core_configurator", "version": "5.6.0" } ``` #### Manage Add-on State ```json { "tool": "addon", "action": "start", // or "stop", "restart" "slug": "core_configurator" } ``` ### Package Management #### List HACS Packages ```json { "tool": "package", "action": "list", "category": "integration" // or "plugin", "theme", "python_script", "appdaemon", "netdaemon" } ``` #### Install Package ```json { "tool": "package", "action": "install", "category": "integration", "repository": "hacs/integration", "version": "1.32.0" } ``` ### Automation Management #### Create Automation ```json { "tool": "automation_config", "action": "create", "config": { "alias": "Motion Light", "description": "Turn on light when motion detected", "mode": "single", "trigger": [ { "platform": "state", "entity_id": "binary_sensor.motion", "to": "on" } ], "action": [ { "service": "light.turn_on", "target": { "entity_id": "light.living_room" } } ] } } ``` #### Duplicate Automation ```json { "tool": "automation_config", "action": "duplicate", "automation_id": "automation.motion_light" } ``` ## Development ```bash # Development mode with hot reload npm run dev # Build project npm run build # Production mode npm run start # Run tests npx jest --config=jest.config.cjs # Run tests with coverage npx jest --coverage # Lint code npm run lint # Format code npm run format ``` ## Troubleshooting ### Common Issues 1. **Node.js Version (`toSorted is not a function`)** - **Solution:** Update to Node.js 20.10.0+ ```bash nvm install 20.10.0 nvm use 20.10.0 ``` 2. **Connection Issues** - Verify Home Assistant is running - Check `HASS_HOST` accessibility - Validate token permissions - Ensure WebSocket connection for real-time updates 3. **Add-on Management Issues** - Verify Supervisor access - Check add-on compatibility - Validate system resources 4. **HACS Integration Issues** - Verify HACS installation - Check HACS integration status - Validate repository access 5. **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 1. Fork the repository 2. Create a feature branch 3. Implement your changes 4. Add tests for new functionality 5. Ensure all tests pass 6. Submit a pull request ## Resources - [MCP Documentation](https://modelcontextprotocol.io/introduction) - [Home Assistant Docs](https://www.home-assistant.io) - [HA REST API](https://developers.home-assistant.io/docs/api/rest) - [HACS Documentation](https://hacs.xyz) - [TypeScript Documentation](https://www.typescriptlang.org/docs) ## License MIT License - See [LICENSE](LICENSE) file