HA 2021.10:
In a template sensor, I have the following template value:
{{ states(‘sensor.abcd’)|round }}
Now I got the error message:
Template warning: ‘round’ got invalid input ‘unknown’ when rendering template but no default was specified. Currently ‘round’ will return ‘unknown’, however this template will fail to render in Home Assistant core 2021.12
{{ states(‘sensor.abcd’)|default(0)|round }} will not solve it.
Won’t round(2,default=0) result in 0’s in the data?
Can I set default=unknown?
And why must a default be set if availability is already checking if the input is a number with is_number in the first place?
What do you do when it is just an unit conversion? You usually don’t want to convert “0” if the source is unknown but get unknown output instead? Is there any simple way to do that or do you need some if-else condition every time?
How? If my formula is like that: (states('sensor.airrohr_bme280_pressure')|float / 133.322)|round(0) ? You can’t set the missing sensor value to string and then use it like a number for further calculations and still get “unknown” result.
I don’t understand why the default value addition does not work in my case.
I tried multiple ways but still the warning:
Template warning: ‘float’ got invalid input ‘unavailable’ when rendering template ‘:host { --card-mod-icon-color: {% if states(‘sensor.paradijsvogelplant_vochtigheid’)| float <= 15 %} red {% else %} {% if states(‘sensor.paradijsvogelplant_vochtigheid’)| float >= 60 %} red {% else %} green {% endif %} {% endif %} }’ but no default was specified. Currently ‘float’ will return ‘0’, however this template will fail to render in Home Assistant core 2022.1
pops up in my log.
code in dashboard:
- type: button
icon: mdi:flower
entity: sensor.paradijsvogelplant_vochtigheid
name: pv plant
show_name: false
card_mod:
style: |
:host {
--card-mod-icon-color:
{% if states('sensor.paradijsvogelplant_vochtigheid') != "unknown" and states('sensor.paradijsvogelplant_vochtigheid') != "unavailable" %}
{% if states('sensor.paradijsvogelplant_vochtigheid')| float(default=0) <= 15 %}
red
{% else %}
{% if states('sensor.paradijsvogelplant_vochtigheid')| float(default=0) >= 60 %}
red
{% else %}
green
{% endif %}
{% endif %}
{% endif %}
}
Good one… It can be grey for my part.
It actually solved the issue!!
I could not imagine that that would solve this warning. I expected it not to matter and that the function would resolve in no change without the ‘else’.
Could you elaborate on that if you know?
- type: button
icon: mdi:flower
entity: sensor.paradijsvogelplant_vochtigheid
name: pv plant
show_name: false
card_mod:
style: |
:host {
--card-mod-icon-color:
{% if states('sensor.paradijsvogelplant_vochtigheid') != "unknown" and states('sensor.paradijsvogelplant_vochtigheid') != "unavailable" %}
{% if states('sensor.paradijsvogelplant_vochtigheid')| float(default=0) <= 15 %}
red
{% else %}
{% if states('sensor.paradijsvogelplant_vochtigheid')| float(default=0) >= 60 %}
red
{% else %}
green
{% endif %}
{% endif %}
{% else %}
grey
{% endif %}
}