智能家居控制服务器

一个集成Home Assistant和MQTT的智能家居控制服务器,支持设备状态监控、自动化规则管理和动态设备添加。

  • by popstas
  • TypeScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 popstas/smarthome-mcp-server

使用说明

智能家居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

许可证

麻省理工学院