Condition "within last X seconds"? How?

How do I set a condition that would be “true” if something happens within the last X number of time units?

Actual example: I’d like to get notified when I get home and forget to wash my hands afterwards (yeah, covid thing). I’d like to do this:

  • trigger: enter zone.home
  • condition: if bathroom body sensor doesn’t detect presence within 1 minute,
    Action: notify


{{(as_timestamp(now()))-(as_timestamp(states.sensor.bathroom.last_changed)) > 60 }}

Actually, you’d want a 60 second delay BEFORE checking that template to work in your scenario.


Trigger on being home for one minute.

With a condition as per @jivesinger above.

If it passes the condition send your notification in the actions.

1 Like

That’s exactly what I don’t know how to do. I use the Zone trigger as simply using State of being home just re-runs the automation whenever it sees me home and not only when entering the zone.

If you guys could basically create this one automation for me, it would help me tremendously in building all kinds of other automations myself later. I’m stumbling on the “within time range” condition thing.

I realize y’all are busy so thanks for any help!

I’m not sure why you can’t use this:

    platform: state
    entity_id: device_tracker.stoovie
    to: "home"
    for: "00:01:00"

You could do the following:

  • Define a 1 minute timer
  • Create an automation when you get home to start the timer
  • Create an automation triggered by the bathroom body sensor to stop the timer
  • Create an automation triggered by the timer finishing to give the notification
1 Like

Because that gets triggered randomly through the day. It’s super unreliable.

actually, it’s possible to use a more compact and intuitive version

{{ (now() - states.sensor.bathroom.last_changed).total_seconds() > 60 }}