Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Xiaomi Air Quality Monitor 2gen #419

Closed
herolee opened this issue Nov 22, 2018 · 33 comments
Closed

Support for Xiaomi Air Quality Monitor 2gen #419

herolee opened this issue Nov 22, 2018 · 33 comments

Comments

@herolee
Copy link

herolee commented Nov 22, 2018

$ mirobo discover
INFO:miio.discovery:Discovering devices with mDNS, press any key to quit...
WARNING:miio.discovery:Found unsupported device cgllc-airmonitor-b1_miio57435516._miio._udp.local. at 192.168.0.79, please report to developers

$ mirobo --ip 192.168.0.79 --token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx info
cgllc.airmonitor.b1 v3.4.4_0077 (34:CE:00:8A:71:CC) @ 192.168.0.79 - token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

@syssi
Copy link
Collaborator

syssi commented Nov 22, 2018

Could you provide the output of:

miiocli airqualitymonitor --ip IP --token TOKEN status

syssi added a commit to syssi/python-miio that referenced this issue Nov 22, 2018
@syssi syssi changed the title Support for Xiaomi Air Quality Monitor Support for Xiaomi Air Quality Monitor 2gen Nov 22, 2018
@herolee
Copy link
Author

herolee commented Nov 22, 2018

The connection is unstable:

ERROR:miio.device:Got error when receiving: timed out
Error: No response from the device

I'll try again later.

@syssi
Copy link
Collaborator

syssi commented Nov 22, 2018

May be your device isn't compatible to the 1gen device. I will provide another command ASAP to retrieve selected properties only.

@herolee
Copy link
Author

herolee commented Nov 22, 2018

OK

The product link:
https://item.mi.com/1184500007.html

@syssi
Copy link
Collaborator

syssi commented Nov 22, 2018

# try to retrieve multiple properties with one request
miiocli airqualitymonitor --ip IP --token TOKEN raw_command get_prop "['power', 'aqi', 'battery']"

# request one property per request
miiocli airqualitymonitor --ip IP --token TOKEN raw_command get_prop "['power']"
miiocli airqualitymonitor --ip IP --token TOKEN raw_command get_prop "['aqi']"
miiocli airqualitymonitor --ip IP --token TOKEN raw_command get_prop "['battery']"
miiocli airqualitymonitor --ip IP --token TOKEN raw_command get_prop "['usb_state']"
miiocli airqualitymonitor --ip IP --token TOKEN raw_command get_prop "['time_state']"
miiocli airqualitymonitor --ip IP --token TOKEN raw_command get_prop "['night_state']"
miiocli airqualitymonitor --ip IP --token TOKEN raw_command get_prop "['night_beg_time']"
miiocli airqualitymonitor --ip IP --token TOKEN raw_command get_prop "['night_end_time']"
miiocli airqualitymonitor --ip IP --token TOKEN raw_command get_prop "['sensor_state']"

@herolee
Copy link
Author

herolee commented Nov 22, 2018

Tried many times,get these results:

Running command raw_command
ERROR:miio.device:Got error when receiving: timed out
Error: No response from the device
OR:
ERROR:miio.device:Unable to discover a device at address 192.168.0.79
Error: Unable to discover the device 192.168.0.79

Maybe because of the monitor using UDP protocol?

@syssi
Copy link
Collaborator

syssi commented Nov 22, 2018

This happens usually if the TOKEN isn't correct.

@syssi
Copy link
Collaborator

syssi commented Nov 22, 2018

Does the info call this work?

@herolee
Copy link
Author

herolee commented Nov 22, 2018

$ mirobo --ip 192.168.0.79 --token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx info
cgllc.airmonitor.b1 v3.4.4_0077 (34:CE:00:8A:71:CC) @ 192.168.0.79 - token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

$ miiocli airqualitymonitor --ip 192.168.0.79 --token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx info
Model: cgllc.airmonitor.b1
Hardware version: Linux
Firmware version: 3.4.4_0077
Network: {'mask': '255.255.255.0', 'localIp': '192.168.0.79', 'gw': '192.168.0.1'}
AP: {'ssid': 'xxx', 'bssid': 'xx:xx:xx:xx:xx:xx'}

but most times get 'time out' result.

@syssi
Copy link
Collaborator

syssi commented Nov 22, 2018

Could you place the device next to your access point just for testing? May be your Wi-Fi connection is unstable/lossy.

@herolee
Copy link
Author

herolee commented Nov 22, 2018

OK,i'll try again later.

@herolee
Copy link
Author

herolee commented Nov 22, 2018

I have putted the device next to the AP but get the same result,always time out.

@syssi
Copy link
Collaborator

syssi commented Nov 27, 2018

Hmm... it's hard to help here because it looks like a firmware issue or protocol incompatibility.

@herolee
Copy link
Author

herolee commented Nov 27, 2018

OK.Hope the next firmware will fix this issue.
Anyway,thank you for your reply :)

syssi added a commit to syssi/python-miio that referenced this issue Jan 17, 2019
@m1yuan
Copy link

m1yuan commented Feb 18, 2019

I think Xiaomi use a new protocol for device with ESP32 chip. I tried to capture both local network and remote access from io.mi.com communication between Mijia.app and this device.

The communication between app and io.mi.com is like:

{"id":188,"method":"get_air_data","accessKey":"******","params":{"systemInfo":{"mobileModel":"iPhone10,2","sysName":"iOS","sysVersion":"12.1.4"},"ownerId":"***","userId":"***","platform":"iOS"}}

{"code":0,"id":198,"result":{"co2e":721,"humidity":46.799999,"pm25":4.800000,"temperature":18.400000,"temperature_unit":"c","tvoc":0.713078,"tvoc_unit":"mg_m3"}}

And the local communication is disappeared. 1st Gen Air Quality Monitor was using udp 54321.

@myvolkov
Copy link

myvolkov commented Mar 7, 2019

I have the same problem for new firmware:

miiocli airqualitymonitor --ip 192.168.1.37 --token XXXXXXXXXXXXX info
Model: cgllc.airmonitor.b1
Hardware version: Linux
Firmware version: 3.4.4_0087
Network: {'mask': '255.255.255.0', 'gw': '192.168.1.1', 'localIp': '192.168.1.37'}
AP: {'bssid': 'xx:xx:xx:xx:xx:xx', 'ssid': 'WIFINET'}

than

miiocli airqualitymonitor --ip 192.168.1.37 --token XXXXXXXXXXXXX status
ERROR:miio.device:Got error when receiving: timed out
Error: No response from the device

and if try again ask info after status

miiocli airqualitymonitor --ip 192.168.1.37 --token XXXXXXXXXXXXX info
ERROR:miio.device:Got error when receiving: timed out
Error: No response from the device

looks like it hangs during several minutes after wrong request

@mwenyuan, how did you dump and decrypt communication between app and io.mi.com?

@fwestenberg
Copy link
Contributor

fwestenberg commented Mar 20, 2019

Hi guys,

Any progress on this one? I'm also having this product and issue. I really want to use it in Home Assistant. Let me know if I can help!

@syssi
Copy link
Collaborator

syssi commented Mar 20, 2019

@fwestenberg Your device doesn't respond, too?

@fwestenberg
Copy link
Contributor

No, just the info endpoint as mentioned above..

@m1yuan
Copy link

m1yuan commented Mar 27, 2019

@myvolkov mijia.app connects to io.mi.com by https, so I use surge.app to MitM and capture the traffic.

@euroiasi
Copy link

Hello ! I have a problem with Xiaomi Mijia Smart Air Detector 3.97 Inch HD touch screen Intelligent Linkage 3 High-precision Sensors.
20190326_102536
Someone can find a solution ?
Thank you very much !

@Saniksanik
Copy link

You must call method "get_air_data"

@syssi
Copy link
Collaborator

syssi commented Aug 26, 2019

Could somebody provide some example payload of the get_air_data response?

@skysilver-lab
Copy link

Could somebody provide some example payload of the get_air_data response?

https://mjdm.ru/forum/viewtopic.php?f=5&t=4863&start=770#p106185

{"result":{"co2e":1264,"humidity":45.400001525878906,"pm25":31.5,"temperature":29,"temperature_unit":"c","tvoc":0.3199849128723145,"tvoc_unit":"mg_m3"},"id":11}

@syssi
Copy link
Collaborator

syssi commented Aug 26, 2019

This is enough to provide basic support of the device.

@DiegoAstuy
Copy link

sorry one basic question it is possible to get the url command in order to integrate it in HA with the information from skysilver?

@fwestenberg
Copy link
Contributor

fwestenberg commented Oct 13, 2019

Added pull request #562
Working fine with Home Assistant locally, hope it will be released soon!

@rytilahti
Copy link
Owner

The next version will contain support for thanks to @fwestenberg - closing this issue now.

@sayzard
Copy link
Contributor

sayzard commented Jan 6, 2020

I found the solution. there are two things must be modified.

  1. id must be unique
  2. accessKey: token on the payload
Send b'{"id": 5, "method": "get_air_data", "accessKey": "5a6a6734316c6c5a434d584a32483756", "params": []}\x00'

Response {'co2e': 1120, 'humidity': 30, 'pm25': 41.5, 'temperature': 23, 'temperature_unit': 'c', 'tvoc': 1.0229264497756958, 'tvoc_unit': 'mg_m3'}

@fwestenberg
Copy link
Contributor

I found the solution. there are two things must be modified.

  1. id must be unique
  2. accessKey: token on the payload
Send b'{"id": 5, "method": "get_air_data", "accessKey": "5a6a6734316c6c5a434d584a32483756", "params": []}\x00'

Response {'co2e': 1120, 'humidity': 30, 'pm25': 41.5, 'temperature': 23, 'temperature_unit': 'c', 'tvoc': 1.0229264497756958, 'tvoc_unit': 'mg_m3'}

Solution to what problem? The integration is running fine here.

@sayzard
Copy link
Contributor

sayzard commented Jan 6, 2020

I found the solution. there are two things must be modified.

  1. id must be unique
  2. accessKey: token on the payload
Send b'{"id": 5, "method": "get_air_data", "accessKey": "5a6a6734316c6c5a434d584a32483756", "params": []}\x00'

Response {'co2e': 1120, 'humidity': 30, 'pm25': 41.5, 'temperature': 23, 'temperature_unit': 'c', 'tvoc': 1.0229264497756958, 'tvoc_unit': 'mg_m3'}

Solution to what problem? The integration is running fine here.

For an example)

airqualitymonitor.py

def __init__
  start_id: int = 0 -> unique number (not the same as previous)

device.py

        if command=='get_air_data':
          cmd = {"id": self._id, "method": command, "accessKey":codecs.encode(self.token, "hex").decode()}
        else:
          cmd = {"id": self._id, "method": command}
miiocli airqualitymonitor --ip IP --token  TOKEN raw_command get_air_data "[]"

@DiegoAstuy
Copy link

Integration is working fine in my side too, but not all the parameters from the unit are shown in HA; I just got CO2e, TVOC and PM2.5 but no Temperature, Humidity and battery. I don´t know if I´m missing something

@rytilahti
Copy link
Owner

Please open a separate issue for that, the basic support is already in place.

Repository owner locked as resolved and limited conversation to collaborators Jan 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests