So I have a Qubino Weather Station that I’ve been playing with, and I’m currently working to create a template sensor to reflect the direction of the wind. I have an entity_id called sensor.qubino_zmnhzdx_weather_station_direction_44_7_2, which outputs a number value between 0 and 360, depending on the direction (i.e. 0/360 = North, 90 = East, 180 = South, 270 = West).
So here is the template I have created, currently:
weather_wind_direction:
friendly_name: 'Wind Direction'
value_template: >-
{% if states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 | int >= 0 and states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 | int <= 22.4 %}
North
{% elif states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 | int >= 22.5 and states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 | int <= 67.4 %}
North-East
{% elif states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 | int >= 67.5 and states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 | int <= 112.4 %}
East
{% elif states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 | int >= 112.5 and states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 | int <= 157.4 %}
South-East
{% elif states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 | int >= 157.5 and states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 | int <= 202.4 %}
South
{% elif states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 | int >= 202.5 and states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 | int <= 247.4 %}
South-West
{% elif states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 | int >= 247.5 and states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 | int <= 292.4 %}
West
{% elif states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 | int >= 292.5 and states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 | int <= 327.4 %}
North-West
{% elif states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 | int >= 327.5 and states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 | int <= 360 %}
North
{% else %}
FAILED
{% endif %}
However, the issue I’m running into, is that no mater what number sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 has, this sensor.weather_wind_direction is showing North, which isn’t correct. I.E., the screenshot above shows 157.5 as the state, which should translate to South, but sensor.weather_wind_direction is showing North.
Is there something wrong with my template? I’m not sure where else to go from here.
I wonder if you might benefit from some parentheses to group statements. Have you tested this in the template dev tool? That’s an easy way to test live.
{% if (states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 | int) >= 0 and (states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 | int) <= 22.4 %}
or even
{% if ( (states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 | int) >= 0 ) and ( (states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 | int) <= 22.4 ) %}
Thanks for the response. I have tried the first option you suggested, and got the same result. I just now tried the second option, and same behavior.
Yes, I have been using the template dev tool for testing. As a test, I moved the North-Eastif to the top, and the result is still giving me the same North. For whatever reason, the template is always matching to:
{% if states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 | int >= 0 and states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2 | int <= 22.4 %}
North
Regardless of where it’s positioned in the template (so it’s not just matching to the top if). The actual value is 132.5, but it’s matching to >= 0 and <= 22.4. How is that possible? Is the actual value (i.e., 132.5) not being properly represented by an integer in the state, and instead a string? Is it not following the and <= x?
Convert the value into an integer. If the conversion doesn’t work it will return 0.
So I think that’s what is happening. It’s failing to convert the value to an integer, so it’s returning 0 which matches the North if statement. The float filter gives me the same result.
What is the output of just {{states.sensor.qubino_zmnhzdx_weather_station_direction_44_7_2}}
I think you need .state at the end after the numbers
By the way, since it checks the conditions in order after the first one you just need to check if it is less than 64.7 you do not need to re confirm that it is greater than 22.5 since that would have been caught in the condition above it. Then do this for every condition below it as well. Bit more efficient and cleaner looking.
Thanks for the advise about ditching the other part of the statement, that makes a lot more sense but I wasn’t sure if it processed in order like that. I assumed it did, but wanted to play it safe. I will get that updated, test, confirm, and share here shortly!
I am new to HA and setting up my system. I have a sun blind at my terrace and I would like to control it with HA over z-wave.
What is your experience with Qubino Weather Station, do you recommend it to buy? The most important for me is the wind sensor. It should be reliable to protect the sun blind being destroyed by wind. Thanks.