Random offsets in time patterns for triggers?

I’ve got a variety of automations that I like to run every 5, 15, or 20 minutes. Just to be nice to the server (and also because some of these generate notifications, and I’d like to avoid multiple notifications arriving to my phone or Echo all at once), it would be nice if they could be scattered around the hour. For example, I don’t need to check that my garage door is open exactly at 15, 30, and 45 past the hour. I just want to check about every 15 minutes.

It turns out that Jenkins has an interesting twist on the periodic time pattern feature (where you can say “/15” to mean "every 15 minutes). They let you include the ID number of the server (or maybe it was the task ID) as a fixed offset. For you programmers out there, it’s like they do a test like:
now() mod 15 == task_id mod 15
So, if task_id mod 15 evaluated to 7, then the event would fire at 7, 22, 37, and 52 minutes past the hour.

Does anybody know if HA has this capability? Even there isn’t the capability to add a random offset based upon some behind-the-scenes ID of the automation, maybe there’s some kind of syntax we could use like "/15 + 7". Right now, as a workaround, I’m just sticking different numbers in the seconds field of the time pattern, but that only lets me distribute the load within a minute.

I’m not sure if you can include this within a trigger, but you could use a random sensor with a wait action to achieve a similar effect

Why poll it at all?

Why not just automate based on state changes?

Door opens → do something.

Door closes → do something else.

1 Like

Because I might have missed the first alert (or was in the middle of something or away when the alert came in and forgot about it by the time I wasn’t busy or got home).

One example are my leak sensors under my sinks. I don’t want alerts about these between 12am and 8am, because leaks are usually not emergencies and I’ll get more grief from my girlfriend if she gets woken up by Alexa announcing the leak than I will from having to mop up more water from a few hours of leak. So, I have a condition on the automation that it has to be between 8am and 11:59pm. If the initial state change happens in the middle of the night, I want to get an alert soon after I get up in the morning.

Another example is an alert I have happen if the garage door has been open for more than 15 minutes. Sometimes, this is because I’m doing something in the garage, so I can ignore it, but I still want to guard against going back into the house and forgetting to close it when I’m all done.

A third example are my alerts for all of my door sensors which let me know if any of the perimeter doors are still open after 10pm. Sometimes, it’s still quite warm in the summer and it’s nice to have the doors open while I’m watching a movie, but I don’t want to forget that some of the doors are open for when I finally bed down.

In short, I just want some of my alerts to be “naggy”.

So, use alert to nag:

And how about a time pattern followed by a random delay? Delays can be templated with random numbers. Maybe the patterns work for time period triggers as well (haven’t tried), but for delays I use:

delay:
  hours: 0
  minutes: '{{ range(0, 30)|random|int }}'
  seconds: 0
  milliseconds: 0

1 Like