Useful Sensor: Cardinal Wind Direction for Home Assistant

ConfigHome AssistantSmart HomeUseful Sensor

Written by:

At a glance – gustier than usual this morning.

As someone who cycles to work most days, I keep a pretty close eye on the weather. One thing I like to know is which way the wind is blowing – a strong headwind means I should maybe opt for the road bike, not the cruiser. Home Assistant has a ton of weather platforms – and the Dark Sky one that I prefer tracks wind direction. The only problem is it returns the direction in degrees, which is meaningless to me.

See below for a template sensor that will convert degrees to a human-readable cardinal direction.

This assumes you have your sensors broken out into a separate YAML file.

sensors.yaml

# Convert the Wind Direction from degrees to cardinal
- platform: template
  sensors:
    friendly_wind_direction:
      friendly_name: 'Wind Direction'
      value_template: >-
        {%if states.sensor.dark_sky_wind_bearing.state | float<=11 %}N
        {% elif states.sensor.dark_sky_wind_bearing.state | float>348 %}N
        {% elif states.sensor.dark_sky_wind_bearing.state | float<=34 | float>11 %}NNE
        {% elif states.sensor.dark_sky_wind_bearing.state | float<=56 | float>34 %}NE
        {% elif states.sensor.dark_sky_wind_bearing.state | float<=79 | float>56 %}ENE
        {% elif states.sensor.dark_sky_wind_bearing.state | float<=101 | float>79 %}E
        {% elif states.sensor.dark_sky_wind_bearing.state | float<=124 | float>101 %}ESE
        {% elif states.sensor.dark_sky_wind_bearing.state | float<=146 | float>124 %}SE
        {% elif states.sensor.dark_sky_wind_bearing.state | float<=169 | float>146 %}SSE
        {% elif states.sensor.dark_sky_wind_bearing.state | float<=191 | float>169 %}S
        {% elif states.sensor.dark_sky_wind_bearing.state | float<=214 | float>191 %}SSW
        {% elif states.sensor.dark_sky_wind_bearing.state | float<=236 | float>214 %}SW
        {% elif states.sensor.dark_sky_wind_bearing.state | float<=259 | float>236 %}WSW
        {% elif states.sensor.dark_sky_wind_bearing.state | float<=281 | float>259 %}W
        {% elif states.sensor.dark_sky_wind_bearing.state | float<=304 | float>281 %}WNW
        {% elif states.sensor.dark_sky_wind_bearing.state | float<=326 | float>304 %}NW
        {% elif states.sensor.dark_sky_wind_bearing.state | float<=348 | float>326 %}NNW
        {%- endif %}

Pastebin link: https://pastebin.com/BvwXDpi5

 

RELATED >>  Location Aware Notification Lights with Node-Red and IFTTT

4 Replies to “Useful Sensor: Cardinal Wind Direction for Home Assistant”

  1. DrJeff says:

    Thanks I did this in my other automation software before “XTension” for the Mac but forgot to transfer it to Home Assistant.

  2. Acuvi says:

    Thank you, this helped a ton. I got also added this to my HADashboard and it makes it much easier to read.

    I walk and bus to work so I also need to know the weather before I leave for the day. I appreciate your work, this also helped me clean up my sensors as I did need to create the sensors.yaml.

    Thanks.

  3. jon snow says:

    Great code, thank you! You can also create a variable, and use that variable inside the conditions instead of having `states.sensor.dark_sky_wind_bearing.state | float` in every condition. Something like below:

    “`
    value_template: >-
    {% set value = states.sensor.dark_sky_wind_bearing.state | float %}
    {%if value 348 %}N
    {% elif value 11 %}NNE
    {% elif value 34 %}NE
    {% elif value 56 %}ENE
    {% elif value 79 %}E
    {% elif value 101 %}ESE
    {% elif value 124 %}SE
    {% elif value 146 %}SSE
    {% elif value 169 %}S
    {% elif value 191 %}SSW
    {% elif value 214 %}SW
    {% elif value 236 %}WSW
    {% elif value 259 %}W
    {% elif value 281 %}WNW
    {% elif value 304 %}NW
    {% elif value 326 %}NNW
    {%- endif %}
    “`

Leave a Reply

Your email address will not be published. Required fields are marked *