home-assistant-configuration icon indicating copy to clipboard operation
home-assistant-configuration copied to clipboard

Need to improve template weather sensor logic

Open thejeffreystone opened this issue 5 years ago • 0 comments
trafficstars

Need logic to handle the event when weather sensors have not returned any data from weather API. Should just be able to wrap this logic to test if states.weather.klzu_daynight.state == 'unavailable' that way the error below doesn't fill my log file.

2020-11-17 15:42:53 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template("{%- if states.weather.klzu_daynight.attributes.forecast[1].daytime == True %} {{ states.weather.klzu_daynight.attributes.forecast[1].detailed_description | truncate(250, False) }} {% elif states.weather.klzu_daynight.attributes.forecast[2].daytime == True %} {{ states.weather.klzu_daynight.attributes.forecast[2].detailed_description | truncate(250, False) }} {%- endif %}") Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 421, in async_render render_result = compiled.render(kwargs) File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 1090, in render self.environment.handle_exception() File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 832, in handle_exception reraise(*rewrite_traceback_stack(source=source)) File "/usr/local/lib/python3.8/site-packages/jinja2/_compat.py", line 28, in reraise raise value.with_traceback(tb) File "<template>", line 1, in top-level template code File "/usr/local/lib/python3.8/site-packages/jinja2/sandbox.py", line 384, in getitem return obj[argument] jinja2.exceptions.UndefinedError: 'mappingproxy object' has no attribute 'forecast'

thejeffreystone avatar Nov 17 '20 20:11 thejeffreystone