Automation set for specific minute intervals triggers at the start of every hour

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?

- id: '1603320704350'
  alias: 'Climate: Update Accuweather Conditions'
  trigger:
  - minutes: /27
    platform: time_pattern
  condition:
  - condition: time
    after: 05:00:00
    before: '23:59:59'
  action:
  - data:
      entity_id: sensor.accuweather_current_conditions
    service: homeassistant.update_entity
  mode: single

https://community.home-assistant.io/t/trigger-automation-every-30-minutes/132299

Just a guess but have you tried quotes? ’ ’

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.

Tried quotes there. No change. Still triggers on the hour every hour as well as at the expected intervals.

Instead of using the following:

Try:

  trigger:
  - minutes: 27
    platform: time_pattern

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"

unfortunately that is the expected behavior of the time_pattern trigger.

there was a discussion of that behavior in a thread not too long ago but I can’t remember where it was (maybe in the v115 or v116 release thread?).

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

https://www.freeformatter.com/cron-expression-generator-quartz.html

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

FYI I did try and it and it behaved as expected. Only triggered 27 minutes after the hour. 12:27, 1:27, 2:27, etc.

Okay, so then why do you not use the automation with /30 and have it trigger every 30 minutes?

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.

Hi, have you solved this? I am facing the same issue, since I want to trigger an automation every 40 minutes. 60 minutes is too long and 30 too short :wink:

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.

Can you use a timer ? On HA startup, setup the timer. When triggered just restart it.
Should work for ANY interval.

Thanks for the inspiration. You brought me to my solution shown below, just in case it’s of any value to anyone else.

23 minute pattern, starting at 3AM

{{ 
 ((now()-today_at("3:00")).seconds/60) | int % 23 == 0
}}

Of course, a time condition is required to prevent it from running before 3AM.
23 minute pattern, starting at midnight:

{{ 
 ((now()-today_at()).seconds/60) | int % 23 == 0
}}