Skip to content

Repository files navigation

SynapseHA

MCP server for Home Assistant providing 21 tools for LLM-driven control and maintenance.

License: ISC TypeScript Node.js

โœจ Key Features

  • ๐ŸŽฏ Smart Resolution: Fuzzy search and typo-tolerant mapping for 3,200+ names
  • ๐ŸŽฎ Full Control: Lights, climate, media, fans, and service calls
  • ๐Ÿ” Deep Discovery: Explore topology, entity relationships, and device health
  • ๐Ÿ“Š Analytics: Live context, historical baselines, and anomaly detection
  • โšก Performance: Persistent disk cache with 60s auto-refresh for <50ms responses

๐Ÿ  Home Assistant Add-on Installation

SynapseHA can be installed as a Home Assistant add-on for easy integration. The add-on runs an HTTP/SSE server that MCP clients can connect to.

Quick Install

  1. Add this repository to Home Assistant

    Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.

    Or manually:

    • Go to Settings โ†’ Add-ons โ†’ Add-on Store
    • Click the three dots menu (โ‹ฎ) in the top right
    • Select Repositories
    • Add: https://github.com/hellosamblack/SynapseHA
    • Click Add โ†’ Close
  2. Install the add-on

    • Find SynapseHA in the add-on store
    • Click Install
  3. Start the add-on

    • Click Start
    • The add-on will automatically connect to your Home Assistant instance using the Supervisor API
    • The MCP server will be available at http://<homeassistant-ip>:3000

Connecting MCP Clients

Once the add-on is running, MCP clients can connect to:

  • SSE endpoint: GET http://<homeassistant-ip>:3000/mcp
  • Messages endpoint: POST http://<homeassistant-ip>:3000/messages?sessionId=<id>
  • Health check: GET http://<homeassistant-ip>:3000/health

Add-on Configuration

The add-on supports the following configuration options:

Option Default Description
log_level info Logging level (debug, info, warn, error)
http_port 3000 HTTP port for MCP server
bearer_token "" Optional bearer token for authentication
require_auth false Require authentication for connections
cache_refresh_interval 60 Cache refresh interval in seconds
entity_cache_enabled true Enable entity caching

โš™๏ธ Configuration

Set the following environment variables:

export HA_URL="http://homeassistant.local:8123"
export HA_TOKEN="your_long_lived_access_token"
export CACHE_DIR="./cache"  # Optional, defaults to ./cache
export CACHE_TTL="60000"    # Optional, defaults to 60 seconds

Getting a Home Assistant Token

  1. Open Home Assistant
  2. Go to your profile (bottom left)
  3. Scroll to "Long-Lived Access Tokens"
  4. Click "Create Token"
  5. Copy the token

Usage

Running the Server

npm start

๐Ÿ”Œ Client Setup

Antigravity & VS Code (MCP Extension)

  1. Install the connection:

    • Ensure you have the MCP Extension installed in VS Code.
    • Open your MCP Server Configuration (usually in .vscode/mcp.json or global settings).
  2. Add the SynapseHA Server:

    If running via Home Assistant Add-on (Remote/Network): Use the URL where your Add-on is communicating.

    {
      "mcpServers": {
        "synapseha": {
          "url": "http://<homeassistant-ip>:3000/mcp"
        }
      }
    }

    Run Locally (Development only): If you are running this code locally (not on HA OS), point directly to the build:

    {
      "mcpServers": {
        "synapseha": {
          "command": "node",
          "args": ["f:/CastleBlackCode/SynapseHA/synapseha/dist/index.js"],
          "env": {
            "HA_URL": "http://homeassistant.local:8123",
            "HA_TOKEN": "your_long_lived_token"
          }
        }
      }
    }

Claude Desktop

Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS or %APPDATA%\Claude\claude_desktop_config.json on Windows):

{
  "mcpServers": {
    "synapseha": {
      "command": "node",
      "args": ["/absolute/path/to/SynapseHA/synapseha/dist/index.js"],
      "env": {
        "HA_URL": "http://homeassistant.local:8123",
        "HA_TOKEN": "your_token_here"
      }
    }
  }
}

๐Ÿ› ๏ธ Available Tools (21 Total)

Entity Discovery (4 tools)
  1. list_entities - List all entities or filter by domain (light, switch, climate, sensor)
  2. search_entities - Fuzzy search entities by name with typo tolerance
  3. get_entity_state - Get detailed state and attributes for specific entities
  4. get_entity_relationships - Get relationships between entities, devices, and areas
Device Control (5 tools)
  1. control_light - Control lights: on/off, brightness, color, temperature
  2. control_climate - Control thermostats: temperature, mode, fan
  3. control_media_player - Control media: play, pause, volume, source
  4. control_fan - Control fans: speed, direction
  5. control_switch - Control switches and smart plugs
Service Calls (1 tool)
  1. call_service - Call any Home Assistant service with custom parameters
Topology & Discovery (4 tools)
  1. get_areas - List all areas (rooms)
  2. get_devices - List all devices with optional area filter
  3. get_device_health - Check unavailable entities and low battery devices
  4. list_services - List all available services by domain
Analytics (4 tools)
  1. get_live_context - Get current state: active entities, recent changes
  2. get_history - Get historical data for entities over time
  3. calculate_baseline - Calculate statistics (avg, min, max, median)
  4. detect_anomalies - Detect stuck sensors and anomalies
Automation (2 tools)
  1. activate_scene - Activate a Home Assistant scene
  2. trigger_automation - Trigger a Home Assistant automation
System Info (1 tool)
  1. get_system_info - Get Home Assistant version, location, and entity counts

See API.md for detailed documentation of each tool.

๐ŸŽฏ Entity Resolution

SynapseHA features intelligent entity resolution that allows flexible device control:

// Use friendly names instead of entity IDs
{name: "living room lights"}  // โ†’ light.living_room_main

// Combine with area for disambiguation
{name: "temperature", area: "bedroom"}  // โ†’ sensor.bedroom_temperature

// Add floor for multi-level homes
{name: "lights", area: "bedroom", floor: "2"}  // โ†’ light.2f_bedroom_main

// Direct entity_id still works
{entity_id: "light.living_room"}

Name normalization: Handles variations like "living room" vs "livingroom", ignores special characters
Partial matching: Finds "temp" when searching for "temperature"
Domain preference: Prefers lights when multiple entity types match

๐Ÿ’ก Example Usage

Ask Claude to:

  • "Turn on the living room lights at 50% brightness"
  • "What's the temperature in the bedroom?"
  • "Show me all devices with low battery"
  • "Find entities that haven't updated in the last hour"
  • "What lights are currently on?"
  • "Set the thermostat to 72 degrees"
  • "Show me the history of the front door sensor for the last 24 hours"

๐Ÿ—๏ธ Architecture

SynapseHA/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ index.ts              # Main MCP server
โ”‚   โ”œโ”€โ”€ lib/
โ”‚   โ”‚   โ”œโ”€โ”€ ha-client.ts      # Home Assistant API wrapper
โ”‚   โ”‚   โ”œโ”€โ”€ cache.ts          # Persistent cache with auto-refresh
โ”‚   โ”‚   โ”œโ”€โ”€ fuzzy-search.ts   # Fuzzy matching for entities
โ”‚   โ”‚   โ””โ”€โ”€ name-resolver.ts  # Intelligent entity name resolution
โ”‚   โ”œโ”€โ”€ tools/
โ”‚   โ”‚   โ””โ”€โ”€ index.ts          # All 21 MCP tools
โ”‚   โ””โ”€โ”€ types/
โ”‚       โ””โ”€โ”€ index.ts          # TypeScript type definitions
โ”œโ”€โ”€ dist/                     # Compiled JavaScript (ES modules)
โ””โ”€โ”€ cache/                    # Persistent disk cache

โšก Performance

  • Cache Hit: <50ms response time
  • Cache Miss: ~200-500ms (API call + cache write)
  • Auto-refresh: Every 60 seconds for entity states
  • Fuzzy Search: ~5-10ms for 3,200+ entities

๐Ÿ”ง Development

# Watch mode for development
npm run watch

# Build for production
npm run build

# Run the server
npm start

See CONTRIBUTING.md for development guidelines.

๐Ÿ“š Documentation

๐Ÿค Contributing

Contributions are welcome! Please read CONTRIBUTING.md for details.

๐Ÿ“ License

ISC - See LICENSE file for details.

๐Ÿ™ Acknowledgments

Built with:

๐Ÿ› Issues & Support

โญ Star History

If you find SynapseHA useful, please consider giving it a star on GitHub!

About

No description, website, or topics provided.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages