How to make sure automation triggers in a set time interval?

Hi All,

I noticed that one of my automation did not run because I restarted my HA at about 22:00, and that was exactly the time it should trigger:

    trigger:
        platform: time
        at: '22:00:00'

I hoped to define a range say, minutes: ‘0-20’, but it doesn’t work (runtime error).
It says in docs that it is possible to match on interval, but it’s rather different - ‘/5’ will trigger every 5 minutes of a given hour.
It will do, but to me seems a bit over the top because of the whole hour.

Any ideas on how to avoid hardcoding triggering time and making sure the automation will eventually run in a given timeframe?

Is this really a problem? I mean, how often do you restart HA?

It should be something like:

automation:
  trigger:
    platform: time_pattern 
    minutes: '/5'
  condition:
    platform: time
    after: '22:00:00'
  action:
    service: light.turn_on
    entity_id: light.yourlight

This will check every 5 minutes, and turn on the light after 22:00.

It depends, but sometimes it takes only one restart to miss that important automation

Well, that automation turns down my central heating temperature for the night, and I don’t want it to leave it as it is all way long, So the answer is yes.

I think my solution is better, but still not quite happy with it:

  trigger:
    platform: time_pattern
    hours: '22'
    minutes: '/5'
    seconds: '00'
  condition:
    condition: template
    value_template: >
      {{ state_attr('climate.combi_boiler', 'away_mode') == 'off' }}
  action:
    service: climate.set_away_mode
    data:
      entity_id: climate.combi_boiler
      away_mode: 'on'

Add 4 spaces.

no spaces

4 spaces

If you use that technique (i.e., select a range of text then click the “Preformatted text” button, you have to make sure there is a blank line before the selected text. Or you can use the “three back-tick” technique, which I find easier:

```
abc
123
```

I think you’re looking for something like this:

- alias: Turn down heating at night
  trigger:
    - platform: time
      at: '22:00:00'
    - platform: homeassistant
      event: start
  condition:
    - condition: time
      after: '22:00:00'
      before: '05:00:00'
  action:
    - service: climate.set_away_mode
      data:
        entity_id: climate.combi_boiler
        away_mode: 'on'

Of course, change the before time in the condition as needed. Or you can delete the before option, in which case it will default to before midnight.

1 Like

Thanks for the code and explanation on code formatting. Not very obvious it is… :\