Hello.
I had a problem when I made the image change depending on the time of day.
**I didn’t like the realistic display of the brightness of the image, **
**for example at noon (the image shows full brightness), **
when the external situation was completely different (cloudy).
Example image at noon:
A more realistic display:
First I tried the code:
- platform: template
sensors:
cloud_coverage:
friendly_name: "Cloud coverage"
value_template: >-
{% set elevation = state_attr('sun.sun','elevation') | float %}
{% set cloud_coverage = states('sensor.astroweather_cloud_cover') | float %}
{% set cloud_factor = (1 - (0.75 * ( cloud_coverage / 100) ** 3 )) %}
{{ cloud_factor | round(2) }}
unit_of_measurement: '%'
device_class: 'illuminance'
Since I don’t have a local external Illuminance sensor (lx) yet, I used sensor.astroweather_cloud_cover, which does not show the real situation where I live (distance from the capital Ljubljana, which is the only one I can choose from the list).
So I made another sensor:
sun_brightness:
friendly_name: "Sun brightness"
value_template: >-
{% set min_bright_percent = 50 %}
{% set max_bright_percent = 100 %}
{% set mins_span = 30 %}
{% set sr = today_at((state_attr('sun.sun', 'next_rising') | as_datetime | as_local).strftime('%H:%M')) %}
{% set pre_sunrise = sr - timedelta(minutes=mins_span ) %}
{% set post_sunrise = sr + timedelta(minutes=mins_span ) %}
{% set ss = today_at((state_attr('sun.sun', 'next_setting') | as_datetime | as_local).strftime('%H:%M')) %}
{% set pre_sunset = ss - timedelta(minutes=mins_span ) %}
{% set post_sunset = ss + timedelta(minutes=mins_span ) %}
{% set t = now() %}
{{ { pre_sunrise <= t < post_sunrise: max_bright_percent - min_bright_percent + ((t - pre_sunrise).seconds * (max_bright_percent - min_bright_percent )/3600)|int(0),
post_sunrise <= t < pre_sunset: max_bright_percent,
pre_sunset <= t < post_sunset: max_bright_percent - ((t - pre_sunset).seconds * (max_bright_percent - min_bright_percent )/3600)|int(0)
}.get(true, min_bright_percent) }}
unit_of_measurement: '%'
device_class: 'illuminance'
To get the position of the sun and Sun brightness
After that I also looked at the UV sensor:
I have an internal sensor with a built-in meter (lx):
At the same time I also watched:
Now the outside looks somewhat comparable to this:
I have a desire and would like to ask if someone is willing to write me a code that would calculate the transparency from the given parameters, which I would then use in the floor plan for the layer.
- element: background
entity: sensor.sunlight_opacity
tap_action: false
hover_action: false
state_action:
action: call-service
service: floorplan.style_set
service_data: |
>
var opacity = '';
switch (entity.state) {
case '0.0': opacity ='0.1'; break;
case '0.1': opacity ='0.1'; break;
case '0.2': opacity ='0.2'; break;
case '0.3': opacity ='0.3'; break;
case '0.4': opacity ='0.4'; break;
case '0.5': opacity ='0.5'; break;
case '0.6': opacity ='0.6'; break;
case '0.7': opacity ='0.7'; break;
case '0.8': opacity ='0.8'; break;
case '0.9': opacity ='0.9'; break;
case '1.00': opacity ='1'; break;
}
return `opacity: ${opacity};`;
Thank you.