Convert wind direction degrees to text

does this still work, or need to be changed?

Still works for me.

1 Like

boom just found this and works a treat!

Sorry a newbie here.
Please tell me which step I am doing wrong and what I should do

  1. create a helper called ā€œsensor.wind_dirā€
  2. Paste the code listed above in the state template field and it objects
    Which field am I supposed to paste the code into please?

Tony

If you havenā€™t already, create a sensors.yaml file in your /config directory and add the following code:

- platform: template
  sensors:
    weather_wind_dir:  
      friendly_name: 'Wind Direction'
      value_template: >
        {% set direction = ['N','NNE','NE','ENE','E','ESE','SE','SSE','S','SSW','SW','WSW','W','WNW','NW','NNW','N'] %}
        {% set degree = states('sensor.wind_direction')|float %}
        {{ direction[((degree+11.25)/22.5)|int] }}

If sensors.yaml is new to your configuration, add this line to configuration.yaml:
sensor: !include sensors.yaml

You could add the sensor directly to your configuration.yaml file if youā€™f prefer, but the syntax would change slightly. I donā€™t use the helpers yet. This is working for me on HA 2024.12.0.

When setting this up as a Helper:

The ā€œState Templateā€ field only accepts Jinja templates, use

{% set direction = ['N','NNE','NE','ENE','E','ESE','SE','SSE','S','SSW','SW','WSW','W','WNW','NW','NNW','N'] %}
{% set degree = states('sensor.wind_direction')|float %}
{{ direction[((degree+11.25)/22.5)|int] }}

Make sure to use the entity ID of your sensor if it isnā€™t sensor.wind_direction.

Leave all the other fields empty: