2024年12月4日星期三 上午1:12:54

[developer]mi home app控制设备协议原理及使用代码控制小米智能插座-diy api (.net core)

2 年 前
#5849 引用
本地控制  lan control


小米智能家居,想通过API去操控米家的智能家居,如果能实现的话,那就能通过自己写程序去操控设备了,DIY等级直接提升了一个大档次!

要实现控制,原理其实很简单,在米家APP能够远程控制设备,那么它的控制肯定是走的公网,只要把米家APP的操控协议抓包分析一下就知道了。
网络协议无非就是http、socket、websocket这些,大概率还是http,当然最大的难点还是破解数据传输的加密算法。

流程分析

实际上发现米家还是通过HTTP协议去控制设备的,设备直接通过网络、蓝牙网关连接到小米云端,米家APP发送控制指令到云端,云端再下发控制指令到设备。

小米智能设备参数、控制命令查询官方操作手册

https://iot.mi.com/new/doc/guidelines-for-access/other-platform-access/control-api


http://miot-spec.org/miot-spec-v2/instances?status=all

output -- Pretty JSON

https://raw.githubusercontent.com/freemsly/home-assistant/main/home-assisant-xiaomi-devices.MD


{
  "instances": [
    {
      "status": "released",
      "model": "lfsmt.plug.ls002",
      "version": 1,
      "type": "urn:miot-spec-v2:device:outlet:0000A002:lfsmt-ls002:1"
    },
    {
      "status": "released",
      "model": "lfsmt.plug.ls060",
      "version": 1,
      "type": "urn:miot-spec-v2:device:outlet:0000A002:lfsmt-ls060:1"
    },



Mi Home API Documentation

https://mihome4u.co.uk/docs/api-documentation

0
2 年 前
#5850 引用
1
0
2 年 前
#5851 引用
查询米家智能产品miot控制协议

米家的智能产品,有一套自己的控制协议:miot。所有的设备都遵循这套协议。
协议查询地址:
https://home.miot-spec.com/

如我们搜索“小爱音箱pro”,在结果页中,点击下方连接就能看到控制协议了。




siid:控制的大分类,比如2为声音控制,3为播放控制,4为麦克风控制。
piid:控制的小分类,比如siid为2的大分类中,1为音量控制,2为是否静音。
属性(properties):属性分为读/写两种权限,比如音量有读和写属性,那么可以获取音箱的音量和设置音箱的音量。
Actions(方法):其实这个方法类似于设置属性,也是用于控制设备的,它的参数为aiid。
aiid:方法的分类。一般来说调用方法的话,可以省略掉piid。siid+aiid就可以了。

0
2 年 前
#5852 引用
当代码能够控制米家智能设备后,可玩性和可DIY性能直接上升了一个档次。再也不需要受到米家APP的束缚,真正做到“为所欲为”的控制。比如:

你可以通过对接QQ机器人、微信机器人,实现QQ、微信发消息控制智能家居;
微信、QQ消息通过小爱同学播报;
通过人脸识别、人体检测,搭配任意摄像机,实现回家欢迎、出门关灯等操作;
让灯光颜色根据你电脑屏幕颜色来自动变化;
家里门打开了自动启动XXX游戏;
0
2 年 前
#5939 引用
米家云端登录接口问题

登陆时的数据采用了RC4加密,该加密算法和相关参数是如何获取到的呢?

登陆账号相关接口没有用到RC4加密
https://github.com/squachen/micloud
https://github.com/al-one/hass-xiaomi-miot/blob/master/custom_components/xiaomi_miot/core/xiaomi_cloud.py
0
2 年 前
#6007 引用
https://api.io.mi.com/app/service/getappconfig?data=%7B%22lang%22%3A%22zh_CN%22%2C%22name%22%3A%22card_control_config%22%2C%22version%22%3A%2211%22%7D

[code]

{"code":0,"message":"","result":{"id":"172","name":"card_control_config","lang":"zh_CN","version":"11","content":"[{\"props\":[{\"supportType\":[1]}],\"cards\":{\"layout_type\":0,\"card_items\":[{\"cardType\":6}]},\"models\":[\"mijia.camera.v1\",\"mijia.camera.v3\",\"chuangmi.camera.xiaobai\",\"chuangmi.camera.v2\",\"isa.camera.isc5c1\",\"isa.camera.isc5\",\"isa.camera.hl5\",\"isa.camera.iscac1\",\"chuangmi.camera.v5\",\"chuangmi.camera.v6\",\"chuangmi.camera.v3\",\"chuangmi.camera.v4\",\"isa.camera.df3\",\"lumi.camera.aq1\",\"yunyi.camera.v1\",\"yunyi.camera.mj1\",\"mijia.camera.v4\",\"chuangmi.camera.ipc009\",\"chuangmi.camera.ipc010\",\"chuangmi.camera.ipc007b\",\"chuangmi.camera.ipc004b\",\"chuangmi.camera.ipc013\",\"chuangmi.camera.ipc013b\",\"chuangmi.camera.ipc013d\",\"chuangmi.camera.ipc016\",\"chuangmi.camera.ipc16a2\",\"chuangmi.camera.ipc13a2\",\"chuangmi.camera.ipc017\"]},{\"props\":[{\"prop_key\":\"prop.power\",\"supportType\":[1],\"switchStatus\":[\"on\"],\"prop_name\":{\"zh_CN\":\"电源开关\",\"en\":\"Power\"},\"prop_extra\":[{\"value\":\"on\",\"desc\":{\"zh_CN\":\"开\",\"en\":\"On\"}},{\"value\":\"off\",\"desc\":{\"zh_CN\":\"关\",\"en\":\"Off\"}}]},{\"prop_key\":\"prop.st_temp_dec\",\"prop_unit\":\"℃\",\"supportType\":[1],\"prop_name\":{\"zh_CN\":\"温度\",\"en\":\"Temperature\"},\"ratio\":0.1,\"format\":\"%.0f\"},{\"prop_key\":\"prop.mode\",\"supportType\":[1],\"prop_name\":{\"zh_CN\":\"挡位选择\",\"en\":\"Mode\"},\"prop_extra\":[{\"value\":\"cooling\",\"desc\":{\"zh_CN\":\"制冷\",\"en\":\"Cool\"}},{\"value\":\"arefaction\",\"desc\":{\"zh_CN\":\"除湿\",\"en\":\"Dry\"}},{\"value\":\"wind\",\"desc\":{\"zh_CN\":\"送风\",\"en\":\"Wind\"}},{\"value\":\"heat\",\"desc\":{\"zh_CN\":\"制热\",\"en\":\"Heat\"}}]}],\"cards\":{\"layout_type\":3,\"card_items\":[{\"supportGrid\":1,\"cardType\":1,\"operation\":[{\"param\":[\"on\"],\"method\":\"set_power\",\"prop_value\":\"off\",\"button_name\":{\"en\":\"Power\",\"zh_HK\":\"開關\",\"zh_CN\":\"开关\",\"zh_TW\":\"開關\"},\"button_image\":{\"selected\":\"title_btn_power_on\",\"unable\":\"title_btn_power_unable\",\"normal\":\"title_btn_power_off\"}},{\"param\":[\"off\"],\"method\":\"set_power\",\"prop_value\":\"on\"}],\"prop_key\":\"prop.power\"},{\"cardType\":3,\"operation\":[{\"param\":[\"cooling\"],\"method\":\"set_mode\",\"prop_value\":\"cooling\",\"button_name\":{\"zh_CN\":\"制冷\",\"en\":\"Cool\"},\"button_image\":{\"selected\":\"popup_icon_cold_hig\",\"unable\":\"popup_icon_cold_unable\",\"normal\":\"popup_icon_cold_nor\"},\"disable_status\":[{\"key\":\"prop.power\",\"value\":\"off\"}]},{\"param\":[\"heat\"],\"method\":\"set_mode\",\"prop_value\":\"heat\",\"button_name\":{\"zh_CN\":\"制热\",\"en\":\"Heat\"},\"button_image\":{\"selected\":\"popup_icon_sun_hig\",\"unable\":\"popup_icon_sun_unable\",\"normal\":\"popup_icon_sun_nor\"},\"disable_status\":[{\"key\":\"prop.power\",\"value\":\"off\"}]},{\"param\":[\"wind\"],\"method\":\"set_mode\",\"prop_value\":\"wind\",\"button_name\":{\"zh_CN\":\"送风\",\"en\":\"Wind\"},\"button_image\":{\"selected\":\"popup_icon_wind_hig\",\"unable\":\"popup_icon_wind_disable\",\"normal\":\"popup_icon_wind_nor\"},\"disable_status\":[{\"key\":\"prop.power\",\"value\":\"off\"}]}],\"prop_key\":\"prop.mode\"},{\"prop_key\":\"prop.st_temp_dec\",\"cardType\":4,\"operation\":[{\"method\":\"set_temperature\",\"disable_status\":[{\"key\":\"prop.power\",\"value\":\"off\"},{\"key\":\"prop.comfort\",\"value\":\"on\"}]}],\"param_range\":{\"min\":160,\"max\":320},\"param_delta\":10,\"param_type\":[{\"index\":0,\"type\":\"JSONArray\"},{\"type\":\"int\"}]}]},\"models\":[\"zhimi.aircondition.v1\",\"zhimi.aircondition.v2\",\"zhimi.aircondition.sa1\",\"zhimi.aircondition.ma1\",\"zhimi.aircondition.ma2\",\"zhimi.aircondition.ma3\",\"zhimi.aircondition.ma4\",\"zhimi.aircondition.za1\",\"zhimi.aircondition.za2\",\"zhimi.aircond
0
2 年 前
#6008 引用
https://dev.mi.com/docs/passport/en/open-api/
0
2 年 前
#6009 引用
https://api.e.mi.com/


{"success":false,"code":12,"msg":"错误的sign参数","message":"错误的sign参数","desc":"错误的sign参数"}
0
2 年 前
#9208 引用
C# Library for using xiaomi smart gateway in your automation scenarious

C# Library for using xiaomi smart gateway in your automation scenarious

This library provides simple and flexible C# API for Xiaomi Mi Home devices.

Currently supports only Gateway version 2 (DGNWG02LM), Air Humidifier (zhimi.humidifier.v1), Mi Robot vacuum (rockrobo.vacuum.v1) and several sensors.

https://github.com/sergey-brutsky/mi-home

0
2 年 前
#9210 引用
Miio.NET

It's .NET Standard library to control Xiaomi smart devices using miio protocol.

To use this library you need to obtain your Xiaomi smart device token

https://github.com/Koli96/Miio.NET





var deviceIp = "127.0.0.1";
var deviceToken = "ffffffffffffffffffffffffffffffff"
MiioEngine device = new MiioEngine(deviceIp, deviceToken);
Next step is to make a handshshake:

await device.Handshake();
and flush receive stream:

device.ReceiveMessage();
Now you can start sending commands. You can find them using modified app mentioned above.

For example if you want turn on Yeelight device, command looks like:

{
    "id": 4545,
    "method": "set_power",
    "params": ["on", "smooth", 500]
}

0