Skip to main content
Glama
mijia-home-mcp

mijia-home-mcp

mijia-home-mcp

中文 | English

米家 MCP server。get_home_snapshot 一次调用批量拉全屋设备状态(65 台约 9s),按家/房间分组,枚举值转成可读文本。默认只读,控制工具要显式开启,锁和摄像头另有一层拦截。

基于 Do1e/mijia-api,共用其登录凭证(~/.config/mijia-api/auth.json,扫码一次约一个月)。

安装

先登录(终端出二维码,米家 App 扫):

uvx --from git+https://github.com/jiayunlimailutorontoca/mijia-home-mcp mijia-home-mcp login

加到 Claude Code:

claude mcp add mijia-home -- uvx --from git+https://github.com/jiayunlimailutorontoca/mijia-home-mcp mijia-home-mcp serve

问一句"家里现在什么情况"就能用了。

帮我安装 mijia-home 米家 MCP:
1. uvx --from git+https://github.com/jiayunlimailutorontoca/mijia-home-mcp mijia-home-mcp login
   二维码给我扫;已有有效的 ~/.config/mijia-api/auth.json 就跳过。这步需要我,停下来等。
2. claude mcp add mijia-home -- uvx --from git+https://github.com/jiayunlimailutorontoca/mijia-home-mcp mijia-home-mcp serve
3. 我有多个家庭的话先问我锁哪个,命令加 --env MIJIA_HOME_MCP_HOME_NAME=家庭名
4. 调 get_home_snapshot,报在线设备数
帮我安装 mijia-home 米家 MCP:
1. 登录同上,二维码给我扫
2. openclaw mcp add mijia-home --command uvx --arg "--from" --arg "git+https://github.com/jiayunlimailutorontoca/mijia-home-mcp" --arg "mijia-home-mcp" --arg "serve"
3. openclaw mcp probe mijia-home 应显示 14+ tools;会话里看不到就 npm i -g mcporter
4. 调 get_home_snapshot 验证

多家庭账号建议锁定默认家庭,否则每次全家庭拉取:

"env": { "MIJIA_HOME_MCP_HOME_NAME": "我的家" }

Related MCP server: xiaomi-device-control

通知

配置通道后多一个 send_notification 工具,一次推所有已配置的通道;不配则该工具不出现。

"env": {
  "MIJIA_HOME_MCP_SPEAKER": "auto",
  "MIJIA_HOME_MCP_MEOW": "MeoW昵称",
  "MIJIA_HOME_MCP_BARK": "Bark设备key",
  "MIJIA_HOME_MCP_NTFY": "ntfy主题",
  "MIJIA_HOME_MCP_FEISHU": "https://open.feishu.cn/open-apis/bot/v2/hook/xxx",
  "MIJIA_HOME_MCP_DINGTALK": "https://oapi.dingtalk.com/robot/send?access_token=xxx"
}

各通道申请方式:

  • 钉钉:群设置 → 机器人 → 自定义。安全设置选关键词填米家,或加签(密钥配 _DINGTALK_SECRET)。仅内部群,限流 20 条/分

  • 飞书:群设置 → 群机器人 → 自定义机器人。签名密钥配 _FEISHU_SECRET

  • MeoW(鸿蒙):装 app 注册昵称,昵称即配置

  • Bark(iOS):app 里复制 device key;自建填 https://host/key

  • ntfy(安卓):订阅一个 topic,topic 即配置。公开 topic 谁都能订,名字取随机

控制

默认只读。开启:

mijia-home-mcp serve --enable-control --allow "客厅*" --deny "*camera*"

规则:

  • 锁/摄像头/燃气水阀/保险柜不吃通配符,必须 --allow 精确写设备名或 did,或 --allow-dangerous

  • run_speaker_command(小爱执行语音指令)能触达全屋设备,按危险设备同等门控;经 run_device_action 调 execute-text-directive 走同一道闸,绕不过去。纯播报用 speaker_announce,普通门控

  • run_scene 不看白名单——场景内容是你在米家 App 定义的,不想让 AI 碰的别做成手动场景

  • 所有写操作(含被拒的)记 ~/.config/mijia-home-mcp/audit.log

工具

读:get_home_snapshot(home/room 过滤,30s 缓存)、get_home_changes(diff)、query_history(本地 30 天事件史)、get_battery_report、get_device_statistics、list_homes/list_devices/get_device_status/get_device_spec/list_scenes/list_consumables、auth_status/login/login_status、send_notification

控制:turn_on/turn_off(自动匹配开关属性)、set_device_property、run_device_action、run_scene、speaker_announce、run_speaker_command

resources:mijia://devices、mijia://homes、mijia://snapshot

耗材:list_consumables 返回云端算好的三态(充足/不足/耗尽),该换的进 needs_attention,同时出现在快照的 attention 里。

命令行

不接 MCP 也能用:

mijia-home-mcp doctor       # 自检 + 更新检查
mijia-home-mcp snapshot     # --home --room --full --json
mijia-home-mcp devices
mijia-home-mcp battery
mijia-home-mcp say "吃饭了"
mijia-home-mcp watch --speak --only "门锁*" --ignore left-time

watch 轮询变化,推送到已配置的通道,每小时查一次耗材,事件写本地历史。--ignore left-time 建议加上,洗碗机倒计时一分钟变一次。

局域网

mijia-home-mcp serve --transport http --host 0.0.0.0 --port 8423 --http-token 随机串
claude mcp add --transport http mijia-home http://<host>:8423/mcp --header "Authorization: Bearer 随机串"

不设 token 无鉴权,启动会警告。别暴露公网。token 建议走环境变量 MIJIA_HOME_MCP_HTTP_TOKEN,命令行参数在进程列表可见。

环境变量

变量

说明

MIJIA_HOME_MCP_AUTH

认证文件,默认 ~/.config/mijia-api/auth.json

MIJIA_HOME_MCP_HOME_NAME

默认家庭

MIJIA_HOME_MCP_ENABLE_CONTROL

1 开控制

MIJIA_HOME_MCP_ALLOW / _DENY

白/黑名单,逗号分隔

MIJIA_HOME_MCP_ALLOW_DANGEROUS

放行危险设备

MIJIA_HOME_MCP_STATE_DIR

状态目录,默认 ~/.config/mijia-home-mcp

MIJIA_HOME_MCP_SPEAKER / _MEOW / _BARK / _NTFY / _FEISHU(_SECRET) / _DINGTALK(_SECRET) / _WEBHOOK

通知通道

MIJIA_HOME_MCP_HTTP_TOKEN

http Bearer token

已知问题

  • 走小米云端(上游为逆向接口),秒级延迟,无推送,轮询别太密

  • 凭证约一个月过期,login 重扫

  • 红外类设备(空调伴侣的"空调")spec 页缺中文数据,解析失败会进 attention.spec_errors,不影响其他设备

  • readOnlyHint 注解只是提示,真正的门在服务端

开发

uv venv && uv pip install -e ".[dev]"
uv run pytest

测试离线,不需要米家账号。

License

GPL-3.0-or-later。上游 mijia-api 为 GPL-3.0 且声明仅供学习交流,本项目相同。

Available Tools

14 tools
auth_statusA
Read-only

查看当前米家登录状态与认证文件路径,排查认证问题时先调这个。

Inputs: no named parameters. Returns: object

get_battery_reportA
Read-only

全屋电量普查:批量读取所有带电池的设备,按电量升序返回。

回答"哪些设备该换电池了"用这个,比逐设备查询快得多。 low 字段列出电量 ≤20% 的设备。

Inputs: home. Returns: object

get_device_specA
Read-only

获取设备规格:支持的属性(类型/读写/范围/枚举值)与动作列表。

用于确定 get_device_status / set_device_property / run_device_action 可用的属性名与动作名。

Inputs: device_or_model (required). Returns: object

get_device_statisticsA
Read-only

获取设备历史统计数据(如插座耗电量、净化器使用时长)。

并非所有设备都支持统计;键 siid_piid 需从设备说明或 https://home.miot-spec.com 查询(常见如插座功耗为 "7.1")。

Inputs: device (required), siid_piid (required), limit, granularity. Returns: result

get_device_statusA
Read-only

读取单个设备的详细状态(批量拉取,含原始值与语义化文本)。

Inputs: device (required), props. Returns: object

get_home_changesA
Read-only

回答"上次以来家里变了什么":与上一次快照对比,返回变化列表。

变化类型: prop_changed(属性值变化)/ went_offline / came_online / device_added / device_removed。调用后会把本次快照存为新基线 (基线只由本工具读写,get_home_snapshot 不影响它)。 首次调用时没有基线,会先建立基线并说明。

Inputs: home. Returns: object

get_home_snapshotA
Read-only

一次调用获取全屋设备状态快照(推荐入口)。

返回 家→房间→设备→语义化状态 的结构化结果,并附 attention (离线/低电量/故障设备)与统计信息。批量拉取,整屋通常几秒内完成。 本工具不影响 get_home_changes 的对比基线。

Inputs: home, room, detail, max_props_per_device. Returns: object

list_consumablesA
Read-only

耗材状态(滤芯/拖布/刷头/电池等),回答"哪些耗材该换了"。

status 是米家云端算好的三态:充足/不足/耗尽。needs_attention 里是不足和耗尽的,items 按紧急程度排序。

Inputs: home. Returns: object

list_devicesA
Read-only

列出设备(名称/did/model/在线状态/所属家庭房间),支持过滤。

Inputs: home, room, online_only, name_contains. Returns: result

list_homesA
Read-only

列出所有家庭及其房间(名称与设备数),用于确定 home 参数取值。

Inputs: no named parameters. Returns: result

list_scenesA
Read-only

列出米家手动场景(名称/scene_id/所属家庭)。

Inputs: home. Returns: result

loginA

发起米家扫码登录(凭证过期时使用)。

先尝试静默刷新 token;不行则返回二维码图片链接,用米家APP在2分钟内 扫码,然后调用 login_status 查询结果。

Inputs: no named parameters. Returns: result

login_statusA
Read-only

查询 login 发起的扫码登录进度(pending/success/error)。

Inputs: no named parameters. Returns: result

query_historyA
Read-only

查询本地事件历史,回答"今天门开过几次""洗衣机几点跑完"这类问题。

事件在 mijia-home-mcp watch 运行期间、以及每次 get_home_changes 调用时记录,保留 30 天;记录之外的时段没有数据。

Inputs: prop, limit, since, until, +2 more. Returns: object

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.9/5.0

    Scored across 14 tools

    Disambiguation5/5

    Each tool targets a distinct aspect of the Mi Home ecosystem: authentication, device listing, status retrieval, battery check, consumables, scenes, history, changes, and specs. No two tools have overlapping purposes.

    Naming Consistency4/5

    Most tools follow a verb_noun pattern (get_, list_, query_), but 'auth_status' and 'login_status' are noun_verb, which is a minor inconsistency. Overall, the pattern is readable and predictable.

    Tool Count5/5

    With 14 tools, the set is well-scoped for a home automation server. Each tool serves a clear purpose, covering authentication, device information, battery, consumables, scenes, history, and changes.

    Completeness2/5

    The tool surface is missing write operations (e.g., set_device_property, run_device_action), which are referenced in get_device_spec but not implemented. This is a significant gap for a home automation server, as agents cannot control devices.

    Maintenance

    ActivityNo data
    ResponsivenessSyncing

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      An MCP server based on the Mastra framework for controlling Xiaomi Mi Home smart devices. It enables device discovery, property management, action execution, and scene control through the Mi Home cloud service.
      ISC
    • F
      license
      Not graded
      quality
      D
      maintenance
      MCP server for controlling Xiaomi/Mi Home smart devices via natural language, supporting device listing, property read/write, action calls, and camera snapshots.
      12
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      A powerful MCP server that enables AI assistants to discover, commission, and control Matter-compatible smart home devices through a standardized interface.
      20 npm
      9
      MIT
    • A
      license
      Not graded
      quality
      A
      maintenance
      An MCP server that enables natural language creation and management of Xiaomi Mi Home automation rules, integrating with AI coding assistants to query devices and manipulate automation graphs.
      144
      MIT