Skip to main content
Glama
Hubitat MCP Server

Hubitat MCP Server

by MvdMunnik26
README.md
# Hubitat MCP Server

> **Model Context Protocol server for Hubitat Elevation home automation via Maker API**

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![TypeScript](https://img.shields.io/badge/TypeScript-5.4-blue)](https://www.typescriptlang.org/)
[![Node](https://img.shields.io/badge/Node-%3E%3D18-green)](https://nodejs.org/)

Integrate your Hubitat Elevation smart home hub with Claude and other MCP-compatible applications. Control devices, monitor status, manage modes, and automate your home through natural language.

---

## 🚀 Features

- **📱 Device Control** - Turn devices on/off, set levels, adjust colors, and execute any supported command
- **📊 Real-time Monitoring** - Query device status, attributes, and recent events
- **🏠 Mode Management** - View and change hub modes (Home, Away, Night, etc.)
- **🛡️ HSM Integration** - Control Hubitat Safety Monitor (arm/disarm/status)
- **🔢 Hub Variables** - Read and write hub variables for automation logic
- **⚡ Full Maker API Support** - Complete implementation of all Maker API endpoints
- **🔒 Secure** - Uses access tokens, validates all inputs, never stores credentials
- **📝 TypeScript** - Fully typed for excellent IDE support and fewer errors

## 📦 Installation

### Prerequisites

- **Hubitat Elevation** hub on your local network
- **Maker API** app installed and configured on your Hubitat hub
- **Node.js** 18 or higher (optional - only if you want to build/test locally)

### Quick Start

```bash
# Clone the repository
git clone https://github.com/MvdMunnik26/Hubitat-MCP.git
cd Hubitat-MCP

# That's it! No build required when using npx tsx method
# Configure Claude Desktop (see Step 3 below) and you're ready
```

### Optional: Local Testing

If you want to test the server locally:

```bash
# Install dependencies
npm install

# Create configuration file
cp .env.example .env

# Edit .env with your Hubitat details
# HUBITAT_HOST=10.10.1.250
# HUBITAT_APP_ID=688
# HUBITAT_ACCESS_TOKEN=your_token_here

# Option 1: Run with tsx (no build needed)
npx tsx src/index.ts

# Option 2: Build and run
npm run build
npm start
```

## ⚙️ Configuration

### Step 1: Enable Maker API on Hubitat

1. Open your Hubitat hub web interface
2. Navigate to **Apps** → **Add Built-In App**
3. Select **Maker API**
4. Choose which devices to authorize
5. Note the **App ID** and **Access Token** shown in the app

### Step 2: Configure Environment Variables

Create a `.env` file in the project root:

```env
HUBITAT_HOST=192.168.1.100      # Your hub's IP address
HUBITAT_APP_ID=123               # From Maker API app
HUBITAT_ACCESS_TOKEN=abc123...   # From Maker API app
```

### Step 3: Add to Claude Desktop

Add this to your Claude Desktop configuration file:

**Location:**
- macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
- Windows: `%APPDATA%\Claude\claude_desktop_config.json`
- Linux: `~/.config/Claude/claude_desktop_config.json`

**Recommended Configuration (runs TypeScript directly, no build needed):**
```json
{
  "mcpServers": {
    "hubitat": {
      "command": "npx",
      "args": [
        "-y",
        "tsx",
        "/absolute/path/to/Hubitat-MCP/src/index.ts"
      ],
      "env": {
        "HUBITAT_HOST": "192.168.1.100",
        "HUBITAT_APP_ID": "123",
        "HUBITAT_ACCESS_TOKEN": "your_access_token_here"
      }
    }
  }
}
```

**Example (Windows):**
```json
{
  "mcpServers": {
    "hubitat": {
      "command": "npx",
      "args": [
        "-y",
        "tsx",
        "C:\\AI-projects\\Hubitat-MCP\\src\\index.ts"
      ],
      "env": {
        "HUBITAT_HOST": "192.168.1.100",
        "HUBITAT_APP_ID": "123",
        "HUBITAT_ACCESS_TOKEN": "your_access_token_here"
      }
    }
  }
}
```

**Alternative: Run compiled version (requires build):**
```json
{
  "mcpServers": {
    "hubitat": {
      "command": "node",
      "args": ["/absolute/path/to/Hubitat-MCP/dist/index.js"],
      "env": {
        "HUBITAT_HOST": "192.168.1.100",
        "HUBITAT_APP_ID": "123",
        "HUBITAT_ACCESS_TOKEN": "your_access_token_here"
      }
    }
  }
}
```

### Step 4: Restart Claude Desktop

Completely quit and restart Claude Desktop for the MCP server to connect.

## 🎯 Usage Examples

### List All Devices

```
User: "List all my Hubitat devices"
Claude: Uses hubitat_list_devices tool
```

### Control a Device

```
User: "Turn on the living room light"
Claude: Uses hubitat_send_command with device ID and "on" command

User: "Set the bedroom light to 50%"
Claude: Uses hubitat_send_command with "setLevel" and parameter "50"
```

### Check Device Status

```
User: "Is the front door locked?"
Claude: Uses hubitat_get_attribute to check "lock" attribute

User: "What's the temperature in the bedroom?"
Claude: Uses hubitat_get_attribute to check "temperature" attribute
```

### Change Modes

```
User: "Set the house to away mode"
Claude: Uses hubitat_get_modes to find mode ID, then hubitat_set_mode
```

### Safety Monitor

```
User: "Arm the security system for away"
Claude: Uses hubitat_set_hsm with "armAway"
```

## 🔧 Available Tools

The MCP server provides these tools to Claude:

### Device Management
- `hubitat_list_devices` - List all authorized devices
- `hubitat_get_device` - Get detailed device information
- `hubitat_send_command` - Send command to a device **with automatic retry logic**
- `hubitat_get_attribute` - Get current attribute value
- `hubitat_get_events` - Get recent device events

### ⚡ Automatic Retry Logic

**Battery-Powered Device Support:**
The server automatically retries commands for battery-powered Z-Wave devices (thermostats, locks, etc.) that may be in sleep mode.

**Supported Commands:**
- Thermostat setpoints (`setHeatingSetpoint`, `setCoolingSetpoint`)
- Dimmer levels (`setLevel`)
- Switches (`on`, `off`)
- Locks (`lock`, `unlock`)

**Retry Strategy:**
1. Initial command sent immediately
2. If not verified: Wait 2 seconds, retry
3. If still not verified: Wait 5 more seconds, retry
4. If still not verified: Wait 10 more seconds, final retry
5. Reports success/failure with detailed verification info

**Example Response:**
```json
{
  "success": true,
  "device": { /* device details */ },
  "verification": {
    "attribute": "heatingSetpoint",
    "expectedValue": "20.0",
    "attempts": 2,
    "message": "Command verified after 1 retry(s) (2s wait)"
  }
}
```

### Hub Variables
- `hubitat_list_variables` - List all hub variables
- `hubitat_get_variable` - Get variable value
- `hubitat_set_variable` - Set variable value

### Modes & Safety
- `hubitat_get_modes` - Get available modes
- `hubitat_set_mode` - Change hub mode
- `hubitat_get_hsm_status` - Get HSM status
- `hubitat_set_hsm` - Set HSM status

## 📚 API Documentation

### Device Commands

Common commands supported by most devices:
- **Switches**: `on`, `off`, `toggle`
- **Dimmers**: `setLevel` (0-100)
- **Color Bulbs**: `setColor` (hue, saturation, level), `setHue`, `setSaturation`
- **Locks**: `lock`, `unlock`
- **Thermostats**: `setHeatingSetpoint`, `setCoolingSetpoint`, `setThermostatMode`
- **Generic**: `refresh`

### Device Attributes

Common attributes you can query:
- **switch**: on/off
- **level**: 0-100 (dimmer level)
- **temperature**: Current temperature
- **humidity**: Current humidity
- **lock**: locked/unlocked
- **contact**: open/closed (doors/windows)
- **motion**: active/inactive
- **presence**: present/not present

### HSM Status Values

- `armAway` - Arm Away
- `armHome` - Arm Home
- `armNight` - Arm Night
- `disarm` - Disarm all
- `disarmAll` - Disarm all
- `armRules` - Arm custom rules
- `disarmRules` - Disarm custom rules
- `cancelAlerts` - Cancel alerts

## 🔒 Security

- **Access Token Security**: Your Maker API access token provides full control over authorized devices. Keep it secure.
- **Local Network**: This MCP server communicates directly with your Hubitat hub on your local network (no cloud).
- **No Credential Storage**: Credentials are passed as environment variables, never stored in code.
- **Input Validation**: All inputs are validated using Zod schemas.
- **HTTPS Support**: Use `https://` in `HUBITAT_HOST` if your hub has HTTPS enabled.

### Security Best Practices

1. **Never commit `.env` file** - It contains your access token
2. **Use `.env.example`** as a template
3. **Rotate tokens periodically** - Generate new access token in Maker API if compromised
4. **Limit device access** - Only authorize necessary devices in Maker API
5. **Network security** - Keep Hubitat hub on secure local network

## 🛠️ Development

### Build

```bash
npm run build
```

### Development Mode (watch)

```bash
npm run dev
```

### Run Tests

```bash
npm test
```

### Lint

```bash
npm run lint
```

## 📖 Further Reading

- [Hubitat Maker API Documentation](https://docs2.hubitat.com/en/apps/maker-api)
- [Hubitat Developer Documentation](https://docs2.hubitat.com/en/developer)
- [Model Context Protocol Specification](https://modelcontextprotocol.io/)
- [MCP TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk)

## 🤝 Contributing

Contributions welcome! Please:

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'feat: add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

Please follow conventional commits format.

## 📄 License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## 🙏 Acknowledgments

- Built for the [Model Context Protocol](https://modelcontextprotocol.io/)
- Powered by [Hubitat Elevation](https://hubitat.com/)
- Uses the [MCP TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk)

## 🐛 Troubleshooting

### Server Won't Start

- **Check Node version**: `node --version` (must be ≥18)
- **Verify `.env` file**: Ensure all required variables are set
- **Test hub connectivity**: `ping <HUBITAT_HOST>`
- **Check Maker API**: Ensure app is installed and devices are authorized

### Devices Not Responding

- **Verify device authorization**: Check Maker API app settings
- **Test endpoint manually**: Try accessing `http://<host>/apps/api/<app_id>/devices?access_token=<token>` in a browser
- **Check device ID**: Use `hubitat_list_devices` to see correct IDs

### Claude Can't See the Server

- **Restart Claude Desktop**: Completely quit and reopen
- **Check configuration**: Verify `claude_desktop_config.json` is correct
- **Check logs**: Look in Claude Desktop logs folder for errors
- **Verify path**: Ensure absolute path to `index.js` is correct

## 📞 Support

- **Issues**: [GitHub Issues](https://github.com/MvdMunnik26/Hubitat-MCP/issues)
- **Discussions**: [GitHub Discussions](https://github.com/MvdMunnik26/Hubitat-MCP/discussions)
- **Hubitat Community**: [Hubitat Community Forums](https://community.hubitat.com/)

---

**Made with ❤️ for the smart home community**