🏠 Home Assistant via MCP protocol技能使用说明
2026-03-29
新闻来源:网淘吧
围观:26
电脑广告
手机广告
Home Assistant
使用MCP协议控制Home Assistant智能家居并查询状态。
前提条件
在Home Assistant中启用MCP服务器:

- 浏览到您的Home Assistant实例。
- 前往 设置 > 设备与服务。
- 在右下角,选择+ 添加集成按钮。
- 从列表中,选择"Model Context Protocol"。
- 按照屏幕上的说明完成设置。
使用
# Get states
mcporter call home-assistant.GetLiveContext
# Turn on the device
mcporter call home-assistant.HassTurnOn(name: "Bedroom Light")
mcporter call home-assistant.HassTurnOn(name: "Light", area: "Bedroom")
# Turn off the device
mcporter call home-assistant.HassTurnOff(name: "Bedroom Light")
mcporter call home-assistant.HassTurnOff(area: "Bedroom", domain: ["light"])
# Control light
# brightness: The percentage of the light, where 0 is off and 100 is fully lit.
# color: Name of color
mcporter call home-assistant.HassLightSet(name: "Bedroom Light", brightness: 50)
# Control fan
# percentage: The percentage of the fan, where 0 is off and 100 is full speed.
mcporter call home-assistant.HassFanSetSpeed(name: "Fan", area: "Bedroom", percentage: 80)
执行以下命令以了解具体使用方法:
mcporter list home-assistant --schema --all-parameters
配置
当提示MCP服务器不存在时,提醒用户通过执行以下命令添加配置来设置HASS_BASE_URL和HASS_ACCESS_TOKEN环境变量:
mcporter config add home-assistant \
--transport http \
--url "${HASS_BASE_URL:-http://homeassistant.local:8123}/api/mcp" \
--header "Authorization=Bearer \${HASS_ACCESS_TOKEN}"
关于mcporter
- 当命令
mcporter不存在时,请使用npx -y mcporter作为替代。 - https://github.com/steipete/mcporter/raw/refs/heads/main/docs/call-syntax.md
- https://github.com/steipete/mcporter/raw/refs/heads/main/docs/cli-reference.md
文章底部电脑广告
手机广告位-内容正文底部


微信扫一扫,打赏作者吧~