openhab-semantic-mcp
Enables semantic control and monitoring of openHAB smart home items through natural language, supporting commands, queries, and time-based monitoring tasks.
README
openHAB Semantic MCP Server
A lightweight MCP (Model Context Protocol) server for openHAB semantic operations.
Features
- Send commands to openHAB items based on semantic filters
- Query items by location, equipment, points, and properties
- Command validation: Uses openHAB Command Description metadata to prevent invalid commands
- State validation: Uses openHAB State Description metadata to prevent invalid state updates
- Recursive equipment relationships: Parent-child equipment chains for device grouping
- Dual hierarchy support: Type-based and parent-based semantic hierarchies
- Get detailed item information from the semantic inventory
- Real-time state updates via Server-Sent Events (SSE)
- Monitoring Tasks: Create time-based monitoring tasks with webhook triggers
- Dynamic Timezone Support: Automatic timezone handling with LLM-aware tool descriptions
- Docker deployment support
- Safety confirmations for large operations
Installation
Docker (Recommended)
-
Set Environment Variables
Create a
.envfile 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 -dThe server will start on port 8000.
-
Check Logs
docker-compose logs -f openhab-semantic-mcp -
Stop the Service
docker-compose down
Local Development
-
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
Configuration
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 transport
LOG_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, orcaldav(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)
Available Tools
The MCP server provides these semantic tools:
Core Semantic Tools
- get_available_semantic_entities: Discover all semantic entities (locations, equipment, points, properties)
- get_items: Query items with semantic filters
- send_command_to_entities: Send commands to items based on semantic filters
- update_entities_state: Update states of items based on semantic filters
Monitoring Tools
- create_monitoring_task: Create time-based monitoring tasks with webhook triggers
- get_monitoring_task_status: Get status and details of a monitoring task
- cancel_monitoring_task: Cancel an active monitoring task
Command & State Validation
The server automatically validates commands and state updates using openHAB's metadata:
Command Validation
- Command Description: Uses
commandDescription.commandOptionsfrom openHAB - Prevention: Blocks invalid commands before sending to openHAB
- Feedback: Shows valid commands from command metadata
State Validation
- State Description: Uses
stateDescription.optionsfrom openHAB - Prevention: Blocks invalid state updates
- Feedback: Shows valid states from state metadata
Example Error Response
{
"success": false,
"error": "Command 'BLINK' not allowed. Allowed commands: ['ON', 'OFF', 'AUTO']",
"allowed_commands": ["ON", "OFF", "AUTO"]
}
Semantic Hierarchies
The server supports dual hierarchy systems for powerful semantic queries:
Type-Based Hierarchies
Uses semantic naming conventions with underscore separators:
Lighting_CeilingLight_Downlight→ indexed underLighting,Lighting_CeilingLight, andLighting_CeilingLight_DownlightIndoor_Room_DiningRoom→ indexed underIndoor,Indoor_Room, andIndoor_Room_DiningRoom
Parent-Based Hierarchies
Uses openHAB isPartOf semantic relationships:
- Equipment can have parent equipment relationships
- Locations inherit from parent locations
- Items without direct location inherit location from parent equipment
Query Examples
# 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
Monitoring Tasks
The server supports advanced monitoring capabilities with time-based task scheduling:
Features
- Time-based scheduling: Create tasks that monitor items during specific time windows
- Webhook notifications: Automatic webhook triggers when monitoring conditions are met
- Dynamic timezone support: Automatic timezone handling with LLM-aware descriptions
- Multiple storage backends: Memory, file, or CalDAV storage for task persistence
- Automatic cleanup: Configurable retention policies for completed tasks
Creating Monitoring Tasks
# 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"]}}
)
Timezone Handling
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.
Storage Backends
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}}'
Webhook Payload
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"
}
}
Testing
# 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:
- DTO models and relationships
- Inventory indexing with dual hierarchies
- openHAB client semantic parsing
- Monitoring system (service layer, trigger evaluation, webhook management)
- CalDAV backend (connection, event mapping, calendar synchronization)
- Storage backends (memory, file, CalDAV)
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。