merdok / homebridge-miot

Homebridge plugin for devices supporting the Xiaomi miot protocol
MIT License
383 stars 62 forks source link

Add Support for Mi Purifying Fan #372

Closed ahmadnazirafiq closed 1 year ago

ahmadnazirafiq commented 1 year ago

Device model dreame.fan.p2018

Device name Xiaomi Smart Purifying Fan

Does the device require a MiCloud connection? No

Anything special about the device? Does it already work with the plugin with a limited scope? - Yes

MiPurifyingFan-01_1000x jpg copy

merdok commented 1 year ago

The device main type is a fan, so it will always be recognizes as that. If you wish to expose the additional data you can you use the propertyControl

ahmadnazirafiq commented 1 year ago

I see. But I’m not sure where to start. Is it propertyControl or propertyMonitor? I just want it to display its pm2.5 and pm10 sensor in addition to filter life. Using MiOT Spec fetcher, here’s what I wanted to add:

environment:pm2.5-density environment:pm10-density filter:filter-life-level

Where do I apply the above parameters on the sample code for propertyMonitor below?

"propertyMonitor": [ { "property": "battery:battery-level", "name": "Show bat level only when mode 1", "linkedProperty": "vacuum:mode", "linkedPropertyValue": 1 }, { "property": "vacuum:mode", "value": 2, "name": "Notify when mode 2 set" } ]

merdok commented 1 year ago

Oh, yes sorry. You need to use propertyMonitor for that. Please see the example and documentation in the README, should be self explaining.

ahmadnazirafiq commented 1 year ago

Oh, yes sorry. You need to use propertyMonitor for that. Please see the example and documentation in the README, should be self explaining.

Thank you. Does the filter life have to be displayed as light sensor instead of it showing inside the device details like it normally does? Because it showed up as Filter Maintenance in Homebridge but doesn't appear like it in HomeKit.

merdok commented 1 year ago

Well, propertyMonitor does not know what kind of property is behind there so it used the light sensor to display numeric values. Right now that is the best that be done. I might try to improve that in the future...

ahmadnazirafiq commented 1 year ago

I see. For reference, I have a robot vacuum that I use with a separate Xiaomi Roborock Vacuum plugin that exposes it as a fan. But it does display its filter life as well. See below:

Screenshot 2022-11-02 at 7 30 31 PM

In addition to that, I also have a Smartmi Stand Fan 2S (which has a built-in battery). Wouldn't it be cool if I can see its battery life as well just like the screenshot above? Haha.

By the way, there seems to be a bug that whenever Homebridge restarts, one of my fan "dmaker.fan.p9" Mi Tower Fan displays the fan speed as 0% until I had to manually adjust it.

merdok commented 1 year ago

It is not about the fan device itself as that supports it in HomeKit. The thing is that there are various devices out there with many different combinations of features. Until you posted the bug here I was not even aware that there is a fan with a built in air purifier😅 So it is uncommon for fans to report Filter state. With the robot vacuum it is a different story. Pretty much every vacuum reports that so that is added automatically.

As for the 2s fan, this is unfortunately impossible as the fan does not report the battery charging state.

For the other fan you would need to post a debug log to see why this is happening. Cannot tell without the log what the issues could be...

ahmadnazirafiq commented 1 year ago

Not sure if this helps but here's the log for the Mi Tower Fan (dmaker.fan.p9):

[02/11/2022, 22:38:41] [homebridge-miot] [Tower Fan] Initializing accessory! [02/11/2022, 22:38:41] [homebridge-miot] [Tower Fan] Creating Fan accessory for device Tower Fan! [02/11/2022, 22:38:41] [homebridge-miot] [Tower Fan] Found accessory class at ../modules/fan/FanAccessory.js! [02/11/2022, 22:38:41] [homebridge-miot] [Tower Fan] Accessory successfully initialized! [02/11/2022, 22:38:41] [homebridge-miot] [Tower Fan] Final properties to monitor: [ "fan:on", "fan:fan-level", "fan:horizontal-swing", "fan:horizontal-angle", "fan:mode", "physical-controls-locked:physical-controls-locked" ] [02/11/2022, 22:38:41] [homebridge-miot] [Tower Fan] Registering 1 accessories! [02/11/2022, 22:38:41] [homebridge-miot] [Tower Fan] Everything looks good! Initiating property polling! [02/11/2022, 22:38:42] [homebridge-miot] [Tower Fan] Device found! Setting up miot device from local connection! [02/11/2022, 22:38:42] [homebridge-miot] [Tower Fan] Device firmware: 2.1.3 [02/11/2022, 22:38:42] [homebridge-miot] [Tower Fan] Connected to device: dmaker.fan.p9 [02/11/2022, 22:38:42] [homebridge-miot] [Tower Fan] Doing initial property fetch. [02/11/2022, 22:38:42] [homebridge-miot] [Tower Fan] Preparing property poll! [02/11/2022, 22:38:42] [homebridge-miot] [Tower Fan] Splitting properties into chunks. Number of chunks: 1. Chunk size: 14 [02/11/2022, 22:38:42] [homebridge-miot] [Tower Fan] Successfully saved device info! [02/11/2022, 22:38:42] [homebridge-miot] [Tower Fan] Property fan:on value changed to ---> true [02/11/2022, 22:38:42] [homebridge-miot] [Tower Fan] Property fan:fan-level value changed to ---> 3 [02/11/2022, 22:38:42] [homebridge-miot] [Tower Fan] Property fan:horizontal-swing value changed to ---> true [02/11/2022, 22:38:42] [homebridge-miot] [Tower Fan] Property fan:horizontal-angle value changed to ---> 90 [02/11/2022, 22:38:42] [homebridge-miot] [Tower Fan] Got initial device properties: [ "fan:on: true", "fan:fan-level: 3", "fan:mode: 0", "fan:horizontal-swing: true", "fan:horizontal-angle: 90", "fan:alarm: false | (not synced)", "fan:off-delay-time: 0 | (not synced)", "fan:brightness: false | (not synced)", "fan:speed-level: 0 | (not synced)", "physical-controls-locked:physical-controls-locked: false" ] [02/11/2022, 22:38:42] [homebridge-miot] [Tower Fan] Starting property polling. country: cn [02/11/2022, 22:38:52] [homebridge-miot] [Tower Fan] Preparing property poll! [02/11/2022, 22:38:52] [homebridge-miot] [Tower Fan] Splitting properties into chunks. Number of chunks: 1. Chunk size: 14 [02/11/2022, 22:39:02] [homebridge-miot] [Tower Fan] Preparing property poll! [02/11/2022, 22:39:02] [homebridge-miot] [Tower Fan] Splitting properties into chunks. Number of chunks: 1. Chunk size: 14 [02/11/2022, 22:39:12] [homebridge-miot] [Tower Fan] Preparing property poll! [02/11/2022, 22:39:12] [homebridge-miot] [Tower Fan] Splitting properties into chunks. Number of chunks: 1. Chunk size: 14

merdok commented 1 year ago

Thanks! I see the issue now, will be fixed in the next update!

ahmadnazirafiq commented 1 year ago

Alright, I appreciate your time and response. Closing this ticket.