Sensor Wind compass - up for grabs

try:

          {%- 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] }}
2 Likes

Awesome! It works really well!

Thanks

Thanks a lot .
I have a netatmo wheather station.
I made the following code

  - platform: template
    sensors:
      wind_angle:
        friendly_name: "Wind angle"
        unit_of_measurement: 'degrees'
        value_template: "{{ states('sensor.netatmo_netatmo_sceaux_anemometre_balcon_angle') | regex_findall_index('([0-9]+)',index=0,ignorecase=TRUE)  }}"
  - platform: template
    sensors:
        wind_compass:
#           friendly_name: Windrichting
#           icon_template: mdi:compass
           value_template: >
             {{ states('sensor.wind_angle') }}
           friendly_name_template: >
             {% set degrees = states('sensor.wind_angle')|float %}
             {% set abbr = ['N','NNNE','NNE','ENNE','NE','NENE','ENE','EENE','E','EESE','ESE','SESE','SE',
                     'ESSE','SSE','SSSE','S','SSSW','SSW','WSSW','SW','SWSW','WSW','WWSW','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] }}
           unit_of_measurement: '°'
           entity_picture_template: >
                {% set degrees = states('sensor.wind_angle')|float %}
                {% set path = '/local/WindCompass/' %}
                {% set ext = '.png' %}
                {{path-}}
                {%- if 354.38 <= degrees or degrees <= 5.62 -%} 0
                {%- else -%}
                {{ ( ((degrees/11.25)|round )*11.25 )| round}}
                {%- endif -%}
                {{-ext-}}


I 've used the above “png” files.
NB : the files have to be put at home_assistant/www/foobar path. It is seen as /local/foobar.

@jugla Maybe also add some attributes to your compass:

        entity_picture_template: >-
                {% set degrees = states('sensor.wind_angle')|float %}
                {% set path = '/local/WindCompass/' %}
                {% set ext = '.png' %}
                {{path-}}
                {%- if 354.38 <= degrees or degrees <= 5.62 -%} 0
                {%- else -%}
                {{ ( ((degrees/11.25)|round )*11.25 )| round}}
                {%- endif -%}
                {{-ext-}}
        attribute_templates:
          speed: "{{states('sensor.weather_wind_speed')}} {{state_attr('sensor.weather_wind_speed', 'unit_of_measurement')}}" 
          speed_txt: >-
           {% set speed = states('sensor.weather_wind_speed')|float %}
           {% if 0 <= speed <= 0.2 %} Stille
           {% elif speed <= 1.5 %} Flau vind
           {% elif speed <= 3.3 %} Svak vind
           {% elif speed <= 5.4 %} Lett bris
           {% elif speed <= 7.9 %} Laber bris
           {% elif speed <= 10.7 %} Frisk bris
           {% elif speed <= 13.8 %} Liten kuling
           {% elif speed <= 17.1 %} Stiv kuling
           {% elif speed <= 20.7 %} Sterk kuling
           {% elif speed <= 24.4 %} Liten storm
           {% elif speed <= 28.4 %} Full storm
           {% elif speed <= 32.6 %} Sterk storm
           {% elif speed > 32.7 %} Orkan
           {% endif %}

Thanks a lot, I will try.
Just a remark with the “round formula”

 ((degrees/11.25)|round )*11.25 )| round}

You must link(or copy) some xxx.png.
112 --> 113
123 --> 124
157 --> 158
168 --> 169
202 --> 203
213 --> 214
22 --> 23
247 --> 248
258 --> 259
292 --> 293
303 --> 304
337 --> 338
348 --> 349
33 --> 34
And to simplify the code, you can link 0 with 360.

1 Like

Just wanted to add that I made a little Python script that generates wind direction icons that also incorporate some indication of the wind speed in whatever style you want (feel free to make them fancier) and I made a relatively simple template as well:

My template is relatively simple and uses rounding like this:

sensor:
  - platform: template
    sensors:
      wind_compass:
          friendly_name: "Wind bearing"
          value_template: >
              {{ state_attr("weather.ksea_hourly", "wind_bearing") }}
          unit_of_measurement: "°"
          entity_picture_template: >
              {% set path = '/local/wind/' %}
              {% set ext = '.png' %}
              {{path-}}
              {{((state_attr("weather.ksea_hourly", "wind_bearing") * 16 / 360)|round(0) *360/16) | int-}}_
              {%- if state_attr("weather.ksea_hourly","wind_speed") <= 8 -%}L
              {%- elif state_attr("weather.ksea_hourly","wind_speed") <= 15 -%}M
              {%- else -%}H
              {%-endif-%}
              {{-ext-}}

Not too beautiful yet, but works!

badge

3 Likes

Hi, I created a Lovelace Card that accepts an entity and displays a css build compass. No images required! Might be of use to some of you.

2 Likes

Hi I have configured windcompass as per your advice and everything works fine but when the wind direction is O ° the image does not work correctly in the North direction

####################################################
#            WIND COMPASS                          #
####################################################
- platform: template
  sensors: 
    wind_compass_abbreviation:
#      icon_template: mdi:compass
      value_template: >-
        {% if 354.38 <= states('sensor.openweathermap_wind_bearing')|float <= 5.62 %}
           N
        {% elif 5.63 <= states('sensor.openweathermap_wind_bearing')|float <= 16.87 %}
           NbE
        {% elif 16.88 <= states('sensor.openweathermap_wind_bearing')|float <= 28.12 %}
           NNE
        {% elif 28.13 <= states('sensor.openweathermap_wind_bearing')|float <= 39.37 %}
           NEbN
        {% elif 39.38 <= states('sensor.openweathermap_wind_bearing')|float <= 50.62 %}
           NE
        {% elif 50.63 <= states('sensor.openweathermap_wind_bearing')|float <= 61.87 %}
           NEbE
        {% elif 61.88 <= states('sensor.openweathermap_wind_bearing')|float <= 73.12 %}
           ENE
        {% elif 73.13 <= states('sensor.openweathermap_wind_bearing')|float <= 84.37 %}
           EbN
        {% elif 84.38 <= states('sensor.openweathermap_wind_bearing')|float <= 95.62 %}
           E
        {% elif 95.63 <= states('sensor.openweathermap_wind_bearing')|float <= 106.87 %}
           EbS
        {% elif 106.88 <= states('sensor.openweathermap_wind_bearing')|float <= 118.12 %}
           ESE
        {% elif 118.13 <= states('sensor.openweathermap_wind_bearing')|float <= 129.37 %}
           SEbE
        {% elif 129.38 <= states('sensor.openweathermap_wind_bearing')|float <= 140.62 %}
           SE
        {% elif 140.63 <= states('sensor.openweathermap_wind_bearing')|float <= 151.87 %}
           SEbS
        {% elif 151.88 <= states('sensor.openweathermap_wind_bearing')|float <= 163.12 %}
           SSE
        {% elif 163.13 <= states('sensor.openweathermap_wind_bearing')|float <= 174.37 %}
           SbE
        {% elif 174.38 <= states('sensor.openweathermap_wind_bearing')|float <= 185.62 %}
           S
        {% elif 185.63 <= states('sensor.openweathermap_wind_bearing')|float <= 196.87 %}
           SbW
        {% elif 196.88 <= states('sensor.openweathermap_wind_bearing')|float <= 208.12 %}
           SSW
        {% elif 208.13 <= states('sensor.openweathermap_wind_bearing')|float <= 219.37 %}
           SWbS
        {% elif 219.38 <= states('sensor.openweathermap_wind_bearing')|float <= 230.62 %}
           SW
        {% elif 230.63 <= states('sensor.openweathermap_wind_bearing')|float <= 241.87 %}
           SWbW
        {% elif 241.88 <= states('sensor.openweathermap_wind_bearing')|float <= 253.12 %}
           WSW
        {% elif 253.13 <= states('sensor.openweathermap_wind_bearing')|float <= 264.37 %}
           WbS
        {% elif 264.38 <= states('sensor.openweathermap_wind_bearing')|float <= 275.62 %}
           W
        {% elif 275.63 <= states('sensor.openweathermap_wind_bearing')|float <= 286.87 %}
           WbN
        {% elif 286.88 <= states('sensor.openweathermap_wind_bearing')|float <= 298.12 %}
           WNW
        {% elif 298.13 <= states('sensor.openweathermap_wind_bearing')|float <= 309.37 %}
           NWbW
        {% elif 309.38 <= states('sensor.openweathermap_wind_bearing')|float <= 320.62 %}
           NW
        {% elif 320.63 <= states('sensor.openweathermap_wind_bearing')|float <= 331.87 %}
           NWbN
        {% elif 331.88 <= states('sensor.openweathermap_wind_bearing')|float <= 343.12 %}
           NNW
        {% elif 343.13 <= states('sensor.openweathermap_wind_bearing')|float <= 354.37 %}
           NbW
        {% endif %}   
 
#- platform: template
#  sensors: 
#    wind_compass_point:
#      value_template: >-
#        {% if 354.38 <= states('sensor.openweathermap_wind_bearing')|float <= 5.62 %}
#           North 
#        {% elif 5.63 <= states('sensor.openweathermap_wind_bearing')|float <= 16.87 %}
#           North by east 
#        {% elif 16.88 <= states('sensor.openweathermap_wind_bearing')|float <= 28.12 %}
#           North-northeast
#        {% elif 28.13 <= states('sensor.openweathermap_wind_bearing')|float <= 39.37 %}
#           Northeast by north
#        {% elif 39.38 <= states('sensor.openweathermap_wind_bearing')|float <= 50.62 %}
#           Northeast
#        {% elif 50.63 <= states('sensor.openweathermap_wind_bearing')|float <= 61.87 %}
#           Northeast by east 
#        {% elif 61.88 <= states('sensor.openweathermap_wind_bearing')|float <= 73.12 %}
#           East-northeast 
#        {% elif 73.13 <= states('sensor.openweathermap_wind_bearing')|float <= 84.37 %}
#           East by north 
#        {% elif 84.38 <= states('sensor.openweathermap_wind_bearing')|float <= 95.62 %}
#           East 
#        {% elif 95.63 <= states('sensor.openweathermap_wind_bearing')|float <= 106.87 %}
#           East by south
#        {% elif 106.88 <= states('sensor.openweathermap_wind_bearing')|float <= 118.12 %}
#           East-southeast 
#        {% elif 118.13 <= states('sensor.openweathermap_wind_bearing')|float <= 129.37 %}
#           Southeast by east
#        {% elif 129.38 <= states('sensor.openweathermap_wind_bearing')|float <= 140.62 %}
#           Southeast
#        {% elif 140.63 <= states('sensor.openweathermap_wind_bearing')|float <= 151.87 %}
#           Southeast by south
#        {% elif 151.88 <= states('sensor.openweathermap_wind_bearing')|float <= 163.12 %}
#           South-southeast 
#        {% elif 163.13 <= states('sensor.openweathermap_wind_bearing')|float <= 174.37 %}
#           South by east
#        {% elif 174.38 <= states('sensor.openweathermap_wind_bearing')|float <= 185.62 %}
#           South
#        {% elif 185.63 <= states('sensor.openweathermap_wind_bearing')|float <= 196.87 %}
#           South by west 
#        {% elif 196.88 <= states('sensor.openweathermap_wind_bearing')|float <= 208.12 %}
#           South-southwest
#        {% elif 208.13 <= states('sensor.openweathermap_wind_bearing')|float <= 219.37 %}
#           Southwest by south
#        {% elif 219.38 <= states('sensor.openweathermap_wind_bearing')|float <= 230.62 %}
#           Southwest
#        {% elif 230.63 <= states('sensor.openweathermap_wind_bearing')|float <= 241.87 %}
#           Southwest by west
#        {% elif 241.88 <= states('sensor.openweathermap_wind_bearing')|float <= 253.12 %}
#           West-southwest 
#        {% elif 253.13 <= states('sensor.openweathermap_wind_bearing')|float <= 264.37 %}
#           West by south 
#        {% elif 264.38 <= states('sensor.openweathermap_wind_bearing')|float <= 275.62 %}
#           West
#        {% elif 275.63 <= states('sensor.openweathermap_wind_bearing')|float <= 286.87 %}
#           West by north
#        {% elif 286.88 <= states('sensor.openweathermap_wind_bearing')|float <= 298.12 %}
#           West-northwest
#        {% elif 298.13 <= states('sensor.openweathermap_wind_bearing')|float <= 309.37 %}
#           Northwest by west
#        {% elif 309.38 <= states('sensor.openweathermap_wind_bearing')|float <= 320.62 %}
#           Northwest 
#        {% elif 320.63 <= states('sensor.openweathermap_wind_bearing')|float <= 331.87 %}
#           Northwest by north
#        {% elif 331.88 <= states('sensor.openweathermap_wind_bearing')|float <= 343.12 %}
#           North-northwest
#        {% elif 343.13 <= states('sensor.openweathermap_wind_bearing')|float <= 354.37 %}
#           North by west
#        {% endif %}
        
    # direzione in gradi con icona bussola 
    wind_compass: 
      friendly_name: "Wind direction"
      value_template: '{{ states.sensor.openweathermap_wind_bearing.state }}'
      friendly_name_template: "Wind direction - {{ states.sensor.wind_compass_point.state }}"
      unit_of_measurement: '°'
      entity_picture_template: >-
        {% if 354.38 <= states('sensor.openweathermap_wind_bearing')|float <= 5.62 %}
            /local/weather/windcompass/N.png
        {% elif 5.63 <= states('sensor.openweathermap_wind_bearing')|float <= 16.87 %}
            /local/weather/windcompass/NbE.png
        {% elif 16.88 <= states('sensor.openweathermap_wind_bearing')|float <= 28.12 %}
            /local/weather/windcompass/NNE.png
        {% elif 28.13 <= states('sensor.openweathermap_wind_bearing')|float <= 39.37 %}
            /local/weather/windcompass/NEbE.png
        {% elif 39.38 <= states('sensor.openweathermap_wind_bearing')|float <= 50.62 %}
            /local/weather/windcompass/NE.png
        {% elif 50.63 <= states('sensor.openweathermap_wind_bearing')|float <= 61.87 %}
            /local/weather/windcompass/NEbE.png
        {% elif 61.88 <= states('sensor.openweathermap_wind_bearing')|float <= 73.12 %}
            /local/weather/windcompass/ENE.png
        {% elif 73.13 <= states('sensor.openweathermap_wind_bearing')|float <= 84.37 %}
            /local/weather/windcompass/EbN.png
        {% elif 84.38 <= states('sensor.openweathermap_wind_bearing')|float <= 95.62 %}
            /local/weather/windcompass/E.png
        {% elif 95.63 <= states('sensor.openweathermap_wind_bearing')|float <= 106.87 %}
            /local/weather/windcompass/EbS.png
        {% elif 106.88 <= states('sensor.openweathermap_wind_bearing')|float <= 118.12 %}
            /local/weather/windcompass/ESE.png
        {% elif 118.13 <= states('sensor.openweathermap_wind_bearing')|float <= 129.37 %}
            /local/weather/windcompass/SEbE.png
        {% elif 129.38 <= states('sensor.openweathermap_wind_bearing')|float <= 140.62 %}
            /local/weather/windcompass/SE.png
        {% elif 140.63 <= states('sensor.openweathermap_wind_bearing')|float <= 151.87 %}
            /local/weather/windcompass/SEbS.png
        {% elif 151.88 <= states('sensor.openweathermap_wind_bearing')|float <= 163.12 %}
            /local/weather/windcompass/SSE.png
        {% elif 163.13 <= states('sensor.openweathermap_wind_bearing')|float <= 174.37 %}
            /local/weather/windcompass/SbE.png
        {% elif 174.38 <= states('sensor.openweathermap_wind_bearing')|float <= 185.62 %}
            /local/weather/windcompass/S.png
        {% elif 185.63 <= states('sensor.openweathermap_wind_bearing')|float <= 196.87 %}
            /local/weather/windcompass/SbW.png
        {% elif 196.88 <= states('sensor.openweathermap_wind_bearing')|float <= 208.12 %}
            /local/weather/windcompass/SSW.png
        {% elif 208.13 <= states('sensor.openweathermap_wind_bearing')|float <= 219.37 %}
            /local/weather/windcompass/SWbS.png
        {% elif 219.38 <= states('sensor.openweathermap_wind_bearing')|float <= 230.62 %}
            /local/weather/windcompass/SW.png
        {% elif 230.63 <= states('sensor.openweathermap_wind_bearing')|float <= 241.87 %}
            /local/weather/windcompass/SWbW.png
        {% elif 241.88 <= states('sensor.openweathermap_wind_bearing')|float <= 253.12 %}
            /local/weather/windcompass/WSW.png
        {% elif 253.13 <= states('sensor.openweathermap_wind_bearing')|float <= 264.37 %}
            /local/weather/windcompass/WbS.png
        {% elif 264.38 <= states('sensor.openweathermap_wind_bearing')|float <= 275.62 %}
            /local/weather/windcompass/W.png
        {% elif 275.63 <= states('sensor.openweathermap_wind_bearing')|float <= 286.87 %}
            /local/weather/windcompass/WbN.png
        {% elif 286.88 <= states('sensor.openweathermap_wind_bearing')|float <= 298.12 %}
            /local/weather/windcompass/WNW.png
        {% elif 298.13 <= states('sensor.openweathermap_wind_bearing')|float <= 309.37 %}
            /local/weather/windcompass/NWbW.png
        {% elif 309.38 <= states('sensor.openweathermap_wind_bearing')|float <= 320.62 %}
            /local/weather/windcompass/NW.png
        {% elif 320.63 <= states('sensor.openweathermap_wind_bearing')|float <= 331.87 %}
            /local/weather/windcompass/NWbN.png
        {% elif 331.88 <= states('sensor.openweathermap_wind_bearing')|float <= 343.12 %}
            /local/weather/windcompass/NNW.png
        {% elif 343.13 <= states('sensor.openweathermap_wind_bearing')|float <= 354.37 %}
            /local/weather/windcompass/NbW.png
        {% endif %}

small problem

You are right. Something has changes so this does not work anymore.
This should work:

         {% set degrees = states('sensor.wind_compass')|float %}
         {% if  degrees <= 5.62   %} /local/WindCompass/0.png
         {% elif degrees <= 16.87 %} /local/WindCompass/11.png
         {% elif degrees <= 28.12 %} /local/WindCompass/22.png
         {% elif degrees <= 39.37 %} /local/WindCompass/33.png
         {% elif degrees <= 50.62 %} /local/WindCompass/45.png
         {% elif degrees <= 61.87 %} /local/WindCompass/56.png
         {% elif degrees <= 73.12 %} /local/WindCompass/67.png
         {% elif degrees <= 84.37 %} /local/WindCompass/78.png
         {% elif degrees <= 95.62 %} /local/WindCompass/90.png
         {% elif degrees <= 106.87 %} /local/WindCompass/101.png
         {% elif degrees <= 118.12 %} /local/WindCompass/112.png
         {% elif degrees <= 129.37 %} /local/WindCompass/123.png
         {% elif degrees <= 140.62 %} /local/WindCompass/135.png
         {% elif degrees <= 151.87 %} /local/WindCompass/146.png
         {% elif degrees <= 163.12 %} /local/WindCompass/157.png
         {% elif degrees <= 174.37 %} /local/WindCompass/168.png
         {% elif degrees <= 185.62 %} /local/WindCompass/180.png
         {% elif degrees <= 196.87 %} /local/WindCompass/191.png
         {% elif degrees <= 208.12 %} /local/WindCompass/202.png
         {% elif degrees <= 219.37 %} /local/WindCompass/213.png
         {% elif degrees <= 230.62 %} /local/WindCompass/225.png
         {% elif degrees <= 241.87 %} /local/WindCompass/236.png
         {% elif degrees <= 253.12 %} /local/WindCompass/247.png
         {% elif degrees <= 264.37 %} /local/WindCompass/258.png
         {% elif degrees <= 275.62 %} /local/WindCompass/270.png
         {% elif degrees <= 286.87 %} /local/WindCompass/281.png
         {% elif degrees <= 298.12 %} /local/WindCompass/292.png
         {% elif degrees <= 309.37 %} /local/WindCompass/303.png
         {% elif degrees <= 320.62 %} /local/WindCompass/315.png
         {% elif degrees <= 331.87 %} /local/WindCompass/326.png
         {% elif degrees <= 343.12 %} /local/WindCompass/337.png
         {% elif degrees <= 354.37 %} /local/WindCompass/348.png
         {% else  %} /local/WindCompass/0.png
         {% endif %}

it works! @Tomahawk Thank you very much