Trying to get my garage lights that are connected to the “Garage Switch” to go on any time the Garage Door is in the “on” / door up position from 15 minutes before sunset to darkness, say midnight.
My Automation for this is below. Every other automation works great, just this one I’m having issues with. Any help is appreciated!
- id: '1589151804789'
alias: Garage Lights After Dark
description: ''
trigger:
- entity_id: binary_sensor.vision_security_zg8101_garage_door_detector_sensor
from: 'off'
platform: state
to: 'on'
condition:
- after: sunset
before: sunset
before_offset: -0:15
condition: sun
action:
- device_id: bcd5830564b84a25814151cef5d83a29
domain: switch
entity_id: switch.garage
type: turn_on
To turn the lights on if the door is open during your time range you need to use both the door and sun as triggers and as conditions.
Also that offset does not look right and it cant be both before and after sunset at the same time.
Try this:
- id: '1589151804789'
alias: Garage Lights On After Dark
description: ''
trigger:
- platform: state
entity_id: binary_sensor.vision_security_zg8101_garage_door_detector_sensor
from: 'off'
to: 'on'
- platform: sun
event: sunset
offset: '-00:15:00'
condition:
- condition: state
entity_id: binary_sensor.vision_security_zg8101_garage_door_detector_sensor
state: 'on'
- condition: sun
after: sunset
after_offset: '-00:15:00'
action:
- service: switch.turn_on
entity_id: switch.garage
So if it’s triggered by the door opening it has to be at least 15 minutes before sunset for the light to turn on. If it’s triggered by being 15 minutes before sunset the door has to be already open.
You need another automation to turn off the light.
- id: 'whatever'
alias: Garage Lights Off
description: ''
trigger:
- platform: state
entity_id: binary_sensor.vision_security_zg8101_garage_door_detector_sensor
from: 'on'
to: 'off'
- platform: time
at: '00:00:00'
action:
- service: switch.turn_off
entity_id: switch.garage
Note this will turn the light off at midnight whether the door is open or not. You might want to be notified of that case. Something like “it’s midnight and the garage door is still open”. Also if you want a delay in switching off the lights when the door is closed to allow you to not be fubling in the dark you could put a for: [some tine] option on the door state trigger.
I will give that code a try and see if it corrects it.
I already have a door close automation that turns the lights off when the door closes, so that part works well, it was just this part I was having issues with.
I’ll paste in your code and see how it works. Really appreciate your help, and the explanation!