Gday, Ive been woring on getting out light to turn on each morning but only if the trigger time at least 30 mins before sunrise. The result of my code below is that the light comes on at 5:45 no matter what (sunrise is 6:03 am at the moment. Any help appreciated.
- id: 'weekday_bedroom_light'
alias: Weekday Light Before Sunrise
trigger:
platform: time
at: '05:45:00'
condition:
- condition: sun
before: sunrise
before_offset: '00:30:00'
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
action:
service: light.turn_on
entity_id: light.bedroom
Yeah, it is confusing. The ābeforeā in before_offset just means it goes with the before option. Or to put that another way, it means the trigger has to happen before the desired time. The desired time is the event (sunrise or sunset) plus the offset. Positive offsets mean after the event, and negative offsets means before the event. So, you want the trigger to let the action run only if it happens before the desired time. So you use before: and before_offset:. But you also want the desired time to be before the event (in this case sunrise), so the offset has to be negative. So, before: sunrise and before_offset: '-00:30:00' means the trigger has to happen before 30 minutes before sunrise.