2024年9月29日星期日 下午1:28:18

1.Mi Smart Power Plug 2 (Wi-Fi and Bluetooth Gateway) (chuangmi.plug.212a01) 直接使用代码控制小米家智能插座2 蓝牙网关版 by rytilahti‘s python-miio - miiocli

2 年 前
#5853 引用
Mi Smart Power Plug 2 (Wi-Fi and Bluetooth Gateway) (chuangmi.plug.212a01)

1.直接使用代码控制小米家智能插座2 蓝牙网关版 by rytilahti‘s python-miio  - miiocli


I was able to get the data from an unsupported device (HeatCold Heating Floor Controller - cubee.airrtc.th123e) and to set the required parameters from a Terminal on Mac. Can someone help with converting this into a working plugin for Home Assistant and then HomeKit?

Here is my step-by-step guide for all newcomers who want to play with their devices:


A guide how to communicate with MIOT devices -> Plugin?
https://github.com/rytilahti/python-miio/issues/901

Add Mi Smart Power Plug 2 (chuangmi.plug.212a01) support step by step
https://github.com/rytilahti/python-miio/issues/844


python-miio/devtools/

https://github.com/rytilahti/python-miio/tree/master/devtools
PCAP parser (parse_pcap.py)
MiOT generator



0
2 年 前
#9207 引用
install python-miio
https://python-miio.readthedocs.io/en/latest/discovery.html#installation

pip install python-miio


or

pip3 install git+https://github.com/rytilahti/python-miio


Get Token of your device   获取小米token和设备IP
Use python-miio get token Tokens from Mi Home Cloud
https://www.msly.cn/boards/topic/2152/tokenhow-to-get-token#5854

#miiocli cloud list


output

== 米家智能插座2 蓝牙网关版2 (设备在线 ) ==
  Model: chuangmi.plug.212a01
  Token: 2408ba10c691feeb2e7cef627dc0683d
  IP: 192.168.2.109 (mac: 68:AB:)
  DID: 556285062
  Locale: cn


Get model name of your device by IP address  and Token

https://www.msly.cn/boards/topic/2186/#2450

root@raspberrypi:~# miiocli device --ip 192.168.2.109 --token 2408ba10c691feeb2e7cef627dc0683d info
Model: chuangmi.plug.212a01
Hardware version: esp32
Firmware version: 2.1.8_0041




# miiocli -d device --ip 192.168.2.109 --token 2408ba10c691feeb2e7cef627dc0683d info
INFO:miio.cli:Debug mode active
DEBUG:miio.click_common:Unknown model, trying autodetection. None None
DEBUG:miio.miioprotocol:Got a response: Container:
    data = Container:
        data = b'' (total 0)
        value = b'' (total 0)
        offset1 = 32
        offset2 = 32
        length = 0
    header = Container:
        data = b'!1\x00 \x00\x00\x00\x00!(<\x86\x00\x0c\xa1\xd5' (total 16)
        value = Container:
            length = 32
            unknown = 0
            device_id = unhexlify('21283c86')
            ts = 1970-01-10 13:57:41
        offset1 = 0
        offset2 = 16
        length = 16
    checksum = b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' (total 16)
DEBUG:miio.miioprotocol:Discovered 21283c86 with ts: 1970-01-10 13:57:41, token: b'ffffffffffffffffffffffffffffffff'
DEBUG:miio.miioprotocol:192.168.


Note 1: You need to put your device's IP and Token here.
Note 2: "-d" is for Debug and can be excluded for a shorter output.


Device is responding! Nice! Going to the next step.
0
1 年 前
#18861 引用
You need to find some property

小米家智能插座2-蓝牙网关版-设备接入homeassistant详细教程

https://zhuanlan.zhihu.com/p/539898440
0
1 年 前
#18862 引用
1
0
1 年 前
#18863 引用
1
0
1 年 前
#18864 引用
You need to find some property in the list which you want to get from the device and which is readable



{
    # Source https://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:outlet:0000A002:chuangmi-212a01:1
    "power": {"siid": 2, "piid": 1},
    "temperature": {"siid": 2, "piid": 6},
    "working_time": {"siid": 2, "piid": 7},
    "led": {"siid": 3, "piid": 1},
    "power_consumption": {"siid": 5, "piid": 1},
    "current": {"siid": 5, "piid": 2},
    "voltage": {"siid": 5, "piid": 3},
    "power": {"siid": 5, "piid": 6},
    "on_duration": {"siid": 4, "piid": 1},
    "off_duration": {"siid": 4, "piid": 2},
    "countdown": {"siid": 4, "piid": 3},
    "task_switch": {"siid": 4, "piid": 4},
    "countdown_info": {"siid": 4, "piid": 5},
    "switch_toggle" {"siid": 4, "piid": 6},    
},



0
1 年 前
#18865 引用
Control

The Xiaomi IoT platform is switching to the MioT-Protocol. New products (e.g. chuangmi.plug.212a01) implement this new protocol and the old miio protocol was deprecated.

Currently python-miio supports this protocol(MioT-Protocol).

To send command to miot devices, for example,



miiocli device --ip 192.168.0.201 --token bb441c71ddfXXXXXX038a8f02806e8cc raw_command set_properties '[{"did":"ANYTHING","value":True,"siid":2,"piid":1}]'

miiocli device --ip 192.168.2.109  --token 2408ba10c691feeb2e7cef627dc0683d raw_command set_properties '[{"did":"556285062","value":True,"siid":2,"piid":1}]'




turns on the power of smart plug, and returns
[{'did': 'ANYTHING', 'piid': 1, 'siid': 2, 'code': 0}]

[{'did': '556285062', 'piid': 1, 'siid': 2, 'code': 0}]




测试:局域网模式,断网可用
0
1 年 前
#18866 引用
1
0
1 年 前
#18867 引用
How to  get_properties by piid and max_properties count for miot devices

https://github.com/syssi/xiaomi_raw/issues/6

Some new devices only support get_properties by piid, and properties count not greater than 10.


#  miiocli device --ip 192.168.2.109 --token  2408ba10c691feeb2e7cef627dc0683d raw_command get_properties "[{'did': '556285062', 'siid': 2, 'piid': 1 }]"


Running command raw_command

[{'did': '556285062', 'piid': 1, 'siid': 2, 'value': True, 'code': 0}]

0
1 年 前
#20248 引用
It looks like the device doesn't expose the bluetooth gateway via miot.

ble gateway is never exposed. it just pass data to cloud from ble sensors in range.

see:https://github.com/rytilahti/python-miio/issues/844#issuecomment-719672293
0