Hi all,
so i defined a test.sun entity with azimuth and elevation (spezifically to test my shading code), and call them with state(‘xxx’) and it works
i also defined fixed value entity in cutomize.yamle, pretty much the same way, but it does not work.
and i cant figure out what i did wrong…
here is the sensor that works (out of my templates.yaml)
# Sun simulation
- trigger:
- platform: time_pattern
# This /1 will update every second
seconds: /4
sensor:
# cycle through 1-360 rinse and repeat
- name: "test.sun_azimuth"
unit_of_measurement: "°"
state_class: measurement
state: >
{% set azimuth = states('sensor.test_sun_azimuth') | float(0) %}
{% if azimuth < 355 -%}
{{ (azimuth + 6) }}
{%- else -%}
{{ "0" }}
{%- endif %}
- trigger:
- platform: time_pattern
# This /1 will update every second
seconds: /2
sensor:
# cycle through 1-360 rinse and repeat
- name: "test.sun_elevation"
unit_of_measurement: "°"
state_class: measurement
state: >
{% set e = 6 %} {# enter azimuth increments #}
{% set b = 65 %} {# enter max elevation #}
{% set c = b - 80 %} {# no input here, calculates the lower elevetion#}
{% set d = 80 / 180 * e %} {# no input here, calculates the elevation per aimuth increment#}
{% set x = states('sensor.test_sun_azimuth') | float(0) %}
{% if x < 180 -%}
{{ ((x*d/e)+c) | round(2) }}
{%- else -%}
{{ (((x-(2*(x-180)))*d/e)+c) | round(2) }}
{%- endif %}
this is the value block that does not work: (out of my customize.yaml)
# values for roller shutter automation
cover.eg_kueche: # individual window shading settings
window_direction: 180 # direction the window is facing: default 180 = south
azimuth_limit_low: 45 # lover deviation from window direction from which shading is required: default 45 (positive value, also its negative of the window!)
azimuth_limit_high: 45 # upper deviation from window direction up to wich shading is required: default 45
window_tilt: 0 # deviation from vertical if e.g. roof window (a wall window is 0° deviation)
window_height: 1000 # height of window in mm
window_wall_thickness: 400 # width of wall including inside window sill in mm
window_sun_strake: 100 # acceptable width of sun streaks (AWS) in mm
window_min_elevation_shading_active: "15" # from which elevation onward shading is required
roller_shutter_depth: 50 # depth of the shutter from outside wall
roller_shutter_start_shading: 98 # start shading in % of roller shutter
roller_shutter_full_shading: 5 # fully shaded in % of roller shutter
roller_shutter_catdoor: 5 # shutter max close setting for cat door or to prevent lock out from terrace door
roller_shutter_catdoor_time: # fixed offset time to close the shutter (catch up with the others), if "" then it will never fully close, except by manual operation.
roller_shutter_catdoor_active: "false" # if true, catdoor function is active, if not, normal operation will be executed.
roller_shutter_max: 68 # formula needs to be build. from which elevation shading is no longer required because the wall itself provides shading
window_awning: "false" # awing available for this window (prefer awning is a global setting), if true, roller shutter will not do any shading work.
shading_paused: "false" # can be true, false and time, time reactivates after the time of automation_pause_time
open_on_window_open: "false" # false will prevent automatic window opening during closed roller shutter, true will rise the roller shutter to slotted if window is opened (false will not on manual windows).
and this is out of my sensors.yaml and should call the values.
azimuth and elevation work, all others are just 0.0, i tried every combination i could think off with _ and . for the names.
# roller-shutter EG-Küche
- platform: template
sensors:
cover_eg_kueche_shading_pos_1:
value_template: >-
{% set azimuth = states('sensor.test_sun_azimuth') | float(0) %}
{% set elevation = states('sensor.test_sun_elevation') | float(0) %}
{% set window_direction = states('sensor.cover_eg_kueche.window_direction') | float(0) %}
{% set azimuth_limit_low = states('sensor.cover_eg_kueche.azimuth_limit_low') | float(0) %}
{% set azimuth_limit_high = states('sensor.cover_eg_kueche.azimuth_limit_high') | float(0) %}
{% set window_tilt = states('sensor.cover_eg_kueche.window_tilt') | float(0) %}
{% set window_height = states('sensor.cover_eg_kueche.window_height') | float(0) %}
{% set window_wall_thickness = states('sensor.cover_eg_kueche.window_wall_thickness') | float(0) %}
{% set window_sun_strake = states('sensor.cover_eg_kueche.window_sun_strake') | float(0) %}
{% set window_depth_roller_shutter = states('sensor.cover_eg_kueche.window_depth_roller_shutter') | float(0) %}
{% set roller_shutter_start_shading = states('sensor.cover_eg_kueche.roller_shutter_start_shading') | float(0) %}
{% set roller_shutter_full_shading = states('sensor.cover_eg_kueche.roller_shutter_full_shading') | float(0) %}
{% set roller_shutter_catdoor = states('sensor.cover_eg_kueche.roller_shutter_catdoor') | float(0) %}
{% set roller_shutter_max = states('sensor.cover_eg_kueche.roller_shutter_max') | float(0) %}
{% set window_min_elevaiton_shading_active = states('sensor.cover_eg_kueche_window_min_elevaiton_shading_active') | float(0) %}
{% if (window_direction - azimuth_limit_low) < azimuth < (window_direction + azimuth_limit_high) and elevation < roller_shutter_max %}
{% set shading = "true" %}
{% else %}
{% set shading = "false" %}
{% endif %}
{% if shading == "true" and elevation > window_min_elevaiton_shading_active %}
{{ ((window_height + window_wall_thickness + window_sun_strake)*(tan((elevation - window_tilt) * pi / 180) / window_height * 10) | float(0)) | round(0) }}
{% elif shading != "true" and elevation > window_min_elevaiton_shading_active %}
{{ window_min_elevaiton_shading_active | float(0)}}
{% elif elevation < -6 %}
{{ '0' | float(0) }}
{% elif -6 < elevation < 0 %}
{{ '10' | float(0) }}
{% else %}
{{ '100' | float(0) }}
{% endif %}
this is the result, it basically jumps to 0.0 when ever i print any of the variables i want to pull from customize.yaml
In this code it should not be 0.0 but 15