Sensor Wind compass - up for grabs

Thanks for this excellent share, works great.

Just comparing readings from your config to readings from Weather Underground which doesn’t match, any ideas?

sensor.wind_compass 221.6
sensor.weather_wind_direction 221.6
sensor.dark_sky_wind_bearing 158
sensor.pws_wind_dir West

I use Yr.no as the source for wind data. Which is the preferred weather data provider where I live.

Weather underground, I think, uses other sources like private weather stations for collecting waether data.

Find your source sensor from HA, which is as local for you. Then use it with the wind compass.

Great work! I have the new sensors with the wind information, but I am not able to get the image to load.

I am using hass.io.
Uploaded all images to my directory: config/www/wind_compass

I am using this code (see file information, is that the right address)?

{% elif 28.13 <= states('sensor.yr_wind_direction')|float <= 39.37 %}
`              /local/wind_compass/33.png`

Remove the apostrophe
feil

1 Like

cool. nice work.
Ive set it up using Buienradar as follows:

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

or shorter:

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

not sure we need the abbreviation template, since Buienradar has that built-in:

48

But, this template might be more precise, so Ill leave it in for the moment :wink:

Nice little dashboard in the frontend Weather page.
Thanks for the icons and work on this!

2 Likes

follow-up:
please have a look at How to shorten/join this template?

how @datamonkey helped me create this even shorter and way more intelligent template:

  wind_compass:
    friendly_name: Windrichting
    value_template: >
      {{ states('sensor.br_wind_direction_azimuth') }}
    friendly_name_template: >
      {{ states('sensor.wind_compass_abbreviation') }}
    unit_of_measurement: '°'
    entity_picture_template: >
      {% set degrees = states('sensor.br_wind_direction_azimuth')|float %}
      {% set path = '/local/weather/wind_compass/' %}
      {% set ext = '.png' %}
      {{path-}}
      {%- if 354.38 <= degrees or degrees <= 5.62 -%} 0
      {%- else -%}
      {{ ( ((degrees/11.25)|round )*11.25 )| round}}
      {%- endif -%}
      {{-ext-}}

so cool.

3 Likes

Wow. Nifty : )

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

thanks to @petro its getting even better:

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

now this I must study :wink:

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) }}

42

2 Likes

Is it possible to show this on the map component in Home assistant ?

I have not tried putting this sensor on the map. Think that sensor need latitude and longitude attributes, and it will display automatically.

Thanks guys for the job, work well to track ISS.

entities:
  - entity: sensor.iss_compass_direction
style: |
  ha-card {
    background: url(/local/pictures/WindCompass/windrose2.png);
    color: red;
    text-shadow: 1px 1px 0 #FFF;
  }
type: glance

Sans%20titre

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.

Hi!

I use Tomahawk’s code, and here is simple Lovelace Wind compass card:

Sensors:

  - platform: template
    sensors: 
      wind_compass_abbreviation:
        value_template: >-
          {% if 354.38 <= states('sensor.weather_wind_direction')|float <= 5.62 %}
             N
          {% elif 5.63 <= states('sensor.weather_wind_direction')|float <= 16.87 %}
             NbE
          {% elif 16.88 <= states('sensor.weather_wind_direction')|float <= 28.12 %}
             NNE
          {% elif 28.13 <= states('sensor.weather_wind_direction')|float <= 39.37 %}
             NEbN
          {% elif 39.38 <= states('sensor.weather_wind_direction')|float <= 50.62 %}
             NE
          {% elif 50.63 <= states('sensor.weather_wind_direction')|float <= 61.87 %}
             NEbE
          {% elif 61.88 <= states('sensor.weather_wind_direction')|float <= 73.12 %}
             ENE
          {% elif 73.13 <= states('sensor.weather_wind_direction')|float <= 84.37 %}
             EbN
          {% elif 84.38 <= states('sensor.weather_wind_direction')|float <= 95.62 %}
             E
          {% elif 95.63 <= states('sensor.weather_wind_direction')|float <= 106.87 %}
             EbS
          {% elif 106.88 <= states('sensor.weather_wind_direction')|float <= 118.12 %}
             ESE
          {% elif 118.13 <= states('sensor.weather_wind_direction')|float <= 129.37 %}
             SEbE
          {% elif 129.38 <= states('sensor.weather_wind_direction')|float <= 140.62 %}
             SE
          {% elif 140.63 <= states('sensor.weather_wind_direction')|float <= 151.87 %}
             SEbS
          {% elif 151.88 <= states('sensor.weather_wind_direction')|float <= 163.12 %}
             SSE
          {% elif 163.13 <= states('sensor.weather_wind_direction')|float <= 174.37 %}
             SbE
          {% elif 174.38 <= states('sensor.weather_wind_direction')|float <= 185.62 %}
             S
          {% elif 185.63 <= states('sensor.weather_wind_direction')|float <= 196.87 %}
             SbW
          {% elif 196.88 <= states('sensor.weather_wind_direction')|float <= 208.12 %}
             SSW
          {% elif 208.13 <= states('sensor.weather_wind_direction')|float <= 219.37 %}
             SWbS
          {% elif 219.38 <= states('sensor.weather_wind_direction')|float <= 230.62 %}
             SW
          {% elif 230.63 <= states('sensor.weather_wind_direction')|float <= 241.87 %}
             SWbW
          {% elif 241.88 <= states('sensor.weather_wind_direction')|float <= 253.12 %}
             WSW
          {% elif 253.13 <= states('sensor.weather_wind_direction')|float <= 264.37 %}
             WbS
          {% elif 264.38 <= states('sensor.weather_wind_direction')|float <= 275.62 %}
             W
          {% elif 275.63 <= states('sensor.weather_wind_direction')|float <= 286.87 %}
             WbN
          {% elif 286.88 <= states('sensor.weather_wind_direction')|float <= 298.12 %}
             WNW
          {% elif 298.13 <= states('sensor.weather_wind_direction')|float <= 309.37 %}
             NWbW
          {% elif 309.38 <= states('sensor.weather_wind_direction')|float <= 320.62 %}
             NW
          {% elif 320.63 <= states('sensor.weather_wind_direction')|float <= 331.87 %}
             NWbN
          {% elif 331.88 <= states('sensor.weather_wind_direction')|float <= 343.12 %}
             NNW
          {% elif 343.13 <= states('sensor.weather_wind_direction')|float <= 354.37 %}
             NbW
          {% endif %}

Lovelace:

  elements:
    - entity: sensor.wind_compass_abbreviation
      image: /local/WindCompass/E.png
      state_image:
        'N': /local/WindCompass/N.png
        NbE: /local/WindCompass/NbE.png
        NNE: /local/WindCompass/NNE.png
        NEbN: /local/WindCompass/NEbN.png
        NE: /local/WindCompass/NE.png
        NEbE: /local/WindCompass/NEbE.png
        ENE: /local/WindCompass/ENE.png
        EbN: /local/WindCompass/EbN.png
        E: /local/WindCompass/E.png
        EbS: /local/WindCompass/EbS.png
        ESE: /local/WindCompass/ESE.png
        SEbE: /local/WindCompass/SEbE.png
        SE: /local/WindCompass/SE.png
        SEbS: /local/WindCompass/SEbS.png
        SSE: /local/WindCompass/SSE.png
        SbE: /local/WindCompass/SbE.png
        S: /local/WindCompass/S.png
        SbW: /local/WindCompass/SbW.png
        SSW: /local/WindCompass/SSW.png
        SWbS: /local/WindCompass/SWbS.png
        SW: /local/WindCompass/SW.png
        SWbW: /local/WindCompass/SWbW.png
        WSW: /local/WindCompass/WSW.png
        WbS: /local/WindCompass/WbS.png
        W: /local/WindCompass/W.png
        WbN: /local/WindCompass/WbN.png
        WNW: /local/WindCompass/WNW.png
        NWbW: /local/WindCompass/NWbW.png
        NW: /local/WindCompass/NW.png
        NWbN: /local/WindCompass/NWbN.png
        NNW: /local/WindCompass/NNW.png
        NbW: /local/WindCompass/NbW.png
      style:
        left: 50%
        top: 50%
        width: 100%
      type: image
  image: /local/WindCompass/background.png
  type: picture-elements

:beers:

1 Like

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