I have a wind sensor which outputs its wind direction in degrees. This part works fine. What I want to do is create a template that translates the “degrees” into the various letters that represent the true direction of the wind.
Quite easy. Simply replace [sensor.tidewater_wind_dir_avg_10m] (my weather stations wind direction sensor) with your wind direction sensor in the code below:
{% set winbearing = (states('sensor.tidewater_wind_dir_avg_10m')|float/45)|int|round +1 %}
{% set winddir = ['North', 'North East','East','South East','South','South West','West','North West']%}
{{ winddir[winbearing]}}
In your code: {{ winddir[winbearing] }} outputs the wind direction as plain text. Test it in the Template Editor and then incorporate into your code. Enjoy.
Disclaimer: I am not the author of this code. All credit goes to the unknown original coder.
When you asked for the code to convert a number of degree to wind direction text, I assumed you were able to create the template sensor. Since the conversion was the complicated part, that’s what I posted for you. Here is the complete code. Cut and Paste into wherever your other template sensors reside. Reload template entities. Done.