merdok / homebridge-miot

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

Unavailable devices report a zero temperature #417

Closed Avamander closed 1 year ago

Avamander commented 1 year ago

Describe the bug When a device is unavailable (in my case an Air Purifier 4 Pro) due to being disconnected from WiFi, it reports a zero (0) temperature when it should be reporting nothing (None). This causes temperature ranges in rooms to be shown like to 0.0C - 21.2C, which is wrong.

Expected behavior An unavailable device reports nothing instead of a zero.

Your config.json N/A

Debug log If this is really necessary I can provide it.

Screenshots N/A

merdok commented 1 year ago

Hi, the temperature sensor needs to return always a value or it will cause errors, but when the device is not connected to the plugin the sensor is marked as inactive so so not sure why homekit still picks it up...

Avamander commented 1 year ago

This would indicate there are cases where the temperature is zero but the device hasn't been marked inactive?

Would it be possible to always mark most devices inactive when temperature (and other readings) is zero?

merdok commented 1 year ago

0 is a valid value for the temperature sensor and certainly be possible so marking device with value 0 as inactive would be bad.

The question here is just why HomeKit ignores the inactivity mark.

Avamander commented 1 year ago

0 is a valid value for the temperature sensor and certainly be possible so marking device with value 0 as inactive would be bad.

Possibly, when looking at just the temperature. But there are other values that could all be zero, allowing quite trustworthy inactivity detection.

The question here is just why HomeKit ignores the inactivity mark.

This doesn't seem to be the case with other bridges, so I'd honestly consider it as the last possible case.

merdok commented 1 year ago

In order to fix the issue correctly, the reason needs to be found why the home app still picks up inactive sensors, maybe that will give me an idea how to properly mark sensors for devices which are not connected.

Avamander commented 1 year ago

[1/14/2023, 4:22:25 PM] [homebridge-miot] [Xiaomi Air Purifier 4 Pro] Error: Could not connect to device, handshake timeout [1/14/2023, 4:22:25 PM] [homebridge-miot] [Xiaomi Air Purifier 4 Pro] Error during connection! Retrying in 60 seconds!

And HomeKit shows: Active: No and Tampered: No. Yet it's indeed still included in the summaries.

merdok commented 1 year ago

Yes, so when homekit picks it up as not active, it does not make sense that it shows the temperature.

Avamander commented 1 year ago

Maybe it's an issue about the sequence of changes sent to HomeKit. E.g. updating the temperature of an inactive device to zero or vice versa, updating a temperature to zero when it should remain the last value.

merdok commented 1 year ago

That should not certainly cause it.

Avamander commented 1 year ago

Should but this seems to unfortunately be the only integration that exhibits this behaviour.

merdok commented 1 year ago

Then differences has to be located so that we can find out why it is happening and how to fix it. I currently am not aware what might be wrong...

Avamander commented 5 months ago

I'm still seeing this issue on v1.7.0.

I also noticed that sensors with 0 readings are not displayed as "Not Available" in HomeKit. Maybe marking those sensors as unavailable (not just inactive) would fix this issue?

merdok commented 5 months ago

I think making a sensor unavailable could potentially lead to other issues like announcements by Siri with something like "some of the devices are not responding"

Avamander commented 5 months ago

Yeah, but that would probably be better than these zero readings, these are also used in Siri announcements.

merdok commented 5 months ago

Yeah well it is kind of a tricky issue. We would need to have a look how manufacturers of native HomeKit sensors handle that...