merdok / homebridge-miot

Homebridge plugin for devices supporting the Xiaomi miot protocol
MIT License
388 stars 61 forks source link

Add support Xiaomi Mi Air Purifier A1 #47

Closed blastoma closed 3 years ago

blastoma commented 3 years ago

Hello! Can you add support Xiaomi Mi Air Purifier A1 (MJXFJ-150-A1) dmaker.airfresh.a1?

merdok commented 3 years ago

Hi, i am not yet sure but it looks to me as an older miio device. I can still add support for it using the MiCloud but for non-miot devices it usually means that some features will be missing.

blastoma commented 3 years ago

Hi, @merdok ! I think it is not an old device. For example, support for Home assistant – https://github.com/syssi/xiaomi_airpurifier/blob/develop/docs/dmaker.airfresh.a1.yaml and https://github.com/syssi/xiaomi_airpurifier/blob/develop/docs/dmaker-airfresh-t2017.md

merdok commented 3 years ago

Yes, based on the home assistant implementation I can see that this device is not a miot device but the older miio device. It might not be that old but it still uses the old miio protocol. Like I mentioned I can add support for the device but only through MiCloud which will probably limit the features a little bit.

blastoma commented 3 years ago

@merdok if you can, please, do it for me

merdok commented 3 years ago

Will add it, will be available in the next update! Will let you know when it is ready.

merdok commented 3 years ago

Did you by the way try to already add the device? If this is a miot device then a generic device should be created and a switch should appear which allows you to at least turn it on and off right now? Can you try that?

blastoma commented 3 years ago

@merdok, yes, I tried already. I set model = dmaker.fan.p5 and use MiHome auth.

merdok commented 3 years ago

Ok, and at least the power switch works?

blastoma commented 3 years ago

Yes, but with model = zhimi.airpurifier.mc2 and with some bug:

  1. [24/06/2021, 22:42:01] [homebridge-miot] This plugin generated a warning from the characteristic 'PM2.5 Density': characteristic was supplied illegal value: number 1284 exceeded maximum of 1000. See https://git.io/JtMGR for more info. 1284 – co2 level, not PM2.5
  2. PM2.5 names like Humidity in Homekit
  3. The other Fan level names
merdok commented 3 years ago

The properties does not match with the zhimi.airpurifier.mc2 device so they are all messed and hence the errors... Please wait till next update, proper support will be added then!

blastoma commented 3 years ago

Thank you so much! I will wait

blastoma commented 3 years ago

@merdok hi! Can you tell me next release date?)

merdok commented 3 years ago

If everything goes well then probably next Sunday or Monday.

merdok commented 3 years ago

Please try version 0.9.6. The device should now be supported.

blastoma commented 3 years ago

@merdok, hi! It works, but with some issues:

  1. co2 sensor is not shown on Homekit
  2. "Manual" mode names "Mode – None" on Homekit

The other in good!

merdok commented 3 years ago
  1. There is no co2 sensor in HomeKit as far as i know, or is there?
  2. This is how it is named by Xiaomi in the official spec, you can change the name of the switch by yourself to whatever you want.
blastoma commented 3 years ago
  1. There is. 4020d26009c8b3b8bd992839e3d76c95fcafcd66_2_363x500

  2. Thank you!

merdok commented 3 years ago

But i do not think that shows a value? How does the detail page look like?

blastoma commented 3 years ago

https://developer.apple.com/documentation/homekit/hmservicetypecarbondioxidesensor

Like this fa803c8a927ce4bfdb74ef45bcc32fd1eca30077_2_342x500

merdok commented 3 years ago

You are right! I see it now. I will add in the next update!

As I never had experience with such sensor, do you know what range is considered normal? And from what value is it abnormal?

blastoma commented 3 years ago

It depends on the Country. https://www.kane.co.uk/knowledge-centre/what-are-safe-levels-of-co-and-co2-in-rooms Typicaly: EXCELLENT – 400-800ppm GOOD – 800-1000ppm LOW – 1000-1500ppm CRITICAL – 1500-2000ppm+

In the flat max ppm can be 3000-4000

merdok commented 3 years ago

The carbon dioxide sensor has just two states: normal and abnormal. So I would need to know the usual value when the abnormal state needs to be triggered...

1000 seems like a good level to trigger abnormal, but maybe I will make that configurable.

blastoma commented 3 years ago

1000 – good level for abnormal. For example, in China, 1000 – normal level, after 1500 – abnormal

merdok commented 3 years ago

Ok, thanks for the info👍 As mentioned will add that in the next update! Will let you know when it is ready!

jimsmt commented 3 years ago

I have a Xiaomi Air Purifier MJXFJ-300-G1(Model: dmaker.airfresh.t2017),the plugin can identify the device model correctly, if I don't set the model in config, it will be added as a general switch to homekit, but the switch is not functional. Following is the log

[7/2/2021, 6:07:19 PM] [miot] [test device] Connected to device: dmaker.airfresh.t2017
[7/2/2021, 6:07:19 PM] [miot] [test device] Setting up device!
[7/2/2021, 6:07:19 PM] [miot] [test device] Fetching device info.
[7/2/2021, 6:07:19 PM] [miot] [test device] Doing device specific setup
[7/2/2021, 6:07:19 PM] [miot] [test device] Doing initial property fetch
[7/2/2021, 6:07:19 PM] [miot] [test device] Splitting properties into chunks. Number of chunks: 1. Chunk size: 14
[7/2/2021, 6:07:19 PM] [miot] [test device] Device setup finished! Device ready, you can now control your device!
[7/2/2021, 6:07:19 PM] [miot] [test device] Device connected!
[7/2/2021, 6:07:19 PM] [miot] [test device] Successfully saved device info!
[7/2/2021, 6:07:20 PM] [miot] [test device] Got device info! Device firmware: 2.2.0
[7/2/2021, 6:07:20 PM] [miot] [test device] Error while parsing response from device for property power. Response: {"did":"124411779","siid":2,"piid":1,"code":-4004}
[7/2/2021, 6:07:20 PM] [miot] [test device] Got initial device properties:
 [
  {
    "name": "power",
    "value": false
  }
]
[7/2/2021, 6:07:24 PM] [miot] [test device] Splitting properties into chunks. Number of chunks: 1. Chunk size: 14
[7/2/2021, 6:07:25 PM] [miot] [test device] Error while parsing response from device for property power. Response: {"did":"124411779","siid":2,"piid":1,"code":-4004}
[7/2/2021, 6:07:29 PM] [miot] [test device] Splitting properties into chunks. Number of chunks: 1. Chunk size: 14
[7/2/2021, 6:07:30 PM] [miot] [test device] Error while parsing response from device for property power. Response: {"did":"124411779","siid":2,"piid":1,"code":-4004}
[7/2/2021, 6:07:34 PM] [miot] [test device] Splitting properties into chunks. Number of chunks: 1. Chunk size: 14
^C[7/2/2021, 6:07:39 PM] Got SIGINT, shutting down Homebridge...
[7/2/2021, 6:07:39 PM] [miot] [test device] Splitting properties into chunks. Number of chunks: 1. Chunk size: 14
[7/2/2021, 6:07:42 PM] [miot] [test device] Error while setting property power to value true! Error: Call to device timed out
[7/2/2021, 6:07:43 PM] [miot] [test device] Poll failed! No response from device! Error: busy.

If I set the model number to "dmaker.airfresh.a1", and set micloud username and password, it always tells me " Error: The device requires a MiCloud connection! In order to control the device please specify a MiCloud username and password! Log as follow


[7/2/2021, 6:10:55 PM] [miot] [test device] Connected to device: dmaker.airfresh.t2017
[7/2/2021, 6:10:55 PM] [miot] [test device] Setting up device!
[7/2/2021, 6:10:55 PM] [miot] [test device] Fetching device info.
[7/2/2021, 6:10:55 PM] [miot] [test device] Doing device specific setup
[7/2/2021, 6:10:55 PM] [miot] [test device] Device requires MiCloud! Trying to connect!
[7/2/2021, 6:10:55 PM] [miot] [test device] Error: The device requires a MiCloud connection! In order to control the device please specify a MiCloud username and password! Canceling setup!
[7/2/2021, 6:10:55 PM] [miot] [test device] Trying to reconnect in 30 seconds...
[7/2/2021, 6:10:55 PM] [miot] [test device] Setup failed!
[7/2/2021, 6:10:55 PM] [miot] [test device] Error: MiCloud is required but login to MiCloud failed!
[7/2/2021, 6:10:57 PM] [miot] [test device] Could not retrieve device info: Error: Network communication is unavailable, device might be destroyed

Config:

{
  "platforms": [
    {
      "platform": "miot",
      "devices": [
        {
            "name": "test device",
            "ip": "192.168.2.xxx",
            "token": "xxxxxxxxx",
            "model": “dmaker.airfresh.a1”
            "micloud": [
            {
                "username": "myusername",
                "password": "mypassword",
                "forceMiCloud": true
            }]
        }
      ]
    }
  ]
}
merdok commented 3 years ago

@gitgayhub the way you specified the micloud in the config is wrong. Remove the [] brackets.

jimsmt commented 3 years ago

@merdok Thanks, I got it working now. By using model dmaker.airfresh.a1, I can get power switch, buzzer switch, heater switch and air quality , but only PM2.5, CO2 sensor is not shown. log attached:

[7/2/2021, 7:08:20 PM] [miot] [window opener] Successfully saved device info!
[7/2/2021, 7:08:21 PM] [miot] [test device] Error while parsing response from device for property co2_density. Response: {"did":"312312313212","siid":3,"piid":2,"code":-704040003}
[7/2/2021, 7:08:21 PM] [miot] [test device] Got initial device properties:
 [
  {
    "name": "power",
    "value": true
  },
  {
    "name": "mode",
    "value": 0
  },
  {
    "name": "heater",
    "value": false
  },
  {
    "name": "child_lock",
    "value": 70
  },
  {
    "name": "alarm",
    "value": false
  },
  {
    "name": "pm25_density",
    "value": 8
  },
  {
    "name": "co2_density",
    "value": 0
  },
  {
    "name": "filter_life_level",
    "value": 40
  },
  {
    "name": "filter_left_time",
    "value": 36
  }
]
[7/2/2021, 7:08:21 PM] [miot] [test device] Filter life level: 40%.
[7/2/2021, 7:08:21 PM] [miot] [test device] Error on initial property request! TypeError: this.getFilterLeftTime is not a function
[7/2/2021, 7:08:21 PM] [miot] [test device] Got device info from MiCloud:
 {
  "did": "14123123123",
  "token": "xxxxxx",
  "longitude": "0.00000000",
  "latitude": "0.00000000",
  "name": "Mi Fresh Air Ventilator",
  "pid": "0",
  "localip": "192.168.2.xxx",
  "mac": "xxxxxx",
  "ssid": "xxxxxx",
  "bssid": "xxxxxx",
  "parent_id": "",
  "parent_model": "",
  "show_mode": 1,
  "model": "dmaker.airfresh.t2017",
  "adminFlag": 1,
  "shareFlag": 0,
  "permitLevel": 16,
  "isOnline": true,
  "desc": "Device online ",
  "extra": {
    "isSetPincode": 0,
    "pincodeType": 0,
    "fw_version": "2.2.0",
    "needVerifyCode": 0,
    "isPasswordEncrypt": 0,
    "mcu_version": "0016"
  },
  "uid": 21321312312,
  "pd_id": 678,
  "password": "",
  "p2p_id": "",
  "rssi": -60,
  "family_id": 0,
  "reset_flag": 0
}

Model description file can be found at https://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:air-fresh:0000A012:dmaker-t2017:1

merdok commented 3 years ago

I will add proper support for your device in the next update. So to be sure, you need to use micloud to control the device, right? That would mean that it is an miio device and I need to add the micloud requirement.

As for the co2, the property does not match with the airfresh.a1, it has a different id on your device, but that will also be fixed as soon as I add proper support for your device!

Oh, and there is also an error! Will also correct that!

jimsmt commented 3 years ago

@merdok Thank you very much!

Seems that micloud is the only method to add this device to homebridge, right?

merdok commented 3 years ago

Yes, there is no other way using my plugin. Your device supports local commands but with the older miio protocol which is not supported here.

jimsmt commented 3 years ago

thank you anyway, I managed to use HA to add it to homekit. I tried to find a miio homebridge plugin but without success. HA is too heavy for this simple job, I still prefer homebridge if there's a miio plugin

merdok commented 3 years ago

@blastoma As of version 0.9.7 a CO2 sensor is now available on supported devices! @gitgayhub support for you device is now included in version 0.9.7!

blastoma commented 3 years ago

Hi, it works