Time triggers. Inelegant?

I’m struggling a little with simple time triggers.

A simple switch triggers to go on at a set time.
The same switch triggers to go off at a set time.

Is the only way to ensure these events happen to use:

  trigger:
    platform: time
    minutes: "/1"
    seconds: 0
  condition:
    condition: time
    after: '23:00:00'

Any other trigger may not get activated if for any reason HA isn’t running at that precise time. If I am right it seems a little inelegant to me. IfI am wrong, please tell me :slight_smile:

    ` automation reduce stairs brightness:

alias: Stairs - Reduce brightness at 11pm
initial_state: True
hide_entity: False
trigger:
platform: time
at: '23:00:00'
action:
- service: scene.turn_on
entity_id: scene.dim_s
- delay: '00:01:00'
- service: scene.turn_on
entity_id: scene.dim_s

I give up trying to format it!! You get the idea

If i understand you correctly, you just want to fire something at 11pm. This is what you would want:

trigger:
  platform: time
  at: "23:00:00"
action:
 - service: light.turn_on
   entity_id: light.mylight1

using “/1” in the minutes catagory will execute that every minute. With the condition you posted, your automation would occur every minute, on the minute from 11pm to midnight (excluding midnight).

are you asking how to ensure the automation runs if home assistant is down at 11pm for example?

there’s obviously a lot of overhead with triggering every minute. if it’s an important automation, i’d instead have additional automations when home assistant starts. so something like:

automation:
  trigger:
    platform: homeassistant
    event: start
  condition:
    condition: time
    after: '23:00:00'
    before: '06:00:00'
  action:
    ...

actually, to make it cleaner and not repetitious, i might do this:

- alias: "turn on light"
  trigger:
    platform: time
    at: '23:00:00'
  action:
    - condition: time
      after: '22:59:59'
      before: '06:00:00'
    - service: light.turn_on
      entity_id: light.some_light

- alias: "turn off light"
  trigger:
    platform: time
    at: '06:00:00'
  action:
    - condition: time
      after: '05:59:59'
      before: '23:00:00'
    - service: light.turn_off
      entity_id: light.some_light

- alias: "startup"
  trigger:
    platform: homeassistant
    event: start
  action:
    - service: automation.trigger
      entity_id: automation.turn_on_light
    - service: automation.trigger
      entity_id: automation.turn_off_light

automation.trigger will only run the “action” (the usual trigger: and condition: statements are ignored).

Thanks everyone, I have gone with something like @creakyshrimp suggested. It seems to cover everything.

- alias: check lights at startup
  trigger:
    platform: homeassistant
    event: start
  action:
    - service: automation.trigger
      entity_id: automation.dining_room_light_on_at_dusk
    - service: automation.trigger
      entity_id: automation.dining_room_light_off_at_11pm
    - service: automation.trigger
      entity_id: automation.dining_room_light_off_if_everyone_goes_out

- alias: dining room light on at dusk
  trigger:
    - platform: template
      value_template: '{{states.group.family_presence.state == "home"}}'
    - platform: numeric_state
      entity_id: sun.sun
      value_template: '{{ state.attributes.elevation }}'
      below: 5.0
  condition: 
    condition: and
    conditions:
    - condition: state
      entity_id: group.family_presence
      state: "home"
    - condition: numeric_state
      entity_id: sun.sun
      value_template: '{{ state.attributes.elevation }}'
      below: 5.0
    - condition: time
      before: "23:00:00"
  action:
    service: homeassistant.turn_on
    entity_id: switch.dining_room_light

- alias: dining room light off at 11pm
  trigger:
    platform: time
    at: "23:00:00"
  condition:
    condition: time
    after: '22:59:59'
  action:
    service: homeassistant.turn_off
    entity_id: switch.dining_room_light

- alias: dining room light off if everyone goes out
  trigger:
    platform: state
    entity_id: group.family_presence
    from: 'home'
    to: 'not_home'
  action:
    service: homeassistant.turn_off
    entity_id: switch.dining_room_light

condition in this template is pointless because the trigger will always occur after 22:59:59. Other than that, everything else looks good.

@petro
I think I might be starting to get the hang of this :slight_smile:

And yes, the condition is unnecessary, it was a throwback to some old logic before I was using

platform: homeassistant
event: start

Thanks!!

Yes yes, that makes sense. If you had another trigger in that automation, the condition would be useful!