I saw your full solution here.
Maybe you can define an array of jsons and have all your mappings in one place.
Not sure if you can share it between template sensors, you would need to try.
{% set dir = [
{"abr": "N" , "friendly" : "North"} ,
{"abr": "NbE", "friendly" : "North by East"},
{"abr": "NNE", "friendly" : "North North East"},
{"abr": "NEbN", "friendly" : "North East by North"},
...
{"abr": "N" , "friendly" : "North"}
] %}
{% set degrees = 7 %}
{% set d = (degrees/11.25)|round %}
Abbreviation = {{dir[d].abr}}
Friendly = {{dir[d].friendly}}
Picture = {{dir[d].abr|lower}}.png
returns
Abbreviation = NbE
Friendly = North by East
Picture = nbe.png
this would require you to rename the pictures, or you add another pair in the array to link to the picture name
wind_compass_abbreviation:
friendly_name: Windrichting Afkorting
value_template: >
{% set degrees = states('sensor.br_wind_direction_azimuth')|float %}
{% set abbr = ['N','NNNO','NNO','ONNO','NO','NONO','ONO','OONO','O','OOZO','OZO','ZOZO','ZO',
'OZZO','ZZO','ZZZO','Z','ZZZW','ZZW','ZZW','ZW','ZWZW','WZW','WWZW','W','WWNW',
'WNW','NWNW','NW','WNNW','NNW','NNNW' ] %}
{%- set i = ((degrees / 11.25) | round(0)) | int %}
{%- set i = 0 if i == 32 else i %}
{{ abbr[i] }}
wind_compass_direction:
friendly_name: Windrichting
value_template: >
{% set degrees = states('sensor.br_wind_direction_azimuth')|float %}
{% set direction = ['Noord','Noord Ten Oosten','Noordnoordoost','Noordoost Ten Noorden','Noordoost',
'Noordoost Ten Oosten','Oostnoordoost','Oost Ten Noorden','Oost',
'Oost Ten Zuiden','Oostzuidoost','Zuidoost Ten Oosten','Zuidoost',
'Zuidoost Ten Zuiden','Zuidzuidoost','Zuid Ten Oosten','Zuid',
'Zuid Ten Westen','Zuidzuidwest','Zuidwest Ten Zuiden','Zuidwest',
'Zuidwest Ten Westen','Westzuidwest','West Ten Zuiden','West',
'West Ten Noorden','Westnoordwest','Noordwest Ten Westen','Noordwest',
'Noordwest Ten Noorden','Noordnoordwest','Noord Ten Westen'] %}
{%- set i = ((degrees / 11.25) | round(0)) | int %}
{%- set i = 0 if i == 32 else i %}
{{ direction[i] }}
have a look at the post above for 2 separate sensors with comparable lists. Is already really very nice.
Combining those into 1 is the next challenge…
thanks for the suggestion , and please don’t hold back ;
meanwhile, here’s a sensor with all info in 1:
wind_compass_direction:
friendly_name_template: >
{% set degrees = states('sensor.br_wind_direction_azimuth')|float %}
{% set abbr = states('sensor.wind_compass_abbreviation') %}
{{abbr}} : {{degrees}} °
value_template: >
{% set degrees = states('sensor.br_wind_direction_azimuth')|float %}
{% set direction = ['Noord','Noord Ten Oosten','Noordnoordoost','Noordoost Ten Noorden','Noordoost',
'Noordoost Ten Oosten','Oostnoordoost','Oost Ten Noorden',
'Oost','Oost Ten Zuiden','Oostzuidoost','Zuidoost Ten Oosten','Zuidoost',
'Zuidoost Ten Zuiden','Zuidzuidoost','Zuid Ten Oosten',
'Zuid','Zuid Ten Westen','Zuidzuidwest','Zuidwest Ten Zuiden','Zuidwest',
'Zuidwest Ten Westen','Westzuidwest','West Ten Zuiden',
'West','West Ten Noorden','Westnoordwest','Noordwest Ten Westen','Noordwest',
'Noordwest Ten Noorden','Noordnoordwest','Noord Ten Westen'] %}
{%- set i = ((degrees / 11.25) | round(0)) | int %}
{%- set i = 0 if i == 32 else i %}
{{ direction[i] }}
entity_picture_template: >
{%- set degrees = states('sensor.br_wind_direction_azimuth')|float %}
{%- set path = '/local/weather/wind_compass/' %}
{%- set ext = '.png' %}
{%- set num = ((degrees // 11.25) * 11.25 // 1) | int %}
{%- set num = 0 if num == 360 else num %}
{{ "{}{}{}".format(path,num,ext) }}
Can someone post how they setup the template? I tried but each time the Check Configuration it says something about format error in code. Now is this to be used under Sensor on the config or something else? I love the idea in using this but can’t seem to get the coding right. I see where some shorten it but I don’t think that works with the Yr.no sensor.
{%- set degrees = states('sensor.winddirection')|float %}
{%- set path = '/local/weather/wind_compass/' %}
{%- set ext = '.png' %}
{%- set num = ((degrees // 11.25) * 11.25 // 1) | int %}
{%- set num = 0 if num == 360 else num %}
{{ "{}{}{}".format(path,num,ext) }}
and
wind_compass_abbreviation:
friendly_name: Windrichting Afkorting
value_template: >
{% set degrees = states('sensor.winddirection')|float %}
{% set abbr = ['N','NNNO','NNO','ONNO','NO','NONO','ONO','OONO',
'O','OOZO','OZO','ZOZO','ZO','OZZO','ZZO','ZZZO',
'Z','ZZZW','ZZW','ZZW','ZW','ZWZW','WZW','WWZW',
'W','WWNW','WNW','NWNW','NW','WNNW','NNW','NNNW' ] %}
{%- set i = ((degrees / 11.25) | round(0)) | int %}
{%- set i = 0 if i == 32 else i %}
{{ abbr[i] }}