miio icon indicating copy to clipboard operation
miio copied to clipboard

Add 'zhimi.airpurifier.mc1' air purifier model

Open arrizer opened this issue 6 years ago • 23 comments

Some Air Purifier S2 models have this model name but apparently work fine otherwise.

arrizer avatar Oct 28 '18 11:10 arrizer

I have only one issue here, how did you retrieve a proper token? Wherever I use a token received by miio discover I get a message UnhandledPromiseRejectionWarning: Error: Could not connect to device, token might be wrong

Exelord avatar Oct 31 '18 08:10 Exelord

I was not able to get the token from the device (cli reported ???). I was also unable to set up the device by connecting directly to it's WiFi and using the miio cli (command was sent, but device never left the setup mode). I could however extract a token from the iOS app and add that manually to the tokens.json file of the cli. After that, device communication did work without any issues.

arrizer avatar Oct 31 '18 15:10 arrizer

How did you extracted from ios app? On Wed, 31 Oct 2018 at 17:02 Matthias [email protected] wrote:

I was not able to get the token from the device (cli reported ???). I was also unable to set up the device by connecting directly to it's WiFi and using the miio cli (command was sent, but device never left the setup mode). I could however extract a token from the iOS app and add that manually to the tokens.json file of the cli. After that, device communication did work without any issues.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/aholstenson/miio/pull/185#issuecomment-434741789, or mute the thread https://github.com/notifications/unsubscribe-auth/ABZrv1Uzq-J2hk2HhAr7DFih56lIaSymks5uqcmdgaJpZM4X96xW .

Exelord avatar Oct 31 '18 17:10 Exelord

Make an unencrypted device backup with iTunes, then pull the .sqlite database from the Mi Home out of the backup. It contains the tokens of all paired devices.

arrizer avatar Oct 31 '18 19:10 arrizer

@arrizer were you able to get the sensor stats? I am able to obtain the device core details and I am able to control it but can't get the sensors details.

Example:

Device ID: 80890738
Model info: zhimi.airpurifier.mc1
Address: 192.168.1.242
Token: TOKEN via stored token
Support: At least basic

but when I want to get stats:

if ( secondarg === "status" ) {
        miio.device({
        address: deviceip
}).then(device => {
                stats = device.getProperties([ 'power', 'mode', 'aqi', 'temperature', 'humidity' ])
                console.log(stats);
                process.exit();
})}

All I get is:

{ power: undefined,
  mode: undefined,
  aqi: undefined,
  temperature: undefined,
  humidity: undefined }

mensfeld avatar Nov 06 '18 11:11 mensfeld

Yes, I can successfully retrieve all properties. I also use the homebridge plugin homebridge-mi-airpurifier which uses this npm module and it can read/write all properties just fine.

arrizer avatar Nov 06 '18 16:11 arrizer

@arrizer could you share some of the code you use to get the properties and the rest of the setup?

mensfeld avatar Nov 07 '18 09:11 mensfeld

~ miio --version
0.15.6

I'm getting the token when I'm connected to zihimi... Wi-Fi

➜  ~ miio discover --sync
 INFO  Discovering devices. Press Ctrl+C to stop.

Device ID: 80854514
Model info: zhimi.airpurifier.mc1
Address: 192.168.13.1
Token: 0b2d53505... via auto-token
Support: At least generic

^C
➜  ~ miio inspect 80854514
 INFO  Attempting to inspect 80854514

Device ID: 80854514
Model info: zhimi.airpurifier.mc1
Address: 192.168.13.1
Token: 0b2d53505... via auto-token
Support: At least generic

Type info: miio
Capabilities:

Firmware version: 1.4.3_21104
Hardware version: MW300

WiFi: . (FE:01:1F:F9:72:12) RSSI: -256
WiFi firmware version: SD878x-14.76.36.p84-702.1.0-WM

Remote access (Mi Home App): Maybe

next I configure it using iOS (as I also could not configure via cli) and it does not show the token in discover mode :(

➜  ~ miio discover
 INFO  Discovering devices. Press Ctrl+C to stop.

Device ID: 80854514
Model info: zhimi.airpurifier.mc1
Address: 10.0.40.14
Token: ???
Support: At least generic

Was anyone able to control the 2s via this library?

artkrz avatar Nov 09 '18 21:11 artkrz

Was anyone able to control the 2s via this library?

I am. I'm still having problems getting the data out of it but the controls work fine. Here's my how-to on the token extractions for this device: https://mensfeld.pl/2018/11/extracting-the-device-token-from-xiaomi-air-purifier-2s-eu-for-domoticz-usage/

mensfeld avatar Nov 10 '18 09:11 mensfeld

@mensfeld In your example above, you try get a property called "temperature" but it's actually called "temp_dec" (see https://github.com/aholstenson/miio/blob/master/lib/devices/air-purifier.js).

I can read all properties from the air purifier device using the high-level API. You can also test it on the command-line:

miio protocol call <IPADDRESS> get_prop '["temp_dec","aqi","humidity"]' Works as expected.

arrizer avatar Nov 11 '18 15:11 arrizer

Is there a way to add token I got when device was in config mode to work with miio after it got configured? As I stated before, inspect isn’t showing the token but I did write it down.

artkrz avatar Nov 11 '18 19:11 artkrz

You just miio tokens update IPADDR --token TOKEN or edit JSON file.

It looks like, after 1.4.3 firmware update, token changes when the device is added to Mi Home app. I have done several attempts of method that worked previously (go into discovery, read token, connect Mi Home app), but now it fails. Workaround method provided by @mensfeld luckily works. Indeed I got different token than the one I got from discovery mode.

kfigiela avatar Nov 15 '18 13:11 kfigiela

I finally got it working but it's not straight forward since the latest app (Android at least) does not store tokens locally :( So here's what I did:

  1. Removed the purifier from my account
  2. Removed data and Uninstalled Mi Home
  3. Installed Mi Home 5.0.30 from APK mirror
  4. Added it back via Mi Home
  5. Extracted the token via backup

artkrz avatar Nov 24 '18 22:11 artkrz

Can we get this merged? I've tested this by installing miio directly from @arrizer's branch and it seems to be working fine through CLI - I've got readings from all 3 sensors and I'm able to set fan mode. I didn't test all commands yet.

I've configured my Purifier 2S directly through miio without using Mi Home app.

XenorPLxx avatar Dec 25 '18 22:12 XenorPLxx

I would also like to have this PR merged, any update @aholstenson or do you need anything fixed in this PR?

JoJ123 avatar Jan 02 '19 14:01 JoJ123

Somehow I've managed to find the token and use it in homebridge. My firmware is 1.2.9_21022 (Update is available to 1.4.3_21104 but i'll skip it for now).

I've rested the device wifi, connected with my mac to the advertised network. Ran a dump and got the token. I was unable to configure the new wifi network via miio, and I've configured it with my iPhone. After reconnecting to my home network, the device was discoverable, but token was ???. After manually configuring the token with miio token update I got another line in tokens.json, and the device now and responds to requests:

{
  "1314111xxx": "TOTOKENKEN",
  "miio:1314111xxx": "TOTOKENKEN"
}
$ miio protocol call 192.168.104.120 get_prop '["temp_dec","aqi","humidity"]'
 INFO  Attempting to call get_prop on 192.168.104.120

 INFO  Device found, making call

 INFO  Got result:
[
  201,
  5,
  39
]

I think the device was supposed to reset the token, once it's added by the Mi Home app, but I'm unsure why it didn't.

Please merge this PR, it works, just finding the token is PITA.

mspasov avatar Jan 20 '19 14:01 mspasov

I confirm this issue with 2s. Get_prop return values. Anybody know, how to use CLI to control 2s (controle fan, mode etc) ?

wteterycz avatar Jan 21 '19 09:01 wteterycz

@wteterycz

miio control 1.2.3.4 setFavoriteLevel 14 # 0...14
miio control 1.2.3.4 setMode favorite
miio control 1.2.3.4 setMode auto

alternatively, for low level access

miio protocol call 1.2.3.4 set_level_favorite '[14]'
miio protocol call 1.2.3.4 set_mode '["favorite"]'
miio protocol call 1.2.3.4 set_mode '["auto"]'

kfigiela avatar Jan 21 '19 09:01 kfigiela

@kfigiela Thank you, works fine

wteterycz avatar Jan 21 '19 17:01 wteterycz

How can one obtain the entire API documentation of a device? I have zhimi.humidifier.ca1, it hangs on get_prop method, is there a wiki page of all available methods/parameters?

AgentFire avatar Dec 03 '20 13:12 AgentFire

How can one obtain the entire API documentation of a device? I have zhimi.humidifier.ca1, it hangs on get_prop method, is there a wiki page of all available methods/parameters? @AgentFire Maybe this helps: https://www.home-assistant.io/integrations/xiaomi_miio and maybe this also: https://github.com/maxinminax/node-mihome

Pittini avatar Dec 03 '20 18:12 Pittini

it works like a charm :) should be merged

bnowak avatar Dec 18 '21 15:12 bnowak

@bnowak if you want you can open a PR on this fork https://github.com/salamwaddah/mijia-io

salamwaddah avatar Dec 18 '21 15:12 salamwaddah