I want to fire an automation but only if the time is anywhere between ± 30 minutes of sunset.
How to write this condition?
Thanks
Arun
I want to fire an automation but only if the time is anywhere between ± 30 minutes of sunset.
How to write this condition?
Thanks
Arun
I think this should work:
condition:
- condition: sun
after: sunset
after_offset: "-00:30:00"
- condition: sun
before: sunset
before_offset: "+00:30:00"
Thanks for clarification.
I was not sure if offset creates a point in time or a window of time. For example, if sun sets at 4:45 PM, then would offset of -30 minutes cause trigger to work only at 4:15 PM or would it create a time window of any time between 4:15 PM and 4:45 PM.
according to the docs it creates a window of time but not the window of time that you reference above.
the “after sunset” is a window of time between sunset and midnight. if you put in an offset it extends or shrinks that window.
so in the case of the “after sunset” it is from sunset till midnight. the after_offset of -30 minutes extends that window to 30 minutes before sunset till midnight.
the “before sunset” is from midnight of the night before till sunset. the before offset of +30 minutes extends that window to midnight of the night before till 30 minutes after sunset.
Since you “and” the two conditions together the only time that both conditions will be true is the 30 minutes before sunset (take from the -30 minutes after offset) until the 30 minutes after sunset (taken from the +30 minutes before offset).
At least I’m pretty sure that’s correct. It’s a bit confusing.
If you look at the chart in the docs it kind of explains it.
You nailed it…!!! The automation worked as expected last night and did not run this morning which is what I was expecting to happen. Thank you so much.
Please mark finity’s post as the solution.