Long delays in automation: bad idea?

Hello,

I want to send a message after 15 minutes, if a window-sensor was opened, and then every 10 minutes, if the window stays open.

So it might be that the automation runs for several hours, mostly doing nothing.

Is it okay to use “repeat” and “delay” for that? Or would it be a better idea to store the start-time in a variable and check regularly (for example every 2 minutes) if a message is appropriate right now?

A restart of the server would reset the automation, but I think getting another reminder in 15 minutes instead of 10 minutes would be okay in this case.

Why not use an alert?

2 Likes

Thanks for your reply. The messages are embeded in a larger automation using multiple sensors and combining all messages into one to avoid too much messages.

Not sure I’m able to get this easily mapped to a alert… :blush: But if thats the best way… :thinking:

Not if the trigger was the window opening.

You can template alerts too, though they’re all separate.

Your automation could use a timer to re-trigger itself. That avoids many problems caused by restarting since timers are restored.

1 Like

Thanks for your replies!

Yes, I already found the trigger:

  - platform: homeassistant
    event: start

Is this the same as my idea as triggering the script every x minutes and check there if another message should be sent? Something like:

trigger:
    - platform: time_pattern
      minutes: "/1"

The question then would be how to determinate how many time has past since the first start of the alarm-messages. I thought about using window_sensor.last_changed to avoid creating another variable, but I fear that this might be reset by a restart as well.

Yes, but no.

The automation would be triggered by the window being open for 15 minutes, and the timer expiring.

When the automation runs it sends the notification and then starts the timer at 10 minutes.

2 Likes

Thanks, I’ll check into timers!

You suggested to store the next trigger time in a helper, which is what I do.
I then just put a automation on that helper, so no delays, no repeat checks. It just gets activated when it hits that timestamp.
When it is not in use, then the automation can be disabled or the timestamp can be set to something in the future, like by hundreds of years.

1 Like

A timestamp entity is not that different from the timer helper. The advantages of a timer helper are that HA knows that what it is for, so it is a bit easier to use (start, stop, pause, resume, reload, trigger, test) and it can be shown in a dashboard as a countdown. No need for templates or time calculation.

1 Like

Thanks for your replies. My main problem is currently: I’m writing a blueprint which I have to use a lot of times. So every time I have to manually create a timer-helper and some other helpers to store values which the notification in the timer need to display correctly. Then you have to manually use them as inputs when creating the automation from the blueprint. Is there no way to create these helpers automatically in some way in the blueprint?

Currently, the only thing an Automation Blueprint can produce is an automation.

Any entities referenced by the blueprint (switch, sensor, timer, counter, etc) must already exist because the blueprint can’t create them.

1 Like

Thank you for this information!