I had been using this flawlessly for a while and then had to rebuild my HA instance. I copied all of the files to my computer via WinSCP and put them all back in the correct locations once it was rebuilt. Since then it has not worked at all. I can manually trigger the automations from the frontend but the automation does not work.
@daenny This script is awesome thank you! I’d like to ask advice on how to organise it in my configuration. Is it possible to wrap this whole “Timer Light” group with the input_sliders, sensors & automations in one file?
Whats the general advice to keep my config tidy while adding this new group?
Can someone post your working code? I still cant figure out why mine is not working (automations not triggering). I’d like to see where I may have gone wrong. Thanks for the help.
@djkmod83 I have a slightly modified version of the original script.
You can set the on and off time offsets related to sunset and sunrise (the original was using duration for the off time)
If the HASS misses the sunrise or sunset event (for example it was off or being rebooted), it will be triggered if its inside the right timeframe. Example: You set the lights to turn on at sunset -10min. Lets say the HASS was off at that time, and you turn it back on at sunset + 120min. It will trigger the on event for the lights.
The off automation does not trigger if the lights are already off. Same thing with the on automation.
As @anon43302295 suggested, I’ve packed everything into one single package file
There’s a lot of room for improvement, so im open to suggestions!
You may want to add entity_id’s to your sensors to specify when they should update. sun.sun and the input_slider.XXXX would do it. If you don’t specify they will update on EVERY STATE change which can become significant.
On a rPI with a lot of sensors it can become a noticeable CPU load; and being specific with the entity_id’s helps cut that down significantly.
I use lux meters for controlling lights, but while reading this thread It hit me that sun elevation might be more useful to use as trigger than time after/before sunset/dawn?
Especially up here north, there will be huge differences of darkness 10 minutes after sunset in summer compared to winter.
This is what prompted me to recently switch to sun angle for automating lights. I also combine that with cloud cover. It’s not super-elegant, but it’s been working so far. In my setup, I handle it as a sensor, then base automations on whether that sensor is true or false. Still dialing in the best numbers, but it’s been good so far. It was interesting yesterday when it suddenly got dark out b/c of a passing storm and the lights came on automatically. Then they turned back off after the storm’d passed.
turn_on_indoor_lights:
friendly_name: 'Turn On Indoor Lights'
value_template: >
{% if (states.sun.sun.attributes.elevation | int < 30) %}true
{% elif ( (states.sun.sun.attributes.elevation | int < 40) and (states.sensor.dark_sky_cloud_coverage.state | int > 50)) %}true
{% elif (states.sensor.dark_sky_cloud_coverage.state | int > 90) %}true
{% else %}false
{% endif %}
@jwelter Thanks ill have a look and improve it! Today it failed to turn on the lights, maybe theres a mistake in the “ON” code, since the “OFF” part worked successfully this morning.
BTW, do you know easy ways to debug sensors, triggers and automations?
For example how could i simulate a sunrise to test my automation?
@caspercba I’m using your version of the script but i had to change part of it because it was using UTC time.
I’ve changed (now().strftime("%s") | int | timestamp_custom("%H:%M")) into as_timestamp (now()) | timestamp_custom("%H:%M"). this two scripts have a difference of one hour (at least here in Portugal).
The script runs fine except for one thing. The lights turn off but they don’t turn on! Let me explain:
my lights are configured to turn on 20 minutes before sunset (at 20:07 - sunset is at 20:27 - today) and 20 minutes after sunrise (at 07:14 - sunrise is at 6:54).
If i analize the conditions at 21:00 (when the lights should be on, but thay aren’t…) the first contition returns TRUE, the second return FALSE and the third returns TRUE. Shouldn’t all the conditions return TRUE because 21:00 > 20:07 and 21:00 < 7:14?? Or the system gets mixed up because 7:14 is on the next day?? In fact 21:00 is bigger than 7:14…
Should the script get the date too? Something like {{ as_timestamp (now()) | timestamp_custom("%d/%b/%Y %T") > states.sensor.auto_light_start.state }}
Thanks in advance for your answer. I really need it…
Check out how I handled it: Automatic Dimming Light Timer . In my latest code I convert all time used for calculations into seconds since the last midnight. I found that this is one of the best ways for me to handle time in home assistant.
the sliders are working now, i made mistake and forgot one change.
now the lamp keeps goiing on after few minutes, maybe another error from me…
I try this code now. it looks great! but when i move the sliders the start and and time doesnt change? I changed input_slider for input_number because it gaves problems. maybe thats why its not working?
I think you might like this : Universal Persistent Timer
It can add a timer to anything including multiple scripts, lights etc. with separate start and stop actions, and will resume in the event of downtime and requires no programming skills once installed. All lights, switches etc can be accessed from auto populated lists; and you can specify days of the week, repetitions, intervals, and much more. Timers can be paused, backed up and give activation notifications etc. https://youtu.be/rUeTIU1uAP0
Hi Everyone,
I’m hoping for a gentle nudge in the right direction, I’ve loaded and updated the timer light package into the latest version of Hassio, and my sunset timer is working, sort of. At the moment, it is meant to trigger at 1734 and turn of at 2134. The problem I am having is that Hassio is ignoring the first number of the time, and is turning on my light at 0734 and off again at 1134. If anyone could tell me where the error is, that would be fantastic.
Thanks,
Mat
Hi all, I know this is an old post but wondered if anyone actually got this package working? Looking for adjustable times to turn on and off garden lights after sunset. any pointers would help… Thanks