#Automation to turn lights on not working when I have a timer condition in the and if section

1 messages · Page 1 of 1 (latest)

shy leaf
#

Hi, I'm having an issue with an automation not triggering when it should.

I have an Aqara FP300 Presence Sensor. Originally I had it connected to HA via zigbee2mqtt but it gave me stability issues. Same with ZHA. So instead I pulled out an Aqara Hub M2 that I had laying around and connected the FP300 to the hub via zigbee. Then added the Hub to HomeKit and from HomeKit into HA via the device integration. This gets the FP300 into HA in a much more stable way for me.

However now I have an issue with an automation. I included a screenshot of the automation. The disabled things are things I've tried to make it work. I have an automation setup to automatically turn the lights on when entering the room based on some conditions. The "And if" condition is set so that this automation only triggers when the room has been cleared for at least 15 minutes. This for example is so if I have the lights off to watch a movie and pause to get a snack part way through the lights don't just come back on when I return to the room. When the FP300 was connected via zigbee2mqtt this worked fine (minus the stability issues).

But now with how I have the FP300 connected to HA I can't get it to work when I have that "And if" condition set. I tried setting that to 1 minute, left the room, let it go clear for over a minute, then walked back in and the automation just doesn't trigger at all. I can tell cause the "Last triggered" stat indicates it was not triggered recently. But as soon as I disabled that "And if" timer the automation triggers just fine.

So it's like it thinks the time condition hasn't been met even though it has. Even when I still had it on 15 minutes I left the room and let it go clear (which shows properly in HA when I bring up the info for the sensor) for an hour. Walked back in and nothing happened. Wasn't triggered.

So I'm wondering if anyone knows why it isn't working or how I can get it to work?

steady scroll
#

In the future, please do not post screenshots of code or configuration... post the actual configuration, properly formatted.

State conditions (and state-based Device conditions) check the current state. The automation is triggered when the sensor turns "on", then your condition checks if it's current state is "off" and if that state has been stable for at least 15 minutes... neither of those is true, so the condition fails.

You need to use a template condition to check the value stored in the trigger variable's from_state property which holds the previous state object of the entity that caused the trigger to fire.

condition: template
value_template: >
  {{ now() - trigger.from_state.last_changed >= timedelta(minutes=15) }}

Also, the last_triggered attribute of an automation only updates when the trigger fires and all conditions pass., but the automation's debug Trace is updated pretty much any time the automation runs whether by natural trigger or manual firing.