Condition - for:?

Hi all!

What I’d like is to have an automation that runs a script when the front door is opened, but only once after my status is changed to ‘home’, But I can’t figure out how to do it. Is it possible to add “for” in the conditions - to say for example “state: home, for: <5 minutes”? Or is there some better way to do this? I know I could have another automation trigger an input boolean when I arrive/leave home, and have this automation look at the boolean as a condition, but I was just hoping for something neater. Thanks!

Found this in the forum:

With the information you’ve given, the following should work. If you don’t mind me asking what the rest of the automation is? There might be a better way.

condition:
  condition: template
  value_template: >
    {% set current = as_timestamp(now()) %}
    {% set device = states.device_tracker.name %}
    {% set stamp = as_timestamp(device.last_changed) %}
    {{ device.state == 'home' and current - stamp < 300 }}
1 Like

Thanks for the help, I’ll give that a try!

It’s absolutely ridiculous, but basically when I come home from work I want the Seinfeld theme to play when I open the door. Any help on how to achieve this is much appreciated, as I obviously don’t want that to happen every time the door is opened!

2 Likes

:rofl: This is hilarious.

I have a set of announcements that play. I might replace them with an applause track for a couple of days as a moral booster.

I use an input boolean that is set when I go to bed or when I arm the house alarm.
It is cleared when the announcement is played (triggered by a PIR) but the condition posted by @walrus_parka is a good one too.

1 Like