智能家居MCP服务器
此MCP服务器与Home Assistant和MQTT集成,允许模型上下文协议(MCP)客户端控制和监视智能家居设备。
特性
- 检索所有已配置设备的当前状态
- 通过Home Assistant或MQTT更改设备状态作为回退
- 管理持续存在的自动化规则
config.yml - 动态添加新设备并保持配置
- 通过MQTT TTS发送文本到语音消息
安装
npm install配置
复制示例配置并更新凭据:
cp config.yml.example config.yml编辑 config.yml:
mqtt:
host: YOUR_MQTT_HOST
port: 1883
user: YOUR_MQTT_USER
password: YOUR_MQTT_PASSWORD
base: home/mcp
home_assistant:
host: YOUR_HASS_HOST
token: YOUR_LONG_LIVED_ACCESS_TOKEN
rules:
- text: 'Your Automation Rule'
devices:
- name: 'Light in Room'
room: room
entity_id: light.your_light_entity
state_type: boolean用法
启动服务器:
npm run build
npm start可用工具
get_smarthome_state:获取当前设备状态change_smarthome_state:更改设备状态get_smarthome_rules:列出自动化规则add_smarthome_rule:添加新的自动化规则add_smarthome_device:将新设备添加到配置中smarthome_tts_voice:通过MQTT发送TTS消息
例子
样品 config.yml
mqtt:
host: localhost
port: 1883
user: user
password: pass
base: home/mcp
home_assistant:
host: localhost
token: token
rules:
- text: When no one is home or sleeping, turn off all lights.
devices:
- name: Light in Room
room: room
entity_id: light.yeelight_ceiling20_0x2339ef2c
state_type: boolean通过MCP使用工具
获取所有设备状态
{
"tool": "get_smarthome_state",
"parameters": {}
}更改设备状态
{
"tool": "change_smarthome_state",
"parameters": {
"name": "Light in Room",
"value": "1"
}
}列出自动化规则
{
"tool": "get_smarthome_rules",
"parameters": {}
}添加新规则
{
"tool": "add_smarthome_rule",
"parameters": { "text": "Turn on fan if humidity > 60%" }
}添加新设备
{
"tool": "add_smarthome_device",
"parameters": {
"name": "Kitchen Fan",
"entity_id": "switch.kitchen_fan",
"room": "kitchen"
}
}发展
找出源头:
npm run lint src运行测试:
npm test许可证
麻省理工学院
