MCPcopy Index your code
hub / github.com/Do1e/mijia-api

github.com/Do1e/mijia-api @v4.1.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v4.1.2 ↗ · + Follow
110 symbols 466 edges 17 files 29 documented · 26%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

mijiaAPI

米家 API,可以使用代码、CLI、MCP 直接控制米家设备。

🎉 v4.0.0 版本已支持 MCP,详见 MCP 使用文档 🎉 v4.1.0 版本已支持 Agent Skill,详见 Agent Skill 使用文档

GitHub PyPI License: GPL-3.0

📖 完整文档请见 mijia-api.do1e.com

常见问题 | 更新日志

安装

要求 Python >= 3.10

pip install mijiaAPI
# Or `uv add mijiaAPI` for uv users

其他安装方式(源码安装、AUR)请参考文档

快速开始

from mijiaAPI import mijiaAPI, mijiaDevice

# 初始化并扫码登录(认证文件默认保存在 ~/.config/mijia-api/auth.json)
api = mijiaAPI()
api.login()

# 通过设备名称控制设备(推荐)
device = mijiaDevice(api, dev_name="我的台灯")
device.on = True              # 打开设备
device.brightness = 60        # 设置亮度为 60%

# 查看设备支持的所有属性和动作
print(device)

CLI 用法:

mijiaAPI login                          # 扫码登录
mijiaAPI -l                             # 列出所有设备
mijiaAPI set --dev_name "台灯" --prop_name "brightness" --value 60

MCP 用法:

执行 uvx mijiaAPI login -p /path/to/auth.json 登录后,在 MCP 客户端配置中添加以下内容即可接入米家:

{
  "mcpServers": {
    "mijia-api": {
      "command": "uvx",
      "args": ["mijiaAPI", "mcp", "-p", "/path/to/auth.json"]
    }
  }
}

更多用法(API 基础调用、MCP Server、CLI 完整参数、最佳实践等)请查阅完整文档

致谢

开源许可

本项目采用 GPL-3.0 开源许可证。

请注意:GPL-3.0 是具有“强传染性”的开源许可证。
如果您在您的项目中使用、修改或分发本项目的代码(包括作为库依赖),您的整个项目也必须以 GPL-3.0 或兼容许可证开源发布。

免责声明

  • 本项目仅供学习交流使用,不得用于商业用途,如有侵权请联系删除
  • 用户使用本项目所产生的任何后果,需自行承担风险
  • 开发者不对使用本项目产生的任何直接或间接损失负责

Core symbols most depended-on inside this repo

get
called by 97
mijiaAPI/devices.py
set
called by 19
mijiaAPI/devices.py
_request
called by 11
mijiaAPI/apis.py
_get_api
called by 11
mijiaAPI/mcp_server.py
_refresh_if_needed
called by 10
mijiaAPI/mcp_server.py
get_homes_list
called by 9
mijiaAPI/apis.py
get_devices_list
called by 9
mijiaAPI/apis.py
run_action
called by 8
mijiaAPI/apis.py

Shape

Method 54
Function 43
Class 13

Languages

Python100%

Modules by API surface

mijiaAPI/apis.py34 symbols
mijiaAPI/mcp_server.py17 symbols
mijiaAPI/errors.py16 symbols
mijiaAPI/devices.py15 symbols
mijiaAPI/__main__.py11 symbols
mijiaAPI/miutils.py7 symbols
decrypt/decrypt_har.py5 symbols
mijiaAPI/logger.py4 symbols
decrypt/decrypt.py1 symbols

For agents

$ claude mcp add mijia-api \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact