Time_pattern trigger does not allow more than 59-minute interval

After upgrading to 0.115.0 yesterday, I started getting this error:

2020-09-19 12:25:43 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: must be a value between 0 and 59 for dictionary value @ data[‘minutes’]. Got None. (See /config/configuration.yaml, line 155).

I have this automation that was working through 0.114.4:

- id: daytime_light_periodic_90_turn_off
  alias: Periodically (every 1.5 hours) turn off lights during daytime
  trigger:
    - platform: time_pattern
      minutes: '/90'
...

I think it’s complaining about ‘/90’. Does anyone know if this was intentional change or a bug ?

Thanks.

1 Like

Intentional. Read the breaking changes for the release.

`/90’ never worked the way people who used it thought it did. By that I mean it never repeated every 90 minutes. To prevent people from continuing to believe that it does do that, they now flag it with the error message you’ve seen.

1 Like

For something like that, you could use a state trigger of the light being on for 90 minutes instead.

Nah !
That would be the sensible way of doing it.
It’s much better to turn a light on at say 87 minutes in and have it turn off 3 minutes later
:rofl:

This is a z-wave light switch. I have had some issues in the past in which status reporting was not reliable, so I got into the habit of never trusting the light switch correctly reporting the status to be on. That’s why I just always send a “turn off” command regardless of the status of the switch.

Hello !
I (wrongly apparently) used the time_pattern for a near reason than naustin.
Mine checked if radiator are still on “every 123mn”, in case the “OFF” triggers didn’t work (for example after a reboot).
Ex. :

- alias: "Chauffage SdB OFF"
  trigger:
    - platform: time_pattern
      minutes: '/123'
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: timer.chauffage_sdb
        state: 'idle'
      - condition: state
        entity_id: timer.chauffage_sdb_60
        state: 'idle'
  action:
    - service: switch.turn_off
      entity_id: switch.chauffage_sdb

But I still can’t understand how to do “the right way”.
Any help please ?

You can’t have 123 minutes, because there’s only 60 minutes in the hour

You can check for the switch being on for 123 minutes, using a state trigger. There’s likely many other options, but it’s hard to solve the problem when all we have is your automation :wink:

The right way of doing what >
If you want a ‘trigger’ every 123 minutes
Then the simplest method would be to have two scripts with 123 minute delays, do your action and call the second script, which is a repeat but then calls the first etc.
You’d have to call one of them on HA start up.

Or you could trigger an automation on start up with a suplementary trigger (ie two triggers) the second trigger being to run when time == input_datetime.next_trigger_value
the first action of the action section of the automation would be to set that datetime to 123 minutes from now - then the rest of your actions after setting the next trigger

If you still want to use an ‘easy’ interval, just change it to

- alias: "Chauffage SdB OFF"
  trigger:
    - platform: time_pattern
      hours: '/2'

You’ll lose the 3 minutes though.

But just so you know, prior to this error message, your automation was running every 3 minutes, not every 123. The calculation is called modulo and represented by the percent symbol (%). Modulo (%) will returns the remainder when you divide 2 numbers. For example, if I do 123 % 60… 123 is divisible by 60 twice. So… 123 - (60 * 2) = 3. And that’s the remainder. This module is performed on every time_pattern field:

  • seconds: - modulo 60 is performed because there is 60 seconds in a minute.
  • minutes: - modulo 60 is performed because there is 60 minutes in a hour.
  • hour: - modulo 24 is performed because there is 24 hours in a day.

EDIT: You could try using:

- alias: "Chauffage SdB OFF"
  trigger:
    - platform: time_pattern
      hours: '/2.05'

Not sure if it will work though. But that’s 123 minutes.

1 Like

Duh ! I’m an idiot for not suggesting that myself, derailed as I was concentrating on the 123 minute bit.

Edit: @Fanch - And before you suggest it (or worse try it for yourself) No, you can’t specify : -
hours: /1.5

1 Like

I’m thinking something like this should also work, but it’s cumbersome. This is doing trigger times calculation yourself and listing them out. It is slightly different since the “/X” notation is relative to the time HA started whereas this one isn’t.

- id: daytime_light_periodic_90_turn_off
  alias: Periodically (every 1.5 hours) turn off lights during daytime
  trigger:
    - platform: time
      at: "07:00:00"
    - platform: time
      at: "08:30:00"
    - platform: time
      at: "10:00:00"
...

This should match every 123 minutes shouldn’t it?

  trigger:
    - platform: time_pattern
      minutes: '3' # 3 minutes past the hour
      hours: '/2' # every 2 hours

Edit: no this is not correct. See below.

I think it will be every 2 hours on the 3rd minute. I can’t say for certain.

How does the /2 work?

So let’s say HA started at 9:04am, would the the ‘/2’ trigger at 11:04am and end up not matching the “3 minutes past the hour” ?

Ah, yeah you’re right. It triggers every 2 hours, just at 3 minutes past the hour.

No, as soon as the hour is divisible by 2 with no remainder it would trigger. i.e. at 10:00 in your example.

Well, it was not clear in the doc (at least when english is not your first language) that the time_pattenr algorithm “just” uses a modulo. But it makes sense as it’s not a "job scheduler / Task planner.

I generally try not put “round hour” triggers, to avoid potential overheads of the RPi. but I switched to hours : '/2'.
(Of course, I tried “/2.05” just before to read here that it doesn’t work, but I can confirm : it does not work and send no error).

Thank you all, I’ll be able to update my hassio, but I’ll still thinking about the way to have a “every 123mn” pattern, just for science.

1 Like

I agree. But it’s usually hard to explain modulo to non-programmers. If you have any pointers for the documentation to make it more clear, please make suggestions.

Yes, it’s not a math manual :slight_smile:
Perhaps in the “warnings” section, just a sentence that gives the limits (0-60 and 0-24) ?