Calculate room illuminance with empirical model

Yesterday I was dreaming of a way to calculate the illuminance il LUX using a theoretical model. In facts, I just need a way to turn on lights on given scenarios and installing sensors for it seems a bit overkill to me.

On the other hands, I think that more or less all the variables to calculate the illuminance of the room could be (approximately) available to me already. Thus I’m here to share my thoughs with you to derive a better formula.

The starting point is my “sunlight at home” sensor, derived from sun elevation and cloud coverage. As a rule of thumbs, it seems to work quite well

{% set elevation = state_attr('sun.sun','elevation') | float %}
{% set cloud_coverage = state_attr('weather.forecast_casa', 'cloud_coverage') | float %}
{% set cloud_factor = (1 - (0.75 * ( cloud_coverage / 100) ** 3 )) %}
{% set min_elevation = -6 %}
{% set max_elevation = 90 %}
{% set adjusted_elevation = elevation - min_elevation %}
{% set adjusted_elevation = [adjusted_elevation,0] | max %}
{% set adjusted_elevation = [adjusted_elevation,max_elevation - min_elevation] | min %}
{% set adjusted_elevation = adjusted_elevation / (max_elevation - min_elevation) %}
{% set adjusted_elevation = adjusted_elevation %}
{% set adjusted_elevation = adjusted_elevation * 100 %}
{% set brightness = adjusted_elevation * cloud_factor %}
{{ brightness | round }}

The I calculated the same but expressed in LUX. Here we have the first empirical parameters of the model.

As a maximum LUX of the sun I set 10752 lx. I finally added a couple of empirical dropping fctors that takes in count the seasonality and latitude/longitude.

{% set sunlight_pct = states('sensor.sunlight_at_home') | float(0) %}

{% set latitude = state_attr('zone.home', 'latitude') %}
{% set longitude = state_attr('zone.home', 'longitude') %}

{% set month = now().month %}

{% if latitude > 40 and latitude < 50 %}
{% if month in [12, 1, 2] %}
{% set seasonal_factor = 0.8 %}
{% elif month in [6, 7, 8] %}
{% set seasonal_factor = 1.2 %}
{% else %}
{% set seasonal_factor = 1.0 %}
{% endif %}
{% else %}
{% set seasonal_factor = 1.0 %}
{% endif %}

{% set max_lux = 32000 %}
{% set lux = (sunlight_pct / 100) * max_lux * seasonal_factor %}
{{ lux | round(0) }}

Finally, I calculate the empirical LUX in the room as a set of dropping factors happening inside the room (pls see the comments in the code):

{% set L_ext = states('sensor.theoretical_sunlight_at_home_lux') | float(0) %}
{# Glass transmittance (took from the technical sheet) #}
{% set T = 0.75 %}
{# Mosquito net drop #}
{% set Z_f = 0.1 %} 
{# A_f = Glass surface (mq)/Room area (mq)  #}
{% set A_f = 0.15 %} 
{# S_o = shadowing effect due to near building (factors: my apt' story and orientation, next building total stories, distance between the building #}
{% set S_o = 0.5 %}
{# Reflectance of internal walls and furniture #}
{% set R = 0.75 %}
{# Internal LUX #}
{% set L_int = L_ext * T * (1 - Z_f) * A_f * S_o * R %}
{{ L_int | round(0) }}

I was wondering if the formula looks good for you and how to better aestimate the parameters I empirically chose (expecially S_o). What do you think about it?