loading…
Search for a command to run...
loading…
Enables semantic control and monitoring of openHAB smart home items through natural language, supporting commands, queries, and time-based monitoring tasks.
Enables semantic control and monitoring of openHAB smart home items through natural language, supporting commands, queries, and time-based monitoring tasks.
A lightweight MCP (Model Context Protocol) server for openHAB semantic operations.
Set Environment Variables
Create a .env file in the project root with your openHAB credentials:
cat > .env << EOF
# openHAB Configuration (Required)
OPENHAB_BASE_URL=https://your-openhab-instance.org
OPENHAB_API_TOKEN=your_api_token_here
# MCP Server Configuration
MCP_HOST=0.0.0.0
MCP_PORT=8000
MCP_TRANSPORT=streamable-http
LOG_LEVEL=INFO
# Inventory Configuration
INVENTORY_REFRESH_MINUTES=60
# Monitoring Configuration (Required)
MONITORING_WEBHOOK_URL=https://your-webhook-endpoint.org/webhook
MONITORING_WEBHOOK_AUTH_HEADER=Authorization: Bearer your_webhook_token
# MONITORING_TIMEZONE=Europe/Berlin # Optional: defaults to UTC
EOF
Build and Run with Docker Compose
docker-compose up -d
The server will start on port 8000.
Check Logs
docker-compose logs -f openhab-semantic-mcp
Stop the Service
docker-compose down
Clone and set up environment
git clone <repository-url>
cd openhab-semantic-mcp
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -e .
Configure environment
cp src/openhab_semantic_mcp/.env.example .env
# Edit the .env file with your openHAB configuration
Run the server
python -m openhab_semantic_mcp
Configure the server using environment variables in a .env file:
OPENHAB_BASE_URL=https://your-openhab-instance.org
OPENHAB_API_TOKEN=your_api_token_here
MCP_HOST=0.0.0.0
MCP_PORT=8000
MCP_TRANSPORT=streamable-http
LOG_LEVEL=INFO
INVENTORY_REFRESH_MINUTES=60
# Monitoring Configuration (Required)
MONITORING_WEBHOOK_URL=https://your-webhook-endpoint.org/webhook
MONITORING_WEBHOOK_AUTH_HEADER=Authorization: Bearer your_webhook_token
# MONITORING_TIMEZONE=Europe/Berlin # Optional: defaults to UTC
# Optional Monitoring Settings
MONITORING_STORAGE_TYPE=memory
MONITORING_CLEANUP_INTERVAL_MINUTES=60
MONITORING_RETAIN_COMPLETED_DAYS=7
MONITORING_RETAIN_CANCELLED_DAYS=3
MONITORING_RETAIN_ERROR_DAYS=7
MONITORING_ENABLE_AUTO_CLEANUP=true
Required:
OPENHAB_BASE_URL: URL of your openHAB instanceOPENHAB_API_TOKEN: API token for authenticationMONITORING_WEBHOOK_URL: Webhook endpoint for monitoring task notificationsMONITORING_TIMEZONE: Timezone for monitoring tasks (e.g., Europe/Berlin, America/New_York). Optional: defaults to UTC if not set.Optional:
MCP_HOST: Host to bind the MCP server (default: 0.0.0.0)MCP_PORT: Port for the MCP server (default: 8000)MCP_TRANSPORT: Transport mode for MCP communication (default: streamable-http)streamable-http: HTTP-based transport (recommended for Docker/containers)stdio: Standard input/output transport (for local development only - not compatible with Docker)sse: Server-Sent Events transportLOG_LEVEL: Logging level (default: INFO)INVENTORY_REFRESH_MINUTES: Interval for refreshing the semantic inventory (default: 60)MONITORING_WEBHOOK_AUTH_HEADER: Authorization header for webhook requests (format: Key: Value)MONITORING_STORAGE_TYPE: Storage backend type: memory, file, or caldav (default: memory)MONITORING_STORAGE_CONFIG: Backend-specific configuration as JSON string (see Storage Backends)MONITORING_CLEANUP_INTERVAL_MINUTES: Cleanup interval in minutes (default: 60)MONITORING_RETAIN_COMPLETED_DAYS: Days to retain completed tasks (default: 7)MONITORING_RETAIN_CANCELLED_DAYS: Days to retain cancelled tasks (default: 3)MONITORING_RETAIN_ERROR_DAYS: Days to retain error tasks (default: 7)MONITORING_ENABLE_AUTO_CLEANUP: Enable automatic cleanup (default: true)The MCP server provides these semantic tools:
The server automatically validates commands and state updates using openHAB's metadata:
commandDescription.commandOptions from openHABstateDescription.options from openHAB{
"success": false,
"error": "Command 'BLINK' not allowed. Allowed commands: ['ON', 'OFF', 'AUTO']",
"allowed_commands": ["ON", "OFF", "AUTO"]
}
The server supports dual hierarchy systems for powerful semantic queries:
Uses semantic naming conventions with underscore separators:
Lighting_CeilingLight_Downlight → indexed under Lighting, Lighting_CeilingLight, and Lighting_CeilingLight_DownlightIndoor_Room_DiningRoom → indexed under Indoor, Indoor_Room, and Indoor_Room_DiningRoomUses openHAB isPartOf semantic relationships:
# Type-based queries
get_items(location="Indoor") # All indoor items
get_items(equipment="Lighting") # All lighting equipment
get_items(equipment="Lighting_CeilingLight") # All ceiling lights
# Parent-based queries (with recursive location inheritance)
get_items(location="Indoor_Room_DiningRoom") # Items in dining room (including nested equipment)
get_items(equipment="LightSource_AccentLight") # All accent lights (inherited from parent equipment)
# Combined queries
get_items(location="Indoor", equipment="LightSource") # All indoor lighting
get_items(location="Indoor_Floor_GroundFloor", equipment="LightSource", point="Control_Switch", property="Light") # All ground floor light switches
get_items(point="Measurement", property="Humidity") # All humidity measurements
get_items(equipment="HVAC", point="Control") # All controls related to HVAC
The server supports advanced monitoring capabilities with time-based task scheduling:
# Monitor a light switch for 10 minutes
create_monitoring_task(
mode="time_window",
start_time="2026-02-10T14:48:00", # Interpreted in configured timezone
end_time="2026-02-10T14:58:00",
filters={
"location": "Indoor_Room_LivingRoom",
"equipment": "LightSource_FloorLamp",
"point": "Control_Switch"
}
)
# One-shot task - triggers once when condition is met
create_monitoring_task(
mode="one_shot",
end_time="2026-02-10T23:59:00",
filters={"point": "Status_OpenState", "state": {"kind": "exact", "states": ["OPEN"]}}
)
All times are automatically interpreted in the configured timezone:
# Configure timezone (optional - defaults to UTC)
MONITORING_TIMEZONE=Europe/Berlin # European time
MONITORING_TIMEZONE=America/New_York # US Eastern time
MONITORING_TIMEZONE=Asia/Tokyo # Japan time
The LLM automatically receives timezone information in tool descriptions, ensuring correct time interpretation.
Select the backend with MONITORING_STORAGE_TYPE and configure it via MONITORING_STORAGE_CONFIG (a JSON string keyed by backend name):
Memory (default) - In-memory storage, data lost on restart:
MONITORING_STORAGE_TYPE=memory
MONITORING_STORAGE_CONFIG='{"memory": {}}'
File - JSON file persistence:
MONITORING_STORAGE_TYPE=file
MONITORING_STORAGE_CONFIG='{"file": {"file_path": "monitoring_tasks.json"}}'
CalDAV - Calendar-based storage with background sync:
MONITORING_STORAGE_TYPE=caldav
MONITORING_STORAGE_CONFIG='{"caldav": {"url": "https://caldav.example.org/remote.php/dav/principals/users/user/", "username": "user", "password": "pass", "calendar_name": "monitoring", "sync_interval": 300}}'
When a monitoring task triggers, it sends a webhook with detailed event information:
{
"task_id": "monitor_abc123",
"mode": "time_window",
"triggered_at": "2026-02-10T14:52:30+01:00",
"trigger_count": 1,
"item": {
"name": "floorlamp_livingroom_toggle",
"state": "ON",
"display_state": "An",
"unit": null
},
"task_config": {
"filters": {
"location": "Indoor_Room_LivingRoom",
"equipment": "LightSource_FloorLamp"
},
"refinement": null,
"last_state_transition": "2026-02-10T14:48:00+01:00"
},
"time_window": {
"start_time": "2026-02-10T14:48:00+01:00",
"end_time": "2026-02-10T14:58:00+01:00"
}
}
# Install test dependencies
pip install -e ".[test]"
# Run tests
pytest tests/ -v
# Run with coverage
pytest tests/ --cov=openhab_semantic_mcp --cov-report=html
Test coverage includes:
Run in your terminal:
claude mcp add openhab-semantic-mcp -- npx Security
Low riskAutomated heuristic from public metadata — not a security guarantee.