merdok / homebridge-miot

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

Add support for MI Air Conditioner Companion MCN #52

Closed jianyun8023 closed 3 years ago

jianyun8023 commented 3 years ago

Hello,

Would it be possible to add support for the Mi Air Conditioner Companion MCN?

Model: lumi.acpartner.mcn02 SKU: KTBL03LM Link: https://www.mi.com/buy/detail?product_id=9726

When setup in the plugin, it seems to connect successfully and is seen as a switch, but there are no additional controls. I see that python-miio has his support, you can refer to python-miio#809. If there is anything I can provide (logs, testing, etc.), I would be happy to help the best I can.

merdok commented 3 years ago

Hi,

I am wondering myself how this actually works that outlets can be air conditioners?šŸ˜…

Anyway, yes adding support for the device should be straight forward, the only thing which we will need to find out if this is actually a miio or miot device. From the issue you linked I saw that they use miio commands. When you right now add the device when you try to use the switch, does it actually do anything? Could you post debug log when you use the switch so we can check out if the device accepts the command?

If the device does not accept miot commands locally then I can use the MiCloud to make it work. So we just need to figure out if the device can be controlled locally using miot or if it requires MiCloud...

jianyun8023 commented 3 years ago

The air conditioner on the socket, I researched some time ago, it should be a miot device.

https://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:air-conditioner:0000A004:lumi-mcn02:1

The following is the desensitization log of homebridge: hb.log

merdok commented 3 years ago

What i can see from the log is that the property fetch call times out and this is a strong indicator that the device is not a miot device. Older devices use the old miio protocol but xiaomi built in a translator in the cloud to convert the miot commands from the specs which you posted here to local miio commands. So yes, i can add support for the device but it will require a MiCloud connection. You can also already check out now if the device will work with MiCloud by adding the following lines to your device config in the config.json:

"micloud":
 {
          "username": "email",
          "password": "pwd",
          "country": "cn",
         "forceMiCloud": true
},

Add your username and password and also the cloud country where your devices are located. That should make the device successfully sync the power property. Let me know if that is the case, and then i will add it.

jianyun8023 commented 3 years ago

@merdok Thanks for your help~ I use micloud to successfully control the power switch.

[7/2/2021, 12:36:20 AM] [miot] [lumi.acpartner.mcn02] Splitting properties into chunks. Number of chunks: 1. Chunk size: 14
[7/2/2021, 12:36:20 AM] [miot] [lumi.acpartner.mcn02] Chunks:  [
 [
  "power"
 ]
]
[7/2/2021, 12:36:20 AM] [miot] [lumi.acpartner.mcn02] MiCloud request https://api.io.mi.com/app/miotspec/prop/get - {"_nonce":"oFnyPHZXxsIBnUyE","data":"{\"params\":[{\"did\":\"333641900\",\"siid\":2,\"piid\":1}]}","signature":"Sg+tJCHFHghc/v4MAw5b+PmXf8in3bV5850z+3/2MBA="}
[7/2/2021, 12:36:20 AM] [miot] [lumi.acpartner.mcn02] Device properties updated: 
 [
  {
    "name": "power",
    "value": true
  }
]

[7/2/2021, 12:38:01 AM] [miot] [lumi.acpartner.mcn02] Set power property request! RAW: {"did":"333641900","siid":2,"piid":1,"value":false}
[7/2/2021, 12:38:01 AM] [miot] [lumi.acpartner.mcn02] MiCloud request https://api.io.mi.com/app/miotspec/prop/set - {"_nonce":"fksI9hG/ZPsBnUyG","data":"{\"params\":[{\"did\":\"333641900\",\"siid\":2,\"piid\":1,\"value\":false}]}","signature":"ja9ky0UA/1LBaw0TFzb6iZYspc/9OyxrTl1XaCtDDYE="}
[7/2/2021, 12:38:01 AM] [miot] [lumi.acpartner.mcn02] Successfully set property power to value false! Response: [{"did":"333641900","siid":2,"piid":1,"code":0}]
[7/2/2021, 12:38:02 AM] [miot] [lumi.acpartner.mcn02] Set power property request! RAW: {"did":"333641900","siid":2,"piid":1,"value":true}
[7/2/2021, 12:38:02 AM] [miot] [lumi.acpartner.mcn02] MiCloud request https://api.io.mi.com/app/miotspec/prop/set - {"_nonce":"M2r43PuZa+MBnUyG","data":"{\"params\":[{\"did\":\"333641900\",\"siid\":2,\"piid\":1,\"value\":true}]}","signature":"F435MotsgSn+t/+VryCDV9bgz5QpS6y/PwSuS6W+wxo="}
[7/2/2021, 12:38:02 AM] [miot] [lumi.acpartner.mcn02] Successfully set property power to value true! Response: [{"did":"333641900","siid":2,"piid":1,"code":0}]

image

merdok commented 3 years ago

Perfect! So as expected this is a miio device. I will add full support for it in the next update! Will let you know when the update is ready!

jianyun8023 commented 3 years ago

@merdok Wow, thatā€™s great~ Thank you very much.

merdok commented 3 years ago

Version 0.9.7 is now online with support for the device. Please try it and let me know!

ahmadnazirafiq commented 3 years ago

Hi,

Works great. However, when trying to tap and hold the tile in the Home app, it defaults to OFF thus turning it back off everytime I wanted to adjust the temperature. Also, the temperature meter stated 0.0 all the time.

IMG_9564

Here's the log on the dashboard:

[18/07/2021, 10:26:53] [homebridge-miot] [Aircond] Poll failed 4 times in a row! Stopping polling and trying to reconnect! (node:11151) UnhandledPromiseRejectionWarning: TypeError: this.getDevice(...).supportsSwingModes is not a function at AirConditionerAccessory.updateDeviceStatus (/usr/local/lib/node_modules/homebridge-miot/lib/modules/airconditioner/AirConditionerAccessory.js:245:56) at LumiAcpartnerMcn02. (/usr/local/lib/node_modules/homebridge-miot/index.js:126:33) at LumiAcpartnerMcn02.emit (events.js:387:35) at /usr/local/lib/node_modules/homebridge-miot/lib/protocol/MiotDevice.js:221:16 at runMicrotasks () at processTicksAndRejections (internal/process/task_queues.js:95:5) (node:11151) 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: 27) [18/07/2021, 10:26:53] [homebridge-miot] [Aircond] Connected to device: lumi.acpartner.mcn02 [18/07/2021, 10:26:53] [homebridge-miot] [Aircond] Setting up device! [18/07/2021, 10:26:53] [homebridge-miot] [Aircond] Doing device specific setup [18/07/2021, 10:26:53] [homebridge-miot] [Aircond] Device requires MiCloud! Trying to connect! [18/07/2021, 10:26:53] [homebridge-miot] [Aircond] Successfully connected to MiCloud! [18/07/2021, 10:26:53] [homebridge-miot] [Aircond] Doing initial property fetch [18/07/2021, 10:26:53] [homebridge-miot] [Aircond] Device setup finished! Device ready, you can now control your device! [18/07/2021, 10:27:14] [homebridge-miot] [Aircond] Poll failed 4 times in a row! Stopping polling and trying to reconnect! (node:11151) UnhandledPromiseRejectionWarning: TypeError: this.getDevice(...).supportsSwingModes is not a function at AirConditionerAccessory.updateDeviceStatus (/usr/local/lib/node_modules/homebridge-miot/lib/modules/airconditioner/AirConditionerAccessory.js:245:56) at LumiAcpartnerMcn02. (/usr/local/lib/node_modules/homebridge-miot/index.js:126:33) at LumiAcpartnerMcn02.emit (events.js:387:35) at /usr/local/lib/node_modules/homebridge-miot/lib/protocol/MiotDevice.js:221:16 at runMicrotasks () at processTicksAndRejections (internal/process/task_queues.js:95:5) (node:11151) 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: 28) [18/07/2021, 10:27:14] [homebridge-miot] [Aircond] Connected to device: lumi.acpartner.mcn02 [18/07/2021, 10:27:14] [homebridge-miot] [Aircond] Setting up device! [18/07/2021, 10:27:14] [homebridge-miot] [Aircond] Doing device specific setup [18/07/2021, 10:27:14] [homebridge-miot] [Aircond] Device requires MiCloud! Trying to connect! [18/07/2021, 10:27:15] [homebridge-miot] [Aircond] Successfully connected to MiCloud! [18/07/2021, 10:27:15] [homebridge-miot] [Aircond] Doing initial property fetch [18/07/2021, 10:27:15] [homebridge-miot] [Aircond] Device setup finished! Device ready, you can now control your device!

merdok commented 3 years ago

I think you do not have the latest version of the plugin hece there is the the error in the console. Please update to the latest version.

The temperature will be reported as 0.0 by the accessory since the device does not support temperature reporting

ahmadnazirafiq commented 3 years ago

Hi,

Appreciate your response. The plugin runs on the latest version tho, which is 0.9.7.

As for the temperature report, maybe if it could follow the temperature we manually adjust in the tile? Iā€™m using a separate ā€œMi Heatercoolerā€ plugin for the the old version of Mi Air Conditioner Controller and it does that.

merdok commented 3 years ago

Ah, you are right, it will be fixed in the next update. Also after the update the tile will show the temperature which you set.

ahmadnazirafiq commented 3 years ago

Thank you! You're awesome!

merdok commented 3 years ago

Should now be fixed in version 0.9.8

ahmadnazirafiq commented 3 years ago

Hi,

I can confirmed that its fixed now. Works really well. Thank you!