获取小米插座的 IP 和 token
https://github.com/cnmeeia/Xiaomi-cloud-tokens-extractor
wget https://github.com/PiotrMachowski/Xiaomi-cloud-tokens-extractor/releases/latest/download/token_extractor.zip
unzip token_extractor.zip
cd token_extractor
pip3 install -r requirements.txt
python3 token_extractor.py
通过在 Mac 上的终端应用程序中输入以下内容来检查您的设备是否可以访问:
miiocli -d device --ip 192.168.1.152 --token b110204d86732b019d3d6axxxxb9ad3a info
注意 1:您需要将设备的 IP 和 token 放在这里。
注意 2:-d 用于调试,可以排除以获得更短的输出。
在我的例子中,我得到了这样的信息:
型号:cubee.airrtc.th123e
硬件版本:esp32
固件版本:2.1.7
设备正在响应!好的!进入下一步。
在 MIOT 设备列表中找到您的设备:http://miot-spec.org/miot-spec-v2/instances?status=all
搜索 “cubee.airrtc.th123e” 并找到以下行:
{"status":"released","model":"cubee.airrtc.th123e","version":1,"type":**"urn:miot-spec-v2:device:thermostat:0000A031:cubee-th123e:1"**},
在这个 url 之后复制 “urn” 部分: https://miot-spec.org/miot-spec-v2/instance?type=
在我的例子中:
https://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:thermostat:0000A031:cubee-th123e:1
您将看到设备规格的未格式化 JSON 文本
{
"iid": 12,
"type": "",
"description": "on-off-count",
"properties": [
{
"iid": 1,
"type": "",
"description": "on-off-count",
"format": "uint8",
"access": [
"read",
"notify"
],
"value-range": [
0,
255,
1
]
},
{
"iid": 2,
"type": "",
"description": "temperature",
"format": "uint8",
"access": [
"read",
"notify"
],
"unit": "celsius",
"value-range": [
0,
150,
1
]
}
查找 temperature 获取 “iid”: 12 “iid”: 2
siid 就是 12 piid 就是 2
IP token 换成你获取的
miiocli -d device --ip 192.168.1.152 --token b110204d86732b019d3d6axxxxb9ad3a raw_command get_properties "[{'did': 'MYDID', 'siid': 2, 'piid': 5 }]"
我收到的响应最后一行是:
“[{'did': 'MYDID', 'siid': 2, 'piid': 5, 'code': 0, 'value': 29 }]"
插座的温度为 29 度