I think making a template sensor in HA would do most of it, then an automation to catch the transition, which turns a helper on or off.
The parts in parenthesis would be the template sensor, the automation would use the value as a trigger, plus another “failsafe” trigger if the weather entity becomes unavailable, 15 degrees would catch it well and be equivalent to 100% cloud cover in the template.
Since negative elevation is darker, we can subtract cloud coverage from it and compare it to our expected value
{%- set clouds = (states.sensor.weatherbit_cloud_coverage.state) | int %}
{{ states.sun.sun.attributes.elevation - (clouds / 10) | int }}
During sunrise, when this value passes from under 5 to 5 or over as an automation trigger, it turns off the “dark” helper value
During sunset, when this value passes from over 5 to 5 or under as an automation trigger, it turns on the “dark” helper value
Since the helper stage change can only occur after solar noon or midnight, the automations will never interfere with eachother or blink the state. The helper state change can now be used as the trigger for actual lighting controls.
I just finished adding this automation to see what happens, there should be cloud coverage this morning where I am during sunrise.
This is my template sensor code that is giving good numbers
- platform: template
sensors:
sun_cloud_elevation:
friendly_name: Sun Elevation Cloud Adjusted
value_template: "{{ states.sun.sun.attributes.elevation - ((states.sensor.weatherbit_cloud_coverage.state) | int / 10) | int }}"
The template sensor can be further modified to take weather conditions such as rain or low visibility (like fog) into account, while still keeping it simple. There is a much more complex algorithm which takes an hours worth of cloud coverage data into account, but that would be more useful for a full day solar output automation rather than just sun rise/set.