-
Hello!
- platform: template
sensors:
sunlight_pct:
friendly_name: "Sončna osvetlitev"
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 )) %}
{%- 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 }}
unit_of_measurement: '%'
device_class: 'illuminance'
#
sunlight_opacity:
friendly_name: "Sončna prosojnost"
value_template: >-
{%- set sunpct = states('sensor.sunlight_pct') | float %}
{%- set opacity = sunpct / 100 | float %}
{{ opacity }}
Is there any solution to make the sunny day image "darken" according to the sensor? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
You could perhaps change the opacity of the image and have a black background behind it? |
Beta Was this translation helpful? Give feedback.
-
with sweethome you can take captures at different times of the day which will change the brightness, and then create a binary.sensor with "I tried some time ago" for the times of the day (morning, noon, evening, night) .
|
Beta Was this translation helpful? Give feedback.
-
I found some sort of instant solution!If this works it will be great because I won't need the following anymore:A sensor that determines what part of the day it is: - platform: template
sensors:
del_dneva:
friendly_name: "Del dneva"
value_template: >
{% set current_hour = strptime(states('sensor.time'), "%H:%M").hour %}
{% set sun_state = states('sun.sun') %}
{% if sun_state == "below_horizon" and current_hour < 22 %}
Noč
{% elif sun_state == "above_horizon" and current_hour < 6 %}
Jutro
{% elif '09:00' <= states('sensor.time') <= '11:45' %}
Dopoldan
{% elif '11:45' <= states('sensor.time') <= '12:15' %}
Poldne
{% elif '12:15' <= states('sensor.time') <= '19:00' %}
Popoldan
{% elif sun_state == "below_horizon" and current_hour < 16 %}
Večer
{% endif %} Setting in the floorplan card: rules:
- element: del_dneva
entity: sensor.del_dneva
tap_action: false
hover_action: false
state_action:
action: call-service
service: floorplan.image_set
service_data: |
>
var imageName = '';
switch (entity.state) {
case 'Jutro': imageName ='jutro'; break;
case 'Dopoldan': imageName = 'dopoldan'; break;
case 'Poldne': imageName = 'poldne'; break;
case 'Popoldan': imageName = 'popoldan'; break;
case 'Večer': imageName = 'vecer'; break;
case 'Noč': imageName = 'noc'; break;
}
return '/local/img/fp/' + imageName + '.png'; New sensor configuration that I will have to adjust (for now it works): - platform: template
sensors:
sunlight_pct:
friendly_name: "Sončna osvetlitev"
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 )) %}
{%- 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 }}
unit_of_measurement: '%'
device_class: 'illuminance'
#
sunlight_opacity:
friendly_name: "Sončna prosojnost"
value_template: >-
{%- set sunpct = states('sensor.sunlight_pct') | float %}
{%- set opacity = sunpct / 100 | float %}
{{ opacity }}
#
visina_sonca:
friendly_name: "Višina sonca"
value_template: >-
{% if state_attr('sun.sun','elevation') > 20 %}
svetlo
{% elif state_attr('sun.sun','elevation') > 9 %}
vmesno
{% elif state_attr('sun.sun','elevation') > -3 %}
temno
{% else %}
črno
{% endif %} New configuration in floorplan card: - 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.3'; break;
case '0.01': opacity ='0.3'; break;
case '0.02': opacity ='0.3'; break;
case '0.03': opacity ='0.3'; break;
case '0.04': opacity ='0.4'; break;
case '0.05': opacity ='0.5'; break;
case '0.06': opacity ='0.6'; break;
case '0.07': opacity ='0.7'; break;
case '0.08': opacity ='0.8'; break;
case '0.09': opacity ='0.9'; break;
case '0.10': opacity ='1'; break;
}
return `opacity: ${opacity};`; Now I'm just using one main image for the background and if everything works (I doubt it will immediately) the image should now be affected by the current clarity/cloudiness in my location so I no longer have the image colored by the midday sun when it's outside due to cloud cover almost dark! Current display of the night: I'm currently using this image: |
Beta Was this translation helpful? Give feedback.
I found some sort of instant solution!
If this works it will be great because I won't need the following anymore:
A sensor that determines what part of the day it is: