Trying to sort out an mqtt sensor template issue. What I have is:
mqtt:
sensor:
- name: weewx_wind_dir
unique_id: weewx_wind_dir
state_topic: "weather/loop"
unit_of_measurement: "º"
value_template: >
{% if value_json.windDir %}
{{ value_json.windDir | round(0) }}
{% endif %}
The issue is that when the wind speed is 0, the windDir is not sent in the mqtt message. No wind - No direction. However the wind speed does report with 0.0.
I would think that the if value_json windDir
would prevent the sensor update but I get the following warning in the logs.
Template variable warning: 'dict object' has no attribute 'windDir' when rendering '{% if value_json.windDir %} {{ value_json.windDir | round(0) }} {% endif %}'
8:52:52 AM – (WARNING) helpers/template.py - message first occurred at 8:48:50 AM and shows up 3 times
Any thoughts on using a value_template that would eliminate this error?
Cheers