In lazy pseudo-code, I’m reading your first automation as:
When (trigger) the light sensor turns on, OR it is exactly 15 min before sunset, then (conditions), if the light is on AND it is exactly 15 min before sunset, then (actions) turn on the garage light.
I’m guessing you want to say:
When I open the door (trigger), then, if it is between 15 min before sunset AND sunrise the next day (conditions), then (actions) turn on the light.
Also, there are some important pointers in the docs that would help you:
Unlike a trigger, which is always or , conditions are and by default - all conditions have to be true.
Note that if only before key is used, the condition will be truefrom midnight until sunrise/sunset. If only after key is used, the condition will be true from sunset/sunrise until midnight . Therefore, to cover time between sunset and sunrise one need to use after: sunset and before: sunrise as 2 separate conditions and combine them using or .
I believe the following single automation meets your requirements. It is triggered by the binary_sensor and will turn your garage light on/off when the garage door opens/closes but only between sunset (-15 minutes) and sunrise.
- id: '1592264830396'
alias: HGD Open-Close
trigger:
- platform: state
entity_id: binary_sensor.lumi_lumi_sensor_magnet_aq2_9ef73602_on_off
condition:
condition: or
conditions:
- condition: sun
after: sunset
after_offset: '-00:15:00'
- condition: sun
before: sunrise
action:
- service_template: 'switch.turn_{{trigger.to_state.state}}'
entity_id: switch.garage
Note that if only before key is used, the condition will be truefrom midnight until sunrise/sunset. If only after key is used, the condition will be true from sunset/sunrise until midnight . Therefore, to cover time between sunset and sunrise one need to use after: sunset and before: sunrise as 2 separate conditions and combine them using or .
Sorry, I misread something in your original post. I thought that sensor was a light sensor and not a magnetic sensor, so I was confused, because I didn’t see where you control your door. That’s why I posted the textual description to hear if I’m understanding correctly. I think 123 has given a good answer.