Useful Sensor: Cardinal Wind Direction for Home Assistant

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 >>  Home Assistant: Making My Plants Talk with IoT Sensors and a Python Script

Leave a Reply

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