Single automation with several triggers to turn light on/off during day

I’m trying to set up an automation that turns a light on at 4:30 AM, off at sunrise, on at sunset and off at 9:30 PM. I set up the automation in the UI but it doesn’t make anything happen to the light. This is the code

alias: Living light control
description: ""
trigger:
  - platform: time
    at: "04:30:00"
condition: []
action:
  - type: turn_on
    device_id: 9b4d51f1a2d52d3a8031aff13c3b84b2
    entity_id: 9860cff2bf7d2dc8d0677eab346585ac
    domain: light
  - wait_for_trigger:
      - platform: sun
        event: sunrise
        offset: 0
    timeout:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: 9b4d51f1a2d52d3a8031aff13c3b84b2
    entity_id: 9860cff2bf7d2dc8d0677eab346585ac
    domain: light
  - wait_for_trigger:
      - platform: sun
        event: sunset
        offset: 0
    timeout:
      hours: 0
      minutes: 2
      seconds: 0
      milliseconds: 0
  - type: turn_on
    device_id: 9b4d51f1a2d52d3a8031aff13c3b84b2
    entity_id: 9860cff2bf7d2dc8d0677eab346585ac
    domain: light
  - wait_for_trigger:
      - platform: time
        at: "21:30:00"
    timeout:
      hours: 0
      minutes: 3
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: 9b4d51f1a2d52d3a8031aff13c3b84b2
    entity_id: 9860cff2bf7d2dc8d0677eab346585ac
    domain: light
mode: single
type or paste code here

In the automation list it says that it was triggered at 4:30AM but the light didn’t turn on, and it wasn’t turned off at sunrise. Initially it had no delay on the timeout and I thought that might be the problem, but adding a minute to each didn’t fix it. I have several other automations that have only one trigger for these different on/off events for other devices, and they work. I thought by combining them together I could just have one automation. I’m a HA beginner - help/explanations much appreciated

The way you have configured the automation what will happen is:

  1. At 4:30, the light will turn on.
  2. 1 minute later (or earlier if Sunrise is between 4:30 and 4:31) the light will turn off.
  3. 2 minutes later the light will turn on.
  4. 3 minutes later the light will turn off.

So, because of the timeouts, the automation will be done by 4:36 and won’t do anything until the next morning. Wait timeouts should only be filled in when you want to limit how long the action stays “waiting”.

Instead of using long waits, move all those triggers you have in the waits to the trigger block and assign each an appropriate ID like in this example.

Thanks - that works perfectly! I tried it on an on-off series with 15 second gaps. All I need to do now is to insert the different platforms (sun/time) in the right places and I’m all go. Thanks for the quick reply - it’s a real help to a beginner trying to navigate HA complexities and jargon

Sidenote: :slight_smile: