miio icon indicating copy to clipboard operation
miio copied to clipboard

feat: air-purifier 3 support

Open kstasik opened this issue 4 years ago • 4 comments

correct me if im wrong but this project looks dead. I created PR some maybe someone find this code useful. Credits to https://github.com/rytilahti/python-miio/issues/543#issuecomment-575163356

kstasik avatar Jan 25 '20 16:01 kstasik

This is amazing, thank you for your work. I installed this and /clauzewitz/homebridge-xiaomi-purifier, and my Air Purifier 3H appears in HomeKit with current status.

I can then issue one command, e.g. power on, which works - but no response is returned to HomeKit and the whole accessory goes to "No response" state.

Further, the Buzzer and LED options do not appear to work at all. They return "On" even when actual state is "Off"

Would you suggest using a different version/pull of homebridge-xiaomi-purifier?

EDIT: Homebridge throws errors like this: [1/26/2020, 1:56:16 PM] [MiAirPurifierPlatform] [MiAirPurifierPlatform][ERROR]MiAirPurifier3BuzzerSwitchAccessory - Mute - getBuzzerState Error: Error: busy.

I have Homebridge config.js like so: { "accessory": "MiAirPurifier", "name": "Air Purifier", "ip": "192.168.1.55", "token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "showTemperature": true, "showHumidity": true, "showAirQuality": true, "enableLED": false, "enableBuzzer": false }

Should the "accessory" be "MiAirPurifier3" or similar?

Shaun-R avatar Jan 26 '20 02:01 Shaun-R

I used original: https://github.com/seikan/homebridge-mi-air-purifier

      {
            "accessory": "MiAirPurifier",
            "name": "Air Purifier 3 Living Room",

            "ip": "ip address",
            "token": "value",

            "showTemperature": true,
            "showHumidity": true,
            "showAirQuality": true
        }

I used this video to retrieve token: https://www.youtube.com/watch?v=g4pa7sesTzY

I found out that my device code is: zhimi.airpurifier.mb3 ( i bought device in europe )

I used this simple php script to decode token and find model name:

<?php

$filename = 'NAME_OF_FILE_mihome.sqlite';

$db = new PDO('sqlite:'.$filename);

$db->setAttribute(PDO::ATTR_ERRMODE,
                        PDO::ERRMODE_EXCEPTION);

$result = $db->query('SELECT ZNAME, ZMODEL, ZLOCALIP, ZTOKEN FROM ZDEVICE');

foreach($result as $r){
    print_r($r);

    echo decrypt_openssl($r['ZTOKEN']);
    echo PHP_EOL;
}

function decrypt_openssl($raw) {
    $key = str_repeat('0', 32);
    $key = hex2bin($key);
    $raw = hex2bin($raw);

	return openssl_decrypt($raw, 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
}

I think you can have different model name (maybe zhimi.airpurifier.ma4) and you should add correct mapping here:

https://github.com/aholstenson/miio/pull/277/files#diff-082a0303463873190e3974467cfb3d0fR38

kstasik avatar Jan 26 '20 12:01 kstasik

correct me if im wrong but this project looks dead. I created PR some maybe someone find this code useful. Credits to rytilahti/python-miio#543 (comment)

Thank you for your great work! Now my air purifier 3 works like a charm!

huongminh avatar Jan 31 '20 06:01 huongminh

Geat work @kstasik, it should be merged ASAP :muscle:

bnowak avatar Dec 18 '21 15:12 bnowak