Wind direction

BTW it only took me 10 minutes to put together so it still falls into your low effort category of goodness. :wink: :grin:

1 Like

You seem to have a great understanding of the use of template in HA. Is there better document than the doc link? Not much detail there. Thanks

Just the Jinja online document which I think is what you are referring to. In general, Jinja uses python-like syntax. So if you know python you have a tremendous leg up. And well, HA is also python. If you keep that in mind then a lot of the rules and behaviors of the whole system start to make a lot more sense (for example why entity states represent numbers as text). So if there is anything you should do it’s learn python if you don’t already know it.

1 Like

I want to use SMHI:s wind bearing but i can’t get it to work . I only get N and today the wind is from S.

Is it possible to use: states.weather.smhi_klagshamn.attributes.wind_bearing?
The state write out 216 in develop tools today.

Can you please help me?

If you haven’t fixed this yet you could always submit your sensor config so we can have a look at it.

Have a look here for another simple solution:
https://community.home-assistant.io/t/wind-direction-template-sensor/297511

This worked great for me, and my Acurite weather station.
I did need to change how the sensor is called, as shown below:

{% set dir = states.sensor.pws_report.attributes.observations[0].winddir|float %}

Hi, I have tried to use this config in my config YAML …and it breaks my main weather integration for some reason that I cant work out … The code works in the template test in Dev Tools.

'sensor:

  • platform: wundergroundpws
    api_key: secret key here
    pws_id: my station here
    numeric_precision: none
    monitored_conditions:
    • temp
    • dewpt
    • heatIndex
    • winddir
    • humidity
    • weather_1d
    • weather_1n
    • weather_2d
    • weather_2n
    • weather_3d
    • weather_3n
    • weather_4d
    • weather_4n

camera:

####################################################

Sensor - Templates

####################################################

sensor:

  • platform: template
    sensors:
    your_wind_sensor:
    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.wupws_winddir’)|float %}
    {{ direction[((degree+11.25)/22.5)|int] }} ’

Not sure what the error message is and you should really preserve the actual code spacing in your question above as it makes it easier to help you however in glancing through your listing there appears to be an extra single quote at the end of the last line that should not be there.

Hi …appreciate you assisting …I take your point about preserving the code spacing & iindents. I solved the issues …it was one of incorrect indents …TIL more about YAML :slight_smile: Thanks again !

3 Likes

I’m glad you solved it!

Cool, it works, ty! :slight_smile:

Is it possible to prefix the String with an arrow image? For example mdi:navigation with rotation?

Gents,

How do I need to change the calculation to fit the new formatting?
template:
sensor:
name: “Wind-Direction”
unique_id: Windrichting
device_class: “Wind”
state: {% set direction = [‘N’,‘NNE’,‘NE’,‘ENE’,‘E’,‘ESE’,‘SE’,‘SSE’,‘S’,‘SSW’,‘SW’,‘WSW’,‘W’,‘WNW’,‘NW’,‘NNW’,‘N’] %}
{% set degree = states(‘GW2000C WWind Direction’)|float %}
{{ direction[((degree+11.25)/22.5)|int] }}

I lioke the solution but the format does not work in the newer version together with my other template sensors.

Kind regards, fantic

I solved it by downloading the Compass card, this will show the correct value and the direction as an arrow plus the windspeed.

Thanks anyhow

which new formatting ?

I was referring to this type of formatting:

  • binary_sensor:
    name: ‘Brievenbusje’
    unique_id: Brievenbusje
    device_class: “door”
    state: >
    {% if is_state(‘binary_sensor.Brievenbus_contact’, ‘Open’) %} closed
    {% else %} Open
    {% endif %}

In my version I get this error when I use the values used in the solutions stated here:
Invalid config for ‘template’ at configuration.yaml, line 145: ‘value_template’ is an invalid option for ‘template’, check: sensor->0->value_template Invalid config for ‘template’ at configuration.yaml, line 145: ‘wind_direction_txt’ is an invalid option for ‘template’, check: sensor->0->wind_direction_txt Invalid config for ‘template’ at configuration.yaml, line 145: required key ‘state’ not provided

I have used this solution,

since some weeks / month it is not working anymore.

i tried some different Solution but none on them seem to be working.

other sensors of the template section are working.
If i copy & Paste the code to delevoper Tools - Template
it shows me the Direvtion correcly in the Output.
Unter Develper Tools - States i cannot find mit wind_direction, or weather_wind_dir, weather_wind_direction as a sensor with a Value.

here’s a part my code of the configuration.yaml
(looks like the wind icon is not working too)
the remaining Power is availble in sensor states.

  - platform: template
    sensors:
        name_icon_weather:
          friendly_name: name icon weather
          value_template: >
           {% if is_state('weather.forecast_home', 'clear-night') %}12181
           {% elif is_state('weather.forecast_home', 'cloudy') %}53384
           {% elif is_state('weather.forecast_home', 'exceptional') %}56705
           {% elif is_state('weather.forecast_home', 'fog') %}17055
           {% elif is_state('weather.forecast_home', 'hail') %}53288
           {% elif is_state('weather.forecast_home', 'lightning') %}50231
           {% elif is_state('weather.forecast_home', 'lightning-rainy') %}49299
           {% elif is_state('weather.forecast_home', 'partlycloudy') %}53802
           {% elif is_state('weather.forecast_home', 'pouring') %}49300
           {% elif is_state('weather.forecast_home', 'rainy') %}2284
           {% elif is_state('weather.forecast_home', 'snowy') %}2289
           {% elif is_state('weather.forecast_home', 'snowy-rainy') %}49301
           {% elif is_state('weather.forecast_home', 'sunny') %}2282
           {% elif is_state('weather.forecast_home', 'windy') %}55032
           {% else %}2422
           {% endif %}
    sensors:
      wind_direction_txt:
      friendly_name: 'Windrichtung'
      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.wettersensoroc3_1_jeq0140841_wind_direction')|float %}
              {{ direction[((degree+11.25)/22.5)|int] }}
#         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 = state_attr('weather.forecast_home', 'wind_bearing')|float %} {{ direction[((degree+11.25)/22.5)|int] }}
#        weather_wind_direction:
#         fiendly_name: windrichtung
#          value_template: >
#              {% set dir = state_attr("weather.forecast_home", "wind_bearing")|float %}
#              {% if 11.25 < dir <= 33.75 %} NNE
#              {% elif 33.75 < dir <= 56.25 %} NE
#              {% elif 56.25 < dir <= 78.75 %} ENE
#              {% elif 78.75 < dir <= 101.25 %} E
#              {% elif 101.25 < dir <= 123.75 %} ESE
#              {% elif 123.75 < dir <= 146.25 %} SE
#              {% elif 146.25 < dir <= 168.75 %} SSE
#              {% elif 168.75 < dir <= 191.25 %} S
#              {% elif 191.25 < dir <= 213.75 %} SSW
#              {% elif 213.75 < dir <= 236.25 %} SW
#              {% elif 236.25 < dir <= 258.75 %} WSW
#              {% elif 258.75 < dir <= 281.25 %} W
#              {% elif 281.25 < dir <= 303.75 %} WNW
#              {% elif 303.75 < dir <= 326.25 %} NW
#              {% elif 326.25 < dir <= 348.75 %} NNW
#              {% else %} N
#              {% endif %}
    sensors:
        remaining_power:
          value_template: "{{ (states('sensor.solarbank_2_e1600_pro_ac_hausabgabe') | float| round(0)) + (states('sensor.smart_meter_netzbezug')| float| round(0))}}"
          unit_of_measurement: 'W'
          friendly_name: Gesamt Verbrauch```

For simplicity a lookup maybe simpler:

  weather_wind_dir:
        value_template: >
          {% set dir = int(states('sensor.darksky_weather_wind_bearing') | float  %}
          {% set navDir = [ 'N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N' ] %}
          {{ navDir[int(dir/22.5)] }}
 

you are using the legacy format, but also you have 3 times

sensors:

the last one will be seen and the other 2 might be lost because of that.

check the link and notice there’s only 1

sensor:
  - platform: template
    sensors:  ### <<<----- check this, only 1 is allowed
      solar_angle:
        friendly_name: "Sun angle"
        unit_of_measurement: "degrees"
        value_template: "{{ state_attr('sun.sun', 'elevation') }}"

      sunrise:
        value_template: "{{ state_attr('sun.sun', 'next_rising') }}"