Need help with "wait for trigger"

Dear community,
i really need some help with the “wait for trigger” part of an automation.

For the automation below, all well (the light comes as planned on) but fails to go off. If i put the value of the time (in the wait for trigger clause) quite close to the sunset it sometime seems to work…
The automation is done completely with the GUI…
Seems like i do not understand some fundamentals about it (even though a similar automation i used for test with a telegram notification does work without problems)…

Any help would be highly appreciated!

- id: '1628859999767'
  alias: Leduri in Living Seara
  description: ''
  trigger:
  - platform: sun
    event: sunset
    offset: -01:00:00
  condition: []
  action:
  - service: light.turn_on
    target:
      entity_id: light.shelly_shrgbw2_fc9842
    data:
      brightness_pct: 10
  - service: light.turn_on
    target:
      entity_id: light.shelly_shrgbw2_fc9c68
    data:
      brightness_pct: 80
  - wait_for_trigger:
    - platform: time
      at: '23:00:00'
    continue_on_timeout: false
  - service: light.turn_off
    target:
      entity_id: light.shelly_shrgbw2_fc9842
  - service: light.turn_off
    target:
      entity_id: light.shelly_shrgbw2_fc9c68
  mode: single

For an automation like this, where the second trigger is static (i.e. not being affected by something within the automation itself) it would be better to use two triggers and a “Choose” action instead of a “Wait for Trigger”.

If you are using version 2021.7 (or later) you can control which option of the “Choose” action is carried out very easily by using trigger ids.

Waits do not always survive restarts, so they aren’t always reliable… especially if they happen late at night and you’re tinkering with your automations in the evening and they are being restarted repeatedly… :grin:

- id: '1628859999767'
  alias: Leduri in Living Seara
  description: ''
  trigger:
  - platform: sun
    event: sunset
    offset: "-01:00:00"
    id: Sunset
  - platform: time
    at: '23:00:00'
    id: "23:00"
  condition: []
  action:
    - choose:
        - conditions:
            - condition: trigger
              id: Sunset
          sequence:
            - service: light.turn_on
              target:
                entity_id: light.shelly_shrgbw2_fc9842
              data:
                brightness_pct: 10
            - service: light.turn_on
              target:
                entity_id: light.shelly_shrgbw2_fc9c68
              data:
                brightness_pct: 80
        - conditions:
            - condition: trigger
              id: "23:00"
          sequence:
            - service: light.turn_off
              target:
                entity_id: light.shelly_shrgbw2_fc9842
            - service: light.turn_off
              target:
                entity_id: light.shelly_shrgbw2_fc9c68
  mode: single

Wow,

This is a nice idea!
Let me test it and I will tell you if it works…

Thanks a lot anyway!
Rafi

If you are interested, you can reduce the automation to this:

- id: '1628859999767'
  alias: Leduri in Living Seara
  trigger:
  - platform: sun
    event: sunset
    offset: "-01:00:00"
  - platform: time
    at: '23:00:00'
  action:
  - choose:
    - conditions: "{{ trigger.platform == 'sun' }}"
      sequence:
      - service: light.turn_on
        target:
          entity_id: light.shelly_shrgbw2_fc9842
        data:
          brightness_pct: 10
      - service: light.turn_on
        target:
          entity_id: light.shelly_shrgbw2_fc9c68
        data:
          brightness_pct: 80
    default:
    - service: light.turn_off
      target:
        entity_id:
        - light.shelly_shrgbw2_fc9842
        - light.shelly_shrgbw2_fc9c68

Thank you both a lot, it works like a charm!!!

In the above example you never triggered off using the “time” trigger though…?? Lights stay on forever.

The last example employs a Time Trigger scheduled for 23:00. When triggered, the action proceeds to the default in choose and turns off two lights.