Automation to wait for condition is met?

I have a device on my roof which tells me how much light is outside. I want to combine this with a trigger for when the sun goes down, to turn on my outdoor lights.

The idea is that i have say a trigger of 2 hours before sunset, the light outside should turn on, but only when the light level outside goes below 10…

If i create an automation with the trigger for sunset and -02:00:00 in offset, along with a condition that the outside lightlevel must be below 10, the light is never turned on, because the condition isn’t met at 2 hours before sunset.

How can i make the automation be triggered, by the 2 hours before sunset, but wait untill the light level gets below 10, if it is not ?

1 Like

wait_template is what you want

1 Like

Try using sun.sun with the elevation attribute

as a condition


  condition:
  - condition: numeric_state
    entity_id: sun.sun
    attribute: elevation
    below: '1'

as a trigger

    trigger:
      - platform: numeric_state
        entity_id: sun.sun
        attribute: elevation
        below: '1'

-6 is approximately the start of dusk/dawn

see here for further explanation.

https://www.home-assistant.io/docs/automation/trigger/#sun-trigger

I’m trying to only use the GUI, but I think I got it. Heres what the YAML looks like

alias: Auto - Solnedgang - Tænd ude
description: ''
trigger:
  - event: sunset
    platform: sun
    offset: '-02:00:00'
condition: []
action:
  - wait_template: '{{ states(''sensor.solar_radiaton'') | float < 17 }}'
    timeout: '02:00:00'
    continue_on_timeout: true
  - service: homeassistant.turn_on
    target:
      entity_id: group.udenfor
mode: single

Add a fixed delay before the next step. Delay an action until a specific timestamp. Delay an action until a specific event occurs. You can use a trigger from the Microsoft Dataverse connector or any other connector as a step in the middle of the flow to delay subsequent steps until a specific event occurs.

dgcustomerfirst

You should do the other way around.
Trigger on the light sensor and add a condition on the sunset -2h.

No need to wait, then.

@Da9L,

Did you end up using the code you posted above? I’m looking to do a similar thing. Trigger based on a temperature. The first time performs the actions but also starts a timer helper. Then next time it is triggered, if the timer helper is active, it will wait for it to expire before running the actions again and restarting the timer.

I think I could adapt your solution, but would be interested if it works and if you found a simpler solution.

Jamie