Will this use of wait_template work? I’m trying to create a 1x catch all rule that fires on sunset, then checks if it’s after 17:45. If it’s not after 17:45 then the rule waits until it is before finally firing the actions.
I think you could achieve this more simply if you had two triggers and two conditions. The two triggers would be sunset offset and time, and the two conditions would be the sunset offset and time. That way it will only run once both conditions are met, regardless of which comes first.
I always thought all conditions of a trigger had to be true in order for the rule to fire.
But as noted in post #2 in this thread, matching any trigger condition will cause a rule to fire. Then any additional filtering could be performed with conditions.
EDIT: You need to use an “and” condition as detailed in the docs.
See below for an additional recommendation regarding this automation…
In your conditions, I would “offset” them by one minute from your trigger. That is, make your condition after: '17:44:00' and after_offset: '-0:46:00'
The reason I recommend this is because say 17:45 is after sunset. Once the automation fires at 17:45, it will fail the condition, because it’s at 17:45, not after 17:45. I’m not sure if this is how it would behave in practice, but it’s my best guess.
Thanks for advice. I always thought that conditions all had to evaluate to being true in order for the rule to perform it’s actions. So I’ve updated the rule and will report back if it works as expected.
trigger:
- platform: sun
event: sunset
offset: '-00:45:00'
- platform: time
at: '17:45:00'
condition:
condition: and
conditions:
- condition: time
after: '17:44:00' #offset by 1 min from trigger just in case
weekday:
- mon
- tue
- wed
- thu
- fri
- condition: sun
after: sunset
after_offset: '-00:46:00' #offset by 1 min from trigger just in case
action:
- delay: '00:{{ (range(0, 15) | random) }}:00'
- service: homeassistant.turn_on
entity_id: group.living_room_lights_card