I have a sensor template i’m trying to make. It takes the sensor reading from sensor.weather_wind_bearing which is in degrees 0-359 I want the sensor to out put 0 = north 90 = east ect. That much works. When I get to in between parts. I need it to show if it’s between 0 and 90 it’s north east and ect. Below is my setup. I’ve look around and can’t seem to find anything on this. If there is a better thread to look at I would love to read that. Thanks
sensor:
platform: template
sensors:
weather_wind_bearing:
friendly_name: Wind direction
value_template: >-
{%- if is_state("sensor.weather_wind_bearing", "0") %}
North
{% elif is_state("sensor.weather_wind_bearing", "90") %}
East
{% elif is_state("sensor.weather_wind_bearing", "180") %}
South
{% elif is_state("sensor.weather_wind_bearing", "270") %}
West
{% elif states.sensor.weather_wind_bearing.state > 0 and states.sensor.weather_wind_bearing.state < 90 %}
North East
{% elif states.sensor.weather_wind_bearing.state > 90 and states.sensor.weather_wind_bearing.state < 180 %}
South East
{% elif states.sensor.weather_wind_bearing.state > 180 and states.sensor.weather_wind_bearing.state < 270 %}
South West
{% elif states.sensor.weather_wind_bearing.state > 270 and states.sensor.weather_wind_bearing.state < 360 %}
North West
{% else %}
unknown
{%- endif %}
If this doesn’t work right I’m sorry Thanks for any and all help
You could include the Weather Underground sensor, which includes two methods of showing the wind direction (wind direction and wind string, which shows direction and speed). It’s not an answer to your question but it is a solution.
It is a different route to go, if I can’t get the and statements working then I’ll have to look into weather underground, thanks for the suggestion. I still want to figure the template and statements out
I know I saw someone doing something similar when I was researching this a while back - I was thinking of doing the same thing. I’m not sure where it was though; it wasn’t in this forum. I’ll look through my history and see if I can find it and if it is of any help.
So I noticed this post was referenced in another post about templating examples. So I figured I better revisit my original and see if my studying has come up fruitful. So far I got it working like a charm. My working code is below for anyone struggling like I was with this or wanting this. Thanks
# Template Sensor Wind Direction
- platform: template
sensors:
wind_dir:
friendly_name: 'Wind Direction'
value_template: >-
{%if states.sensor.weather_wind_bearing.state | float<=11 %}North
{% elif states.sensor.weather_wind_bearing.state | float>348 %}North
{% elif states.sensor.weather_wind_bearing.state | float<=34 | float>11 %}North North East
{% elif states.sensor.weather_wind_bearing.state | float<=56 | float>34 %}North East
{% elif states.sensor.weather_wind_bearing.state | float<=79 | float>56 %}East North East
{% elif states.sensor.weather_wind_bearing.state | float<=101 | float>79 %}East
{% elif states.sensor.weather_wind_bearing.state | float<=124 | float>101 %}East South East
{% elif states.sensor.weather_wind_bearing.state | float<=146 | float>124 %}South East
{% elif states.sensor.weather_wind_bearing.state | float<=169 | float>146 %}South South East
{% elif states.sensor.weather_wind_bearing.state | float<=191 | float>169 %}South
{% elif states.sensor.weather_wind_bearing.state | float<=214 | float>191 %}South South West
{% elif states.sensor.weather_wind_bearing.state | float<=236 | float>214 %}South West
{% elif states.sensor.weather_wind_bearing.state | float<=259 | float>236 %}West South West
{% elif states.sensor.weather_wind_bearing.state | float<=281 | float>259 %}West
{% elif states.sensor.weather_wind_bearing.state | float<=304 | float>281 %}West North West
{% elif states.sensor.weather_wind_bearing.state | float<=326 | float>304 %}West North West
{% elif states.sensor.weather_wind_bearing.state | float<=348 | float>326 %}North North West
{%- endif %}
I think there is a duplication in the list (the second West North West should be North West).Here is my modification to correct that as well as abbreviate the longer direction headings:
Ahh nice. I had a issue when I was changing it from the original template I used and must have copied a line and not fixed the result. I have been thinking about simplifying it even more. cutting it back to 4-8 directions instead of 16.