merdok / homebridge-miot

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

Device Request for: Mi Air Purifier 2H #31

Closed BigConspiracy closed 3 years ago

BigConspiracy commented 3 years ago

Hi Merdok,

Sorry in advance, if I post this in the wrong section. Would it be possible to add support for Xiaomi Air Purifier 2H; zhimi.airpurifier.mc2 .

merdok commented 3 years ago

Hi,

unfortunately the zhimi.airpurifier.mc2 is not a miot device. It uses the old miio protocol.

BigConspiracy commented 3 years ago

Hi,

I see. I appreciate the quick response and wish you and the project well.

merdok commented 3 years ago

Hi, i actually found a way to support older devices with the miot protocol. You should now be able to control the Mi Air Purifier 2H using this plugin from version 0.9.0. But for that device you need to specify your MicCoud credentials. You can try it out and let me know!

BigConspiracy commented 3 years ago

Thanks for taking the time to implement the miot protocol! I have salvaging Github for a newer and maintained plugin. I'll try it out and update you later. Thanks again!

BigConspiracy commented 3 years ago

I followed the instructions where I filled the required fields hereby Device ID, Token and Mi Account ID + Password (Tried with/without Force Micloud ID).
Please let me know, if I should follow other procedures for installation or reporting logs. ---------------------------------------- Log: [31/05/2021, 01:28:35] [miot] [AirPurifier] Connected to device: zhimi.airpurifier.mc2 [31/05/2021, 01:28:35] [miot] [AirPurifier] Setting up device! [31/05/2021, 01:28:35] [miot] [AirPurifier] Doing device specific setup [31/05/2021, 01:28:35] [miot] [AirPurifier] Device requires MiCloud! Trying to connect! [31/05/2021, 01:28:38] [miot] [AirPurifier] Successfully connected to MiCloud! [31/05/2021, 01:28:38] [miot] [AirPurifier] Doing initial property fetch [31/05/2021, 01:28:38] [miot] [AirPurifier] Device setup finished! Device ready, you can now control your device! [31/05/2021, 01:28:38] [miot] [AirPurifier] Getting device info from MiCloud! [31/05/2021, 01:28:54] [miot] [AirPurifier] Poll failed 3 times in a row! Stopping polling and trying to reconnect! [31/05/2021, 01:28:54] [miot] [AirPurifier] Connected to device: zhimi.airpurifier.mc2 [31/05/2021, 01:28:54] [miot] [AirPurifier] Setting up device! [31/05/2021, 01:28:54] [miot] [AirPurifier] Doing device specific setup [31/05/2021, 01:28:54] [miot] [AirPurifier] Device requires MiCloud! Trying to connect! (node:23607) UnhandledPromiseRejectionWarning: TypeError: Cannot convert undefined or null to object at Function.keys () at ZhimiAirPurifierMc2._setupDeviceInternal (/usr/local/lib/node_modules/homebridge-miot/lib/protocol/MiotDevice.js:104:16) at ZhimiAirPurifierMc2.setupDevice (/usr/local/lib/node_modules/homebridge-miot/lib/protocol/MiotDevice.js:233:7) (Use node --trace-warnings ... to show where the warning was created) (node:23607) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:23607) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

merdok commented 3 years ago

Ok, seems that there are still some smaller issues which I need to resolve. This should not happen but I will handle this properly so it does not happen. This probably happened due to a bad connection the mi cloud servers...

Btw, what server is your device on? The more far away the server the worst the connection will be. You will have around the same delay as in the xiaomi home app.

BigConspiracy commented 3 years ago

I am connected to the DE server. I tried setting it to None and afterwards DE.

merdok commented 3 years ago

Can you also please post a homebridge debug log? I am interested to see if the poll failed due to high latency or another issue...

BigConspiracy commented 3 years ago

Hopefully, I have used the debug mode correctly on homebridge.

[31/05/2021, 17:51:48] [miot] [AirPurifierX1] Connected to device: zhimi.airpurifier.mc2 [31/05/2021, 17:51:48] [miot] [AirPurifierX1] Setting up device! [31/05/2021, 17:51:48] [miot] [AirPurifierX1] Fetching device info. [31/05/2021, 17:51:48] [miot] [AirPurifierX1] Doing device specific setup [31/05/2021, 17:51:48] [miot] [AirPurifierX1] Device requires MiCloud! Trying to connect! [31/05/2021, 17:51:48] [miot] [AirPurifierX1] Login in to MiCloud with username XXXXXX [31/05/2021, 17:51:48] [miot] [AirPurifierX1] Got device info! Device firmware: 1.4.3_23101 [31/05/2021, 17:51:50] [miot] [AirPurifierX1] MiCloud - Login step 1 [31/05/2021, 17:51:51] [miot] [AirPurifierX1] MiCloud - Login step 2 [31/05/2021, 17:51:51] [miot] [AirPurifierX1] MiCloud - Login step 3 [31/05/2021, 17:51:51] [miot] [AirPurifierX1] Successfully connected to MiCloud! [31/05/2021, 17:51:51] [miot] [AirPurifierX1] Doing initial property fetch [31/05/2021, 17:51:51] [miot] [AirPurifierX1] Splitting properties into chunks. Number of chunks: 1. Chunk size: 14 [31/05/2021, 17:51:51] [miot] [AirPurifierX1] Device setup finished! Device ready, you can now control your device! [31/05/2021, 17:51:51] [miot] [AirPurifierX1] Getting device info from MiCloud! [31/05/2021, 17:51:51] [miot] [AirPurifierX1] Device connected! [31/05/2021, 17:51:51] [miot] [AirPurifierX1] Successfully saved device info! [31/05/2021, 17:51:53] [miot] [AirPurifierX1] Got device info from MiCloud: undefined [31/05/2021, 17:51:56] [miot] [AirPurifierX1] Splitting properties into chunks. Number of chunks: 1. Chunk size: 14 [31/05/2021, 17:51:56] [miot] [AirPurifierX1] Error on initial property request! FetchError: network timeout at: https://api.io.mi.com/app/miotspec/prop/get [31/05/2021, 17:51:58] [miot] [AirPurifierX1] Poll failed! No response from device! Error: Error: No response or response empty! [31/05/2021, 17:52:01] [miot] [AirPurifierX1] Splitting properties into chunks. Number of chunks: 1. Chunk size: 14 [31/05/2021, 17:52:06] [miot] [AirPurifierX1] Splitting properties into chunks. Number of chunks: 1. Chunk size: 14 [31/05/2021, 17:52:06] [miot] [AirPurifierX1] Poll failed! No response from device! Error: FetchError: network timeout at: https://api.io.mi.com/app/miotspec/prop/get [31/05/2021, 17:52:08] [miot] [AirPurifierX1] Poll failed! No response from device! Error: Error: No response or response empty! [31/05/2021, 17:52:08] [miot] [AirPurifierX1] Poll failed 3 times in a row! Stopping polling and trying to reconnect! [31/05/2021, 17:52:08] [miot] [AirPurifierX1] Trying to reconnect [31/05/2021, 17:52:08] [miot] [AirPurifierX1] Device diconnected! [31/05/2021, 17:52:08] [miot] [AirPurifierX1] Connected to device: zhimi.airpurifier.mc2 [31/05/2021, 17:52:08] [miot] [AirPurifierX1] Setting up device! [31/05/2021, 17:52:08] [miot] [AirPurifierX1] Doing device specific setup [31/05/2021, 17:52:08] [miot] [AirPurifierX1] Device requires MiCloud! Trying to connect! (node:25350) UnhandledPromiseRejectionWarning: TypeError: Cannot convert undefined or null to object at Function.keys () at ZhimiAirPurifierMc2._setupDeviceInternal (/usr/local/lib/node_modules/homebridge-miot/lib/protocol/MiotDevice.js:104:16) at ZhimiAirPurifierMc2.setupDevice (/usr/local/lib/node_modules/homebridge-miot/lib/protocol/MiotDevice.js:233:7) (Use node --trace-warnings ... to show where the warning was created) (node:25350) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:25350) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

merdok commented 3 years ago

It seems like the device which you are trying to control is not available on the specified server? You said that your xiaomi home app is configured for Germany, right? Did you specify the property countryto de, like country: "de"? From what i can see in the logs you are connecting to the china server which is the default one.

merdok commented 3 years ago

Ahhhh, i just noticed that i currently ignore the country and always connect to the Chinese server🤦 Well in that case that explains your issue, even if you specified the country... I will correct that today and post an update later which should fix that.

merdok commented 3 years ago

@BigConspiracy Please try out version 0.9.1. The country should now properly be used which you specified in the config.json.

BigConspiracy commented 3 years ago

Sorry for the late reply. I just updated and restarted. It works perfectly! Thank you very much. If I stumble upon anything, I'll update you :-)

BigConspiracy commented 3 years ago

I receive this error when trying to access the settings for the plugins besides that everything seems to be working :) Screenshot 2021-06-01 at 00 21 07

merdok commented 3 years ago

Good to hear that it is working now :)

And sorry about the settings issues, somehow that sneaked in... It should be fixed in version 0.9.2

BigConspiracy commented 3 years ago

I appreciate the support for older Mi devices even though that you didn't had to. I can see that you are constantly adding new devices (changelog) and must say. Thank you! You should post something or let someone be apple to buy you a coffee at least!

merdok commented 3 years ago

Thanks! That is true, I initially did not plan to support older devices with the plugin, but thanks to the MiCloud I can use the miot protocol to control even the older devices which makes this pretty straightforward. The biggest part was just to implement the MiCloud connection...

Anyway, there is a "Sponsor" link on the front page of the repository which can be used to buy me a coffee🙂 But I guess it is only visible on desktop.