torifat/xiaomi-mi-air-purifier

Child lock and Filter life don't work in 2H and Pro H

Opened this issue · 19 comments

Child lock and Filter life don't work in 2H and Pro H. They throw Cannot read properties of undefined (reading 'value').

20/11/2021, 19:08:09] [homebridge-xiaomi-mi-air-purifier] This plugin threw an error from the characteristic 'Lock Physical Controls': Unhandled error thrown inside read handler for characteristic: Cannot read properties of undefined (reading 'value'). See https://git.io/JtMGR for more info.
[20/11/2021, 19:08:09] [homebridge-xiaomi-mi-air-purifier] This plugin threw an error from the characteristic 'Filter Life Level': Unhandled error thrown inside read handler for characteristic: Cannot read properties of undefined (reading 'value'). See https://git.io/JtMGR for more info.
[20/11/2021, 19:08:09] [homebridge-xiaomi-mi-air-purifier] This plugin threw an error from the characteristic 'Filter Change Indication': Unhandled error thrown inside read handler for characteristic: Cannot read properties of undefined (reading 'value'). See https://git.io/JtMGR for more info.

Version is homebridge-xiaomi-mi-air-purifier v2.0.0
NPM 8.1.4
Node 16.13

Affected Devices

  • Xiaomi Air Purifier 2H
  • Xiaomi Air Purifier 2S
  • Xiaomi Air Purifier Pro H

Reported by @Dane03 in #226 (comment)
Reported by @guesq in #226 (comment)

I need some volunteers to test 2* and Pro devices. I don't own those devices, so it's tough for me to test.

@torifat made a pull request #233

Thanks, @luluhoc. Can you please share the output of the following code snippet?

require('miio')
  .device({
    address: "?.?.?.?",
    token: "YOUR_TOKEN",
  })
  .then(console.log);

It should output something like:

MiioDevice {
  model=zhimi.airpurifier.mb3,
  types=miio:air-purifier, sensor, miio, air-purifier,
  capabilities=fan-speed, miio:led-brightness, pm2.5, relative-humidity, temperature, switchable-mode, mode, switchable-power, restorable-state, power, state
}

⚠️ If it spits out any private information please remove it before sharing.

guesq commented

Thanks, @luluhoc. Can you please share the output of the following code snippet?

require('miio')
  .device({
    address: "?.?.?.?",
    token: "YOUR_TOKEN",
  })
  .then(console.log);

It should output something like:

MiioDevice {
  model=zhimi.airpurifier.mb3,
  types=miio:air-purifier, sensor, miio, air-purifier,
  capabilities=fan-speed, miio:led-brightness, pm2.5, relative-humidity, temperature, switchable-mode, mode, switchable-power, restorable-state, power, state
}

⚠️ If it spits out any private information please remove it before sharing.

@torifat, this is the output of my device. Looks like my device is Air Purifier 2. I thought it was 2H. Sorry for the misinformation.

MiioDevice {
  model=zhimi.airpurifier.m1,
  types=miio:air-purifier, sensor, miio, air-purifier,
  capabilities=miio:buzzer, miio:led-brightness, miio:switchable-led, pm2.5, relative-humidity, temperature, switchable-mode, mode, switchable-power, restorable-state, power, state
}

Thank you, this will help me a lot.

@torifat This is the 2S:

MiioDevice {
  model=zhimi.airpurifier.ma2,
  types=miio:air-purifier, sensor, miio, air-purifier,
  capabilities=miio:buzzer, miio:led-brightness, miio:switchable-led, pm2.5, relative-humidity, temperature, switchable-mode, mode, switchable-power, restorable-state, power, state
}

(edit: relevant to #10)
Are you saying there differences depending on which version of the miio NPM module is installed?

@cbrunnkvist 2* & 3* devices use different method and property names. In my fork, I'm trying to make them same. For example this - torifat/miio@856110e. However, my end goal is to move to https://github.com/maxinminax/node-mihome.

Thanks, @luluhoc. Can you please share the output of the following code snippet?

require('miio')
  .device({
    address: "?.?.?.?",
    token: "YOUR_TOKEN",
  })
  .then(console.log);

It should output something like:

MiioDevice {
  model=zhimi.airpurifier.mb3,
  types=miio:air-purifier, sensor, miio, air-purifier,
  capabilities=fan-speed, miio:led-brightness, pm2.5, relative-humidity, temperature, switchable-mode, mode, switchable-power, restorable-state, power, state
}

⚠️ If it spits out any private information please remove it before sharing.

I will give you later, I can open another PR if you want i can leave your old properties and just add conditional if model is PRO

also check this out this guy listed all properties https://github.com/syssi/xiaomi_airpurifier

Can you folks try the new version 2.0.1 and see if it fixes your problem.

also check this out this guy listed all properties https://github.com/syssi/xiaomi_airpurifier

@luluhoc Thanks, but I don't actually need those. Xiaomi has an official API that gives you those. I'm asking you folks to run it to see what miio library gives us, not what is supported.

Can you folks try the new version 2.0.1 and see if it fixes your problem.

also check this out this guy listed all properties https://github.com/syssi/xiaomi_airpurifier

@luluhoc Thanks, but I don't actually need those. Xiaomi has an official API that gives you those. I'm asking you folks to run it to see what miio library gives us, not what is supported.

I will try it later when I'll get home from work :)

guesq commented

Can you folks try the new version 2.0.1 and see if it fixes your problem.

also check this out this guy listed all properties https://github.com/syssi/xiaomi_airpurifier

@luluhoc Thanks, but I don't actually need those. Xiaomi has an official API that gives you those. I'm asking you folks to run it to see what miio library gives us, not what is supported.

@torifat Thanks for your effort.
There are no error messages when starting Homebridge now.
The values of Filter Life Level and Filter Change Indication should be correct.
Filter Life Level

But when Fan speed is enabled and I'm trying to adjust the fan speed in Home app, I get the following errors:

[homebridge-xiaomi-mi-air-purifier] This plugin threw an error from the characteristic 'Rotation Speed': Unhandled error thrown inside write handler for characteristic: Mode `none` not supported. See https://git.io/JtMGR for more info.

When Child Lock is enabled and switched on or off in Home app, I get the following errors:

[homebridge-xiaomi-mi-air-purifier] This plugin threw an error from the characteristic 'Lock Physical Controls': Unhandled error thrown inside write handler for characteristic: device.changeChildLock is not a function. See https://git.io/JtMGR for more info.

Thanks @guesq, that's quite helpful. I will fix both of those issues soon.

Confirmed on 2S it doesn't spam logs anymore now 👍 , also power switch works fine. And if I enable speed control, it logs the same exception as @guesq's on changing its value:

2021-11-24, 4:24:19 PM { speed: 65 }
2021-11-24, 4:24:19 PM [Raspberry-HOOBS 1F84@Air Purifier 2S@Air Purifier 2S@Rotation Speed] Unhandled error thrown inside write handler for characteristic: Mode `none` not supported

An observation: at first sight it is a little bit ambiguous as to what should actually happen when you adjust Fan Speed because in the Mi Home app, (-for the 2S at least-), in two (🅰️Auto and 🌙Night) out of its three possible operating modes, there is no fan speed slider shown. Only the third mode (🖤Manual) lets the user pick a constant speed.

In the (Apple-)Home app however, the slider is shown all the time. However, in the other older plugins, while the Fan Speed is always visible, touching actually has the side effect of instantly throwing the device into Manual mode, which actually makes a lot of sense then. 🙂

@guesq and @cbrunnkvist I just released a new version homebridge-xiaomi-mi-air-purifier@2.0.2. Can you folks please check if it fixes the fan speed and child lock problem 🙏🏽.

guesq commented

@guesq and @cbrunnkvist I just released a new version homebridge-xiaomi-mi-air-purifier@2.0.2. Can you folks please check if it fixes the fan speed and child lock problem 🙏🏽.

@torifat Tested. While adjusting Fan Speed, the following messages show in logs:

MiioDevice {
  model=zhimi.airpurifier.m1,
  types=miio:air-purifier, sensor, miio, air-purifier,
  capabilities=fan-speed, miio:buzzer, miio:led-brightness, miio:switchable-led, pm2.5, relative-humidity, temperature, switchable-mode, mode, switchable-power, restorable-state, power, state
}
[12/4/2021, 6:30:30 AM] [homebridge-xiaomi-mi-air-purifier] This plugin threw an error from the characteristic 'Rotation Speed': Unhandled error thrown inside write handler for characteristic: device.changeFanSpeed is not a function. See https://git.io/JtMGR for more info.

While Child Lock is switched, the following messages show in logs:

[12/4/2021, 6:32:01 AM] [homebridge-xiaomi-mi-air-purifier] This plugin threw an error from the characteristic 'Lock Physical Controls': Unhandled error thrown inside write handler for characteristic: . See https://git.io/JtMGR 

@guesq and @cbrunnkvist I just released a new version homebridge-xiaomi-mi-air-purifier@2.0.2. Can you folks please check if it fixes the fan speed and child lock problem 🙏🏽.

Still 2.0.1 listed as the newest version in Hoobs!

Now it was showing up in Hoobs, 2.0.2 installed. Now it don’t even show the Fan speed control in HomeKit even if it is on in Hoobs. 🤔

[21/12/2021, 06:50:24] [homebridge-xiaomi-mi-air-purifier] This plugin threw an error from the characteristic 'Active': Unhandled error thrown inside write handler for characteristic: device.power is not a function. See https://git.io/JtMGR for more info. MiioDevice { model=zhimi.airp.mb3a, types=miio, capabilities= }

First of all, a big thank you very much for this.
I installed the latest 2.0.2, but as many have noted trying to use the fan speed slider results in the same following error, on either model MC1 or MA2:
Thanks again for looking into this.

MiioDevice {
model=zhimi.airpurifier.mc1,
types=miio:air-purifier, sensor, miio, air-purifier,
capabilities=fan-speed, miio:buzzer, miio:led-brightness, miio:switchable-led, pm2.5, relative-humidity, temperature, switchable-mode, mode, switchable-power, restorable-state, power, state
}
[1/19/2022, 9:47:30 PM] [homebridge-xiaomi-mi-air-purifier] This plugin threw an error from the characteristic 'Rotation Speed': Unhandled error thrown inside write handler for characteristic: device.changeFanSpeed is not a function. See https://git.io/JtMGR for more info.