I have an automation taken from the example here on the site, which triggers my lights based on a movement senor, which works great. See below.
I would also like to make sure the light is only triggered when there is movement and it’s dark. So I thought I could use the ‘Sun’ option, but I’m unclear as to whether it should be a trigger or a condition? I would appreciate some help, thanks.
alias: Turn on hall lights when there is movement
trigger:
platform: state
entity_id: binary_sensor.motion_sensor_3_1
to: ‘on’
action:
service: homeassistant.turn_on
entity_id: script.timed_lamp
script:
timed_lamp:
alias: “Turn on lamp and set timer”
sequence:
# Cancel ev. old timers
- service: script.turn_off
data:
entity_id: script.timer_off
- service: light.turn_on
data:
entity_id: light.hall
# Set new timer
- service: script.turn_on
data:
entity_id: script.timer_off
timer_off:
alias: “Turn off lamp after 5 minutes”
sequence:
- delay:
minutes: 5
- service: light.turn_off
data:
entity_id: light.hall
Thanks, so where should I put the condition in the script or in the first part of the automation? so this condition will work?
condition: sun
after: sunset
- alias: Turn on hall lights when there is movement
trigger:
platform: state
entity_id: binary_sensor.motion_sensor_3_1
to: 'on'
action:
service: homeassistant.turn_on
entity_id: script.timed_lamp
script:
timed_lamp:
alias: "Turn on lamp and set timer"
sequence:
# Cancel ev. old timers
- service: script.turn_off
data:
entity_id: script.timer_off
- service: light.turn_on
data:
entity_id: light.hall
# Set new timer
- service: script.turn_on
data:
entity_id: script.timer_off
timer_off:
alias: "Turn off lamp after 5 minutes"
sequence:
- delay:
minutes: 5
- service: light.turn_off
data:
entity_id: light.hall
Great thanks, sorry for my ignorance, but I assume you mean this part of your automation? but how do you work out the elevation? I already know the elevation of my home, which is 63, so do I just change to below:63 ??
It is the sun elevation,
Go to your_ip:8123/dev-state and search for sun.
Then you can see the current elevation of the sun. If you watch the value when it gets dark, you get a good indication of a starting value. Then you can adjust it later.
I see, These are my readings right now, but the sun set around two hours ago, so your saying I will need to check around sunset tomorrow for the elevation then and use that number in my condition?