I've tried adding the current_consumption of 2 localtuya plugs in your current_consumption sensor template but i keep getting "Template Loop" warnings in the logs.
"Logger: homeassistant.components.template.template_entity
Source: components/template/template_entity.py:216
Integration: Template (documentation, issues)
First occurred: 10:04:05 AM (2 occurrences)
Last logged: 10:04:38 AM
Template loop detected while processing event: <Event state_changed[L]: entity_id=sensor.current_consumption_home, old_state=<state sensor.current_consumption_home=275.9; unit_of_measurement=W, friendly_name=Current Consumption, icon=mdi:flash-outline @ 2021-07-22T10:04:03.421334+03:00>, new_state=<state sensor.current_consumption_home=277.3; unit_of_measurement=W, friendly_name=Current Consumption, icon=mdi:flash-outline @ 2021-07-22T10:04:04.331133+03:00>>, skipping template render for Template[{% set ns = namespace(states=[]) %} {% for s in states.sensor %} {% if (s.object_id.startswith('shelly_sh') or s.object_id.startswith('plug')) and s.object_id.endswith('_current_consumption') %} {% set ns.states = ns.states + [ s.state | float ] %} {% endif %} {% endfor %} {{ ns.states | sum | round(2) }}]"
I've tried multiple modifications of the code but didn't manage to get it to work. Any ideas?
platform: template
sensors:
current_consumption_home:
friendly_name: Current Consumption
unit_of_measurement: W
icon_template: mdi:flash-outline
value_template: >
{% set ns = namespace(states=[]) %}
{% for s in states.sensor %}
{% if (s.object_id.startswith('shelly_sh') or s.object_id.startswith('plug')) and s.object_id.endswith('_current_consumption') %}
{% set ns.states = ns.states + [ s.state | float ] %}
{% endif %}
{% endfor %}
{{ ns.states | sum | round(2) }}
or
platform: template
sensors:
current_consumption_home:
friendly_name: Current Consumption
unit_of_measurement: W
icon_template: mdi:flash-outline
value_template: >
{% set ns = namespace(states=[]) %}
{% for s in states.sensor %}
{% if s.object_id.startswith('shelly_sh') and s.object_id.endswith('_current_consumption') %}
{% set ns.states = ns.states + [ s.state | float ] %}
{% endif %}
{% endfor %}
{% for s in states.sensor %}
{% if s.object_id.startswith('plug') and s.object_id.endswith('_current_consumption') %}
{% set ns.states = ns.states + [ s.state | float ] %}
{% endif %}
{% endfor %}
{{ ns.states | sum | round(2) }}
I've tried adding the current_consumption of 2 localtuya plugs in your current_consumption sensor template but i keep getting "Template Loop" warnings in the logs.
"Logger: homeassistant.components.template.template_entity Source: components/template/template_entity.py:216 Integration: Template (documentation, issues) First occurred: 10:04:05 AM (2 occurrences) Last logged: 10:04:38 AM
Template loop detected while processing event: <Event state_changed[L]: entity_id=sensor.current_consumption_home, old_state=<state sensor.current_consumption_home=275.9; unit_of_measurement=W, friendly_name=Current Consumption, icon=mdi:flash-outline @ 2021-07-22T10:04:03.421334+03:00>, new_state=<state sensor.current_consumption_home=277.3; unit_of_measurement=W, friendly_name=Current Consumption, icon=mdi:flash-outline @ 2021-07-22T10:04:04.331133+03:00>>, skipping template render for Template[{% set ns = namespace(states=[]) %} {% for s in states.sensor %} {% if (s.object_id.startswith('shelly_sh') or s.object_id.startswith('plug')) and s.object_id.endswith('_current_consumption') %} {% set ns.states = ns.states + [ s.state | float ] %} {% endif %} {% endfor %} {{ ns.states | sum | round(2) }}]"
I've tried multiple modifications of the code but didn't manage to get it to work. Any ideas?
or
Thanks in advance.