Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 102659

Summation of individual sensors via sensor template not working

$
0
0

@markus78 wrote:

can anyone tell me what I am doing wrong? When I test the template via the template editor everything works. If I use it as a sensor template, it does not sum up correct my values. I do not know what I’m doing wrong. Does anyone have a tip?

The values are:

[0.0, 0.3, 0.85, 0.51, 0.48, 0.09, 1.18, 0.2, 0.6]

The result of my sensor is 1.12 instead of 4.21. When I test this via template editor I get the correct result back.

This is my sensor:

platform: template
sensors:
  house_energy_daily_consumption:
    friendly_name: 'Hausstromverbrauch pro Tag'
    unit_of_measurement: 'kwh'
    value_template: >
      {% set ns = namespace(states=[]) %}
      {% for s in states.sensor %}
        {% if s.object_id.endswith('_energy_daily') %}
          {% set ns.states = ns.states + [ s.state | float ] %}
        {% endif %}
      {% endfor %}
      {{ ns.states | sum | round(2) }}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 102659

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>