WIP: brightness sensor without an actual brightness sensor

I know I could just put an ESP together and get accurate brightness values for my place but I want to share my current approach and ask for feedback because it has some drawbacks.

Here is what I’m using to calculate the brightness:

  • the sun’s elevation attribute
  • Dark Sky’s cloud coverage sensor
  • A statistics sensor to get the highest elevation in the past 24h:
- platform: statistics
    name: hist_evelevation
    entity_id: sensor.elevation
    max_age:
      hours: 24 
    sampling_size: 5000

And here is the sensor:

sunlight_pct:
        entity_id:
          - sun.sun
          - sensor.dark_sky_cloud_coverage
        value_template: >-
          {%- set elevation = state_attr('sun.sun','elevation') | float %}
          {%- set cloud_coverage = states('sensor.dark_sky_cloud_coverage') | float %}
          {%- set max_elevation = states.sensor.hist_evelevation.attributes.max_value | float %}
          {%- set adjusted_elevation = [elevation,0] | max %}
          {%- set adjusted_elevation = adjusted_elevation / max_elevation %}
          {%- set brightness = adjusted_elevation * ((0.5*sqrt(adjusted_elevation)+1)-cloud_coverage/100) %}
          {%- set brightness = ([brightness*100,99.9]|min) %}
          {{ (brightness) | round(1) }}
        unit_of_measurement: '%'

It is calculating the relative sun elevation (if the sun is below the horizon, the value is 0). Now the interesting part the brightness: it is the product of the sun’s relative elevation times some adjusted cloud coverage. With the last part I’m using a sqrt function to penalize the time of the day. When the relative elevation is 0 the value the function returns is 1 (so the case rel. elevation is 0 and cloud coverage is 1 will result in a brightness of 0%). On the other hand when the sun is at its highest point the sqrt function returns 1.5 so the sensor won’t ever reach 0% during bright daylight.

The problem I see is that the sensor isn’t taking seasons into account. Any idea how to take care of this as well? My guess is that I need to include the absolute elevation but how?