Spent a whole day wrestling with this too, still could not find out why but wanted to post a workaround I found.
Workaround that might work for you:
On HA dashboard, go to the Homekit integration page (“HomeKit Device”), then find your device in the “Integration entries” list, click on the three dots beside that device, then select “System options”, then toggle “Enable polling for updates” to either on or off, then click Update.
Afterwards, my delay is gone even if I toggle it back to what it was before. So something in toggling that setting must have fixed it. At time of this writing, I am unsure how this could have possibly fixed it and how long this fix would last, but it is much better than nothing I guess.
More Background Info:
I have an Aqara FP2 sensor that was setup on the Aqara app and integrated with HA via the Homekit integration. Everything was working well for a while, zones were detecting and automations were triggering. Generally nothing to complain about. Then one day, all the automations from the FP2 zone triggers stopped working and while I was sitting there scratching my head for a minute, one of the lights turned on. I checked HA, the automation did execute for some reason. After some testing, I found there was a 20 to 30 second delay between me getting into a zone and HA firing off the automation.
After some more (a lot more) testing, I found that:
- Aqara FP2 detects the presence and movement with no problems as shown on the Aqara app.
- Home Assistant executes the automation as soon as it received the state change from “Clear” to “Detected”
- There was nothing in the debug logs that’d suggest any messages were dropped or whether there were relevant errors.
So this implies that something after the handoff from Aqara is delaying the signal and HA was performing faithfully as soon as it receives the signal. This leaves HomeKit as the most likely culprit but that’s a pretty big blackbox as it can be Aqara’s integration with Homekit, the Homekit protocol itself, the network that the HomeKit communications is on, or the Homekit Integration in HA. Digging into it more, I tried many solutions on the internet that did not seem to address the problem, most notably the various posts about mDNS, multicast, broadcast, and other Wifi / network settings. While I am sure it solves other problems, it didn’t help this one. I stopped barking up this tree after I paired another FP2 sensor and it was performing as intended without the delay. This meant that if it was a wifi / network problem, it is unlikely it’d be isolated to one device, and, if it was a homekit integration problem on HA, it probably should not only affect one device too (it can, but not likely).
So this pointed me to the individual device configuration. I then poked around for whatever I can tinker with on HA and found the workaround above to somehow work. I am guessing removing the device and reinstalling it works too, however, I was afraid that I might have to re-link or at least refresh all my automations since re-registering the device can cause some IDs to shift even if you name them back to the same entity name / ID. Re-installing was going to be my last resort, but I am glad I did not have to do it.
All in all, this solution has been working well. I am going to test out whether leaving “Enable polling for updates” off might actually be helpful here since the FP2 would be the one to do the pushing. I am unsure if luminance values or anything else is a poll, but personally I did not need those. Or, this polling setting might be totally irrelevant.
Anyways, hope this helps somebody who is frantically googling this issue to save sometime and hair pulling =D