I can see some errors for a few sensors that I extract attributes from, and just cleaning up a bit.
I’m using the meteoalarm, and I extract the color and type to seperate sensors to format the output a bit better.
The problem is that after a boot, the sensor doesn’t have all the attributes populated, so I will see errors like this:
Could not render template meteo_type, the state is unknown.
This should prevent errors when the attribute is unknown and is why you should always use this format for templates. There’s a yellow warning about it half way down this page:
Hi @tom_l
Ok, at first I just had that in the config, and got the errors, then I ventured out into the jinja thing to get rid of the error
If I just have this
meteo_type:
value_template: >
{% set v = state_attr('binary_sensor.meteoalarm', 'event') %}
{{ 'off' if v == none else v.split(" ")[1] }}
If the event attribute doesn’t exist, the state_attr function will return none. The second line will report off if the result is none otherwise it will process the result.