Condtion something on for less than x minutes

I want unlock a door automatically, but only within the 1st 5 minutes of my Bayesian sensor turning on.

I already have a series of automations that mark me as just arrived, home, just left and away. I use this right now, and it works fine for my goals. But as I’ve gotten more involved, I realize I dont really need these extra states, and they are not really being used other than this one thing.

Is there an option for
to: on
for less than x minutes?

I guess I can always do a value template Boolean based on the state time of my other Boolean sensor, just wondering what other ways people might go about this.

I use timers for this. I have an “entrance” timer that’s true for the first few minutes after someone arrives home. Handy to trigger multiple events from that single timer.

1 Like

Super great idea. Hmm, what has your expereince been with a timer if it gets triggered again before it runs out? Start over? Just curious

from the guide it looks like it would start over if called again.

I suppose if that were an issue for you, you could test for “timer is not idle” as a condition in your automation. Restarting is actually helpful for the way I’m using it.

But, yes - calling timer.start should start the timer over based on its duration.

I have an automation that checks whether my garage door was opened or closed within the last 10 min (implying I opened and closed it when I drove my car out) to decide whether it should auto-open when I return. You can see how I checked in the condition. You could use a similar template

  - alias: Should Auto Open Detect
    trigger:
      - platform: state
        entity_id: device_tracker.my_iphone
        to: 'not_home'
    condition:
      - condition: template
        value_template: "{{ (as_timestamp(now())-as_timestamp(states.cover.left_garage_door.last_changed)) < 600 }}"
    action:
      - service: input_boolean.turn_on
        entity_id: input_boolean.left_garage_auto_open
5 Likes
- alias: Do something in 5 minutes after you get home
    trigger:
      platform: state
      entity_id: device_tracker.you
      to: home
      for:
        minutes: 5
    action:
      service: script.turn_on
      entity_id: script.do_something