Hello
I use a sensor to calculate my power consumption. to do this, I add all the devices together to get one value. This also works. Now it can be that a sensor delivers no value. Which is sporadically the case with the Shelly sockets. For this I would like to build an if statement around each sensor that checks the value first and if it does not exist returns a status of 0.0 or the value. For this I have thought of the following statement:
{% if (is_number(states('sensor.netzwerkfestplatte_power'))) and (states('sensor.netzwerkfestplatte_power') | float(0) > 0) %}
{{ (states('sensor.netzwerkfestplatte_power') | float(0) ) | round (3) }}
{% else %}
{{(states ('0.0') | float(0)) | round (3) }}
{% endif %} +
{% if (is_number(states('sensor.kaffemaschine_power'))) and (states('sensor.kaffemaschine_power') | float(0) > 0) %}
{{ (states('sensor.kaffemaschine_power') | float(0) ) | round (3) }}
{% else %}
{{(states ('0.0') | float(0)) | round (3) }}
{% endif %}
But I always get an error
Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: unexpected ‘%’) for dictionary value @ data[‘sensors’][‘power_total_consumption’][‘value_template’]. Got "{{\n {% if (is_number(states(‘sensor.netzwerkfestplatte_power’))) and (states(‘sensor.netzwerkfestplatte_power’) | float(0) > 0) %} \n {{ (states(‘sensor.netzwerkfestplatte_power’) | float(0) ) | round (3) }} \n {% else %} \n {{(states (‘0.0’) | float(0)) | round (3) }} \n {% endif %} | float(0) + \n {% if (is_number(states(‘sensor.kaffemaschine_power’))) and (states(‘sensor.kaffemaschine_power’) | float(0) > 0) %} \n {{ (states(‘sensor.kaffemaschine_power’) | float(0) ) | round… (See ?, line ?).
Is this combination of if statements not possible?
BR
Bastian