does this still work, or need to be changed?
Still works for me.
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
- create a helper called āsensor.wind_dirā
- 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: