Sorry to raise this issue up again over a week later, but I’ve been trying to hunt down some more information that helps explain things with the device Health Check “Offline” status of Xiaomi devices.
Health Check uses two methods to determine whether a device is online, as explained in this post from last year:
Xiaomi devices are unusual in that their check-in reporting interval is rather long (between 50-60 minutes depending on whether it’s an “original” Xiaomi or Aqara device), and more importantly, with a few exceptions, they don’t respond to ZigBee read commands, which is what the “ping” method mentioned above uses as a last resort to check if the device is online.
The way the all the Xiaomi device handlers (both a4refillpad’s and in the bspranger/Xiaomi collection) are set up is this:
- The Health Check time interval is set to 2 hours, 2 minutes. So if 2 hours and 2 minutes have passed since the last event was posted by a Xiaomi device, then the ST hub will attempt the “ping” method, but no
pingfunction is included in the DTH because it won’t work anyhow, so the device will be marked as “OFFLINE”. The 2 hours, 2 minutes interval allows for one missed check-in. - When a Xiaomi device checks in every 50-60 minutes the message contains battery status, so a battery level event is generated for the ST hub. This satisfies the Health Check requirement of a device event to confirm that it is still online.
While testing DTHs and looking at the events list for Xiaomi devices, I have noticed that occasionally the ST hub misses a check-in with the battery status. I have no idea why this happens, but if it were to happen twice consecutively, then Health Check will mark the device as offline. I suspect this is what has happened to some people a few times in past, but with the recent Health Check problems that quite a few Xiaomi users have posted about, it’s more likely that either the Health Check time interval set-up wasn’t been honored, or some (or even all) battery status events were being ignored or missed.
If Health Check is working normally again, the only way that the number of false positives of Xiaomi devices being marked as offline can be reduced is to increase the Health Check time interval. Unfortunately, this does mean it will take that much longer to find out when a Xiaomi device has actually dropped its connection.
My suggestion is to bump the Health Check time interval up to a little over 6 hours. This will allow for 1-5 missed check-ins before the device is marked as offline. Another option is that a preference setting for the user to change the Health Check time interval could be added, say with a range of 2 to 24 hours (I don’t think it’s wise to allow 1 hour check intervals.)