Skip to main content
Glama
README.md
# Smart Home MCP Server

A Model Context Protocol (MCP) server that enables LLMs to control smart home devices through natural language commands.

## Features

- **Device Control**: Control TP-Link Kasa smart plugs and bulbs
- **Natural Language Interface**: Human-friendly device names and commands
- **Scene Management**: Predefined lighting scenes (bright, dim, warm, cool, party, relax, bedtime)
- **Real-time Status**: Get current device states and capabilities
- **Room-based Control**: Organize devices by room for targeted control

## Prerequisites

1. **REST API Server**: The smart home REST API must be running on `http://localhost:3001`
2. **Device Discovery**: Devices must be registered in the device registry
3. **Network Access**: Ensure the MCP server can reach your smart home network

## Installation

```bash
cd /Users/veli/Documents/Cline/MCP/smart-home-mcp
npm install
npm run build
```

## Usage

### Claude Desktop Integration

Add this to your Claude Desktop configuration:

```json
{
  "mcpServers": {
    "smart-home": {
      "command": "/Users/veli/Documents/Cline/MCP/smart-home-mcp/build/index.js"
    }
  }
}
```

### Available Tools

#### 1. `list_devices`
List all smart home devices with their current status.

**Example**: "Show me all my smart home devices"

#### 2. `control_light`
Control smart lights with various actions:
- **Power**: Turn lights on/off
- **Brightness**: Adjust brightness (1-100%)
- **Color**: Set RGB color values
- **Color Temperature**: Set warm/cool white (2500-9000K)

**Examples**:
- "Turn on the elizabeth night lamp"
- "Set the holiday lights to 50% brightness"
- "Make the bedroom light red"
- "Set the living room light to warm white"

#### 3. `control_plug`
Control smart plugs (on/off only).

**Example**: "Turn off the holiday lights plug"

#### 4. `set_scene`
Apply predefined lighting scenes:
- **bright**: 100% brightness, 4000K
- **dim**: 20% brightness, 2700K  
- **warm**: 70% brightness, 2500K
- **cool**: 80% brightness, 6500K
- **party**: 100% brightness, magenta color
- **relax**: 40% brightness, 2200K
- **bedtime**: 10% brightness, 2000K

**Examples**:
- "Set a relaxing scene"
- "Apply bedtime lighting"
- "Make it bright in the living room"

#### 5. `get_device_status`
Get detailed status of a specific device.

**Example**: "What's the status of the elizabeth night lamp?"

## Device Names

The server uses friendly device names from the device registry:
- `holiday-lights` - HS103 Smart Plug
- `elizabeth-night-lamp` - KL125 Smart Bulb
- `guest-bedroom-lamp` - KL125 Smart Bulb
- And more...

## API Integration

The MCP server communicates with the REST API at `http://localhost:3001/api`:

- `GET /devices` - List all devices
- `POST /devices/{name}/control` - Control device
- `POST /devices/{name}/power` - Set power state

## Development

### Building
```bash
npm run build
```

### Testing
Make sure the REST API server is running:
```bash
# From the main project directory
cd /Users/veli/code/automation/home-automation
npx tsx packages/smart-home-api/src/app.ts
```

### Debugging
The MCP server logs to stderr, so you can see debug output when running with Claude Desktop.

## Example Conversations

**User**: "Turn on all the lights and set them to a warm, cozy scene"

**Assistant**: I'll turn on your lights and set them to a warm, cozy ambiance.

*Uses `set_scene` with "warm" to apply 70% brightness and 2500K color temperature to all lights*

**User**: "What devices do I have available?"

**Assistant**: Here are your smart home devices:

*Uses `list_devices` to show all registered devices with their current status*

**User**: "Turn off the holiday lights"

**Assistant**: I'll turn off the holiday lights for you.

*Uses `control_plug` to turn off the holiday-lights device*

## Troubleshooting

1. **MCP Server Not Found**: Ensure the path in Claude Desktop config is correct
2. **API Connection Failed**: Verify the REST API is running on port 3001
3. **Device Not Found**: Check device names in the registry match the friendly names
4. **Network Issues**: Ensure firewall allows communication between networks

## Next Steps

- Add Tuya device support
- Implement advanced scene management
- Add device grouping and automation rules
- Integrate with N8N for complex workflows