Using a condition on a sensor so as not to trigger too often

I have read countless forum posts, tried a bunch of methods but cannot figure out why my tests are not working.

Problem: I want to send a notification if the front porch sensor sees something but only if its been more than 60 seconds since the last notification.

Using the template tester I put these in and the results always look correct to me:

{% set a = states.binary_sensor.frontporch_motion.last_changed.timestamp() %}
{% set b = now().timestamp() %}
{% set c = (now().timestamp() - states.binary_sensor.frontporch_motion.last_changed.timestamp()) %}
{% set x = (now().timestamp() - states.binary_sensor.frontporch_motion.last_changed.timestamp()) > 60  %}

And so I put my condition into the automation as follows:

condition: template
value_template: >-
  (now().timestamp() -
  states.binary_sensor.frontporch_motion.last_changed.timestamp()) > 60

But the sensor never sends an alert if the condition is in place.

Have I missed something obvious?

The simplest cheat in the automation would be to use this to get a “cooldown”.

Your template checks when the sensor last updated which will always be “right now” when running I assume. Instead check to see when the automation last triggered.

    value_template: >-
      {{ ((now()) - state_attr('automation.whatever_it_is','last_triggered')).seconds > 60 }}

@Tinkerer I tried the automation last triggered:

condition: template
value_template: >-
  (now().timestamp() -
  state_attr('automation.notify_frontporch_motion','last_triggered').timestamp())
  > 60

It still stops any triggering (like my old method). Unsure why.

BUT the good thing is the other way you suggested with the delay is so much better/easier! Thank you!

There’s a much easier way now.

Put a 60 sec delay at the end of your actions and set the automation run mode to single (or not bother as it is the default).

1 Like

Yes! I am using that method now - sooo much easier!