I have the following automation set to run every 27 minutes. For some reason it triggers at the 1 hour mark every hour as well and then starts it’s 27 minute count over again from there. This is causing it to trigger many more times throughout the day that it should. What causes this?
Around the minutes portion of the trigger? I can attempt it when I get home. Everything in that yaml was created via the editor. Following you’re link and digging further I see it used to be the case where the editor would produce invalid yaml but not anymore? Time_Pattern Automations Not Formed Correctly from UI Automations Editor
Either way I will give it a try. If I were to guess I’d say that isn’t or at least shouldn’t be since the automation is valid and running.
According to the doc that will just match at 27 minutes past the hour. The / is required to execute every X minutes (5 in the examples from the doc).
automation:
trigger:
platform: time_pattern
# Matches every hour at 5 minutes past whole
minutes: 5
automation 3:
trigger:
platform: time_pattern
# You can also match on interval. This will match every 5 minutes
minutes: "/5"
That’s unfortunate, I suspected that might be the case based on this wording in the
With the time pattern trigger, you can match if the hour, minute or second of the current time matches a specific value. You can prefix the value with a / to match whenever the value is divisible by that number.
So if they’re treating the full hour mark as 0 then it will always divide evenly and match (example 0/27 = 0). Whereas if they were using 60 it may or may not (2.22). I don’t think the core Linux cron works like this but I’m not sure. Maybe it does and that’s why it’s matching that way.
Looks like cron time patterns actually work that way, which is probably why the HA implementation works that way. It likely use cron behind the scenes.
For example, this 0 0/27 0 ? * * *
Translates to this, which triggers on each hour as well.
* Tue Oct 27 00:00:00 UTC 2020
* Tue Oct 27 00:27:00 UTC 2020
* Tue Oct 27 00:54:00 UTC 2020
* Wed Oct 28 00:00:00 UTC 2020
* Wed Oct 28 00:27:00 UTC 2020
* Wed Oct 28 00:54:00 UTC 2020
* Thu Oct 29 00:00:00 UTC 2020
* Thu Oct 29 00:27:00 UTC 2020
this is my exact thinking that is why I asked that you remove the “/”. The only time pattern based automation I have runs every 2 minutes using the /2 method. So I cant verify behavior of the /27. I just thought maybe run it without the /. Just trying to help
That’s what I fell back to since I cannot achieve what I want. Any oddball intervals that don’t naturally land on a 1 hour mark (example 7, 14, 17, 27, etc…) will trigger the automation too frequently (the defined interval plus every hour on the hour)
I’m working within API request limits and am attempting to call the API as frequently as possible without going over the limit within the given time period. Based on my parameters every 27 minutes was optimal (with a bit of buffer). So in this case the 3 minute difference of bumping to 30 mins isn’t a huge deal but it’s annoying that this may interfere with future scenarios where the interval is further off from the “on the hour” intervals. Guess in any case I’d just have to round it to the nearest interval that lands on the hour.
Unfortunately not. I think it’s a limitation of the underlying cron system that I assume is used. Similar issue described here. It’s been so long since I looked at this that I forget how much of the cron syntax this part of HA supports. Maybe the suggestion in this server fault post will help, maybe not.
I was looking for a solution for this and while I don’t think you can use cron syntax for this, there are other ways in home assistant. For example you can test if current unix timestamp (or you can use time from uptime intergration) is divisible by the desired interval, like so:
# will be true for one second, every 23 minutes
value_template: "{{ (now().timestamp() | int % 1380) == 0 }}"
You could set the above as a template value trigger. The only problem with this approach is that the triggers without entities in them are only executed once per minute, and they only trigger on value change, therefore the minimum resolution is 2 minutes. If you want more granular, let’s say “every 1 minute and 33 seconds”, then you need to set up time trigger to execute every second, and then put a value template condition that checks for the interval like in the above example. Executing automations every second might have some performance impact, but I haven’t had any problems so far.
Interesting solution. I definitely don’t need granularity down to the minute so the first suggestion on its own should work. Will see if I can find time to play around with it.