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 Thanks again !
I’m glad you solved it!
Cool, it works, ty!
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') }}"
Hello ya’ll. Same thing here. Trying to convert wind direction degrees into text. All the code provided here gave me errors and also it looked quite different to the other sensor i had set up in my config. I adapted it to the same format, no errors, bit also no new entity.
What am I doing wrong?
Total noob here, so please bare with me.
Her is my complete config.yaml
# Loads default set of integrations. Do not remove.
default_config:
# Load frontend themes from the themes folder
frontend:
themes: !include_dir_merge_named themes
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
template:
- sensor:
- name: "Technical & Garden | Power"
unit_of_measurement: W
icon: mdi:lightning-bolt
state: >-
{{ (states('sensor.shellyproem50_08f9e0e5c190_em0_power')|float -
states('sensor.shellyproem50_08f9e0e5c190_em1_power')|float )|round(1) }}
- sensor:
- name: "Wind Direction TXT"
icon: mdi:navigation
value_template: >
{% set dir = int(states('sensor.gw2000a_wind_direction') | 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)] }}