I’ve tested it and I think this works! I was having my sensors permanently in “motion” and “open” state after a power cut and this fixed it!
I also saw that domoticz has implementation for the Xiaomi hub and I don’t see anyone there complaining about ghost openings. I think what they are doing is to rely only on the broadcast without polling (i.e. cmd: “read”) the gateway.
I also reported this API bug to Xiaomi but the response I got was that they can’t understand the issue I think any bug reports should be submitted in chinese to get this up the chain and this API bug resolved.
I’ve not yet tried @Danielhiversen code, but when my sensors went ghost mode, sending a “read” command would return with a “motion” message, so I don’t think that would fix the issue, but I may be wrong.
Relying only on the broadcast could indeed be a way around the issue. We could ignore the heartbeats which are the main issue here. But that would make it easier to miss states I guess.
Did you unplug and replug the gateway, thats the easiest way to test it? I had always ghost openings after this action. I have the eMail of the API developer, i wrote him in english but i didn’t get an answer yet. Next step is, that my chinese friend translates my issue and i hope i will get an answer.
I have one xiaomi gateway, but it can’t be discovered.
Do anyone know how can I fix this issue? Thanks in advance.
And I’ve turned off the 5G wifi.
Invalid Config:
The following components and platforms could not be set up:
xiaomi
Please check your config
Log:
The following errors have been logged this session:
17-03-21 12:27:49 ERROR (Thread-9) [homeassistant.components.switch.broadlink] Failed to connect to device.
17-03-21 12:27:57 WARNING (MainThread) [homeassistant.setup] Setup of sensor is taking over 10 seconds.
17-03-21 12:27:58 WARNING (MainThread) [homeassistant.setup] Setup of xiaomi is taking over 10 seconds.
17-03-21 12:28:03 ERROR (Thread-4) [custom_components.xiaomi] No gateway discovered
17-03-21 12:28:03 ERROR (MainThread) [homeassistant.setup] Setup failed for xiaomi: Component failed to initialize.
I can confirm its working well with a Ubiquiti Unifi AC access point coupled with a Edgerouter-X router.
The Unifi AP also works well with HA for presence detection.
I highly recommend these devices - might be a bit of a learning curve for some people to configure, but amazing value.