115 lines
3.1 KiB
Markdown
115 lines
3.1 KiB
Markdown
# MIDI-to-Hue Controller
|
|
|
|
A modular Python application for controlling Philips Hue lights with MIDI controllers.
|
|
|
|
## Features
|
|
|
|
- Map MIDI notes and control changes to Hue light parameters
|
|
- Throttled updates to prevent overwhelming the Hue Bridge
|
|
- Configurable mappings via JSON
|
|
- LED feedback support for controller visualization
|
|
- Customizable value transformations
|
|
|
|
## Structure
|
|
|
|
This application has been refactored to follow modular design principles:
|
|
|
|
- `config.py` - Configuration management module
|
|
- `hue_controller.py` - Philips Hue bridge and light control
|
|
- `midi_controller.py` - MIDI device management
|
|
- `mapper.py` - Mapping logic between MIDI and Hue
|
|
- `main.py` - Application entry point
|
|
|
|
## Usage
|
|
|
|
1. Connect your MIDI device
|
|
2. Edit `midi_hue_config.json` to configure your mappings
|
|
3. Run `python main.py`
|
|
|
|
## Configuration
|
|
|
|
The default configuration file (`midi_hue_config.json`) contains:
|
|
|
|
```json
|
|
{
|
|
"midi_device": 1,
|
|
"update_interval_ms": 50,
|
|
"bridge_ip": "192.168.178.35",
|
|
"mappings": [
|
|
{
|
|
"midi_channel": 5,
|
|
"midi_control": 1,
|
|
"light_name": "Zimmer Decke",
|
|
"parameter": "bri",
|
|
"value_transform": "value * 2"
|
|
},
|
|
...
|
|
]
|
|
}
|
|
```
|
|
|
|
## Dependencies
|
|
|
|
- mido
|
|
- phue
|
|
- mcp (FastMCP)
|
|
|
|
## MCP Server Integration
|
|
|
|
The application now includes MCP (Machine Control Protocol) server integration, allowing you to control your Hue lights through an MCP client. This enables voice assistants and other AI agents to control your lighting system.
|
|
|
|
### Running the MCP Server
|
|
|
|
By default, the MCP server starts automatically alongside the main application. To run only the MCP server:
|
|
|
|
```bash
|
|
python main.py --mcp-only
|
|
```
|
|
|
|
### Available MCP Tools
|
|
|
|
The following tools are available through the MCP server:
|
|
|
|
#### Core Light Control
|
|
|
|
- **list_all_lights** - List all available lights and their current states
|
|
- **set_light_state** - Turn a specific light on or off
|
|
- **set_light_brightness** - Adjust brightness of a specific light (0-254)
|
|
- **flash_alert** - Make a light blink/flash for notifications
|
|
|
|
#### Advanced Light Control
|
|
|
|
- **set_light_color** - Set a light to a specific color using hex (#RRGGBB), RGB format, or common names
|
|
- **get_light_info** - Get detailed information about a specific light
|
|
- **group_control** - Control multiple lights as a group
|
|
|
|
#### Scheduling
|
|
|
|
- **schedule_lighting** - Schedule a light change for a future time
|
|
- **list_scheduled_tasks** - List all scheduled lighting tasks
|
|
- **cancel_scheduled_task** - Cancel a scheduled lighting task
|
|
|
|
### Example MCP Usage
|
|
|
|
```python
|
|
# Using the list_all_lights tool to see available lights
|
|
response = await hue_control.list_all_lights()
|
|
print(response)
|
|
|
|
# Turn on a specific light
|
|
response = await hue_control.set_light_state(light_name="Living Room", on=True)
|
|
print(response)
|
|
|
|
# Set a light to a specific color
|
|
response = await hue_control.set_light_color(light_name="Bedroom", color="#FF0000")
|
|
print(response)
|
|
|
|
# Schedule a light to turn off in 30 minutes
|
|
response = await hue_control.schedule_lighting(
|
|
light_name="Kitchen",
|
|
parameter="on",
|
|
value=False,
|
|
minutes_from_now=30
|
|
)
|
|
print(response)
|
|
```
|