I have an automation I want to run in the mornings at 07:00 but only if it is somewhere between 1 h. before sunrise to 1 h. after sunrise.
Would this condition work?
initial_state: True
trigger:
platform: time
at: '07:00:00'
condition:
- condition: or
conditions:
- condition: sun
before: sunrise
before_offset: "-1:00:00"
- condition: sun
after: sunrise
after_offset: "1:00:00"
action:
service: homeassistant.turn_on
entity_id: group.window_lights```
Will this trigger automation when the time is 07:00 and +- 1 h. to sunrise?
I can’t get this to work. The automation doesn’t trigger, even though sunrise is ~06:50. Can someone see what I’m doing wrong with this automation?
initial_state: True
trigger:
platform: time
at: '07:00:00'
condition:
condition: and
conditions:
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
- condition: state
entity_id: input_select.presence_mode
state: 'Home'
- condition: state
entity_id: input_boolean.vacation_switch
state: 'off'
- condition: sun
before: sunrise
before_offset: "-1:00:00"
- condition: sun
after: sunrise
after_offset: "1:00:00"
action:
- service: homeassistant.turn_on
entity_id: group.window_lights
- service: notify.notifications_ios
data:
message: 'Tänder belysning!"
I struggled with this while trying to create an automation condition based on time. I couldn’t figure out how the offsets behaved. I ended up using the solar angle attribute of the sun component.
You can see my condition here. I think ~15 degrees is an hour