How? Like I see you’re specifically looking for when the sun’s elevation is -7 to decide between night and dusk/dawn. How did you come up with that particular number for your region?
I also just do sunset -30 min. I just figured it was good enough. But this topic has piqued my interest, I have noticed it was turning on when it was still bright out before. And I’m always on the lookout for ways to optimize my automations
EDIT: Duh, click the link Mike . Sounds like 6 degrees is the official differentiator but some trial and error will figure out what works best for your region, might be a bit higher or lower. Thanks!
Here is another I found awhile back when I want to turn on my living room lights at sunset but also depends on the cloud coverage outside. The sample uses Darksky which is now a paid subscription. Weatherbit is free.
I just have an event on sunset or sunrise and I add an offset for what I feel is comfortable for my area. In my case I like the lights on 30min BEFORE sunset.
alias: 'Lights: turn on outdoor lights when the sun sets'
trigger:
- event: sunset
offset: '-00:30:00'
platform: sun
condition: []
action:
- device_id: xxxxx
domain: switch
entity_id: switch.switch_3
type: turn_on
- device_id: xxxxx
domain: switch
entity_id: switch.switch_2
type: turn_on
initial_state: 'on'
mode: single
Deploy a light sensor outside. Outdoor light during twilight time varies much more than I realized until comparing Lux readings against astronomical calculations (e.g. civil twilight). This is especially true if you’re in northern latitudes (I’m close to 48 degs N).
I use an XBee3 ZigBee module (which can do I2C) and a TSL2591 light sensor (it’s part of my weather station). Use a moving average of Lux readings to smooth variations and outliers as last light approaches.
Exactly this was gonna be my suggestion. I originally did this with sunset ending up in the same problem where it would need changing. Then I tried using info from weather but was also not as accurate. The best solution I ended up with was a lux sensor. It is way more close to what is actually happening outside.
The offset of the sun is based on geographic location and the time of year. It should be accurate regardless of time of year and latitude that is the entire point as long as your “Home” is set correctly.
I am at 49 degrees N, and have been fine year round with 30min before sunset for a few years now even with our dark short overcast days in winter and long summer days.
I am curious how “spot on” you are trying to be I find that 30 min window somewhat covers any variance however I am trying to have the lights on BEFORE it gets dark.
I even use it with my Christmas lights and have them come on in the morning but ONLY if it is dark during the normal hours people get up for work.
I posted work I did developing a simple model in this thread:
I am still working on it, I need to get data now that the snow is gone, and in 2 days when it is raining to adapt the final formulas, then in the summer sort out my surface reflectivity value
I got it working exceptionally well during winter as long as it was not actively snowing, but I figure the adjusted compensation due to rain will be sufficient.