I have an automation which isn’t being triggered reliably, even when the trigger event is being logged by HA.
The trigger comes from a PIR sensor. When occupancy is detected the automation should fire, but it doesn’t always do so.
This is the automation:
Here is an extract from my HA log, showing occupancy being detected twice in the five minute period (at 12:53:09 and 12:56:53), but the automation only being triggered once (at 12:56:53). This has been happening alot over the last week.
Any idea why the automation isn’t firing every time, when the event is being logged by HA? I’m running HA 2024.12.5
Check your automation traces to determine why it didn’t run. The logbook is only useful for triggers.
Wild guess - it’s the illuminance condition. Most Pirs only update illuminance after they detect motion.
Your second trigger caused the automation to run correctly because illuminance was updated to >3500 when the previous trigger ran a few minutes before that.
Assuming I’m not wrong, adding a check that entity has been in the on state for 1s (or less) to your trigger should fix this.
Thanks. That could well explain this particular example, as the motion sensor looks like it was triggered shortly after the front door was opened and closed - which would have raised the illuminance level for a short while.
Sorry for being dense, but I can’t work out why adding the 1sec condition would help?
I’ll keep an eye on this and see if it explains all of the other apparent anomalies.
Yes sorry that’s exactly what I thought you meant. What’s the rationale behind that? Wouldn’t the occupancy status always persist for more than a second?
The rationale is that you’re probably encountering what is called a race condition.
The motion sensor registers occupancy and updates illuminance at around the same time. If there is even a few milliseconds delay between those two events, your automation would be already running and evaluates your condition as false.
Setting that 1s in the trigger should be enough of a delay to ensure your occupancy has been updated to the latest values before the automation’s condition is evaluated.