Aggregate template showing down spikes

Hi,

I am tracking energy costs from a Shelly 3EM which gives me the power draw from three different channels (a, b, c). In order to track the total power draw I use this template code:

{{ states('sensor.3em_tn12_channel_a_power') | float | round(0) + states('sensor.3em_tn12_channel_b_power') | float | round(0) + states('sensor.3em_tn12_channel_c_power') | float | round(0)  }}

While the graphs of the seperate channels show no signs of downspikes, the aggregated sensor shows this:

Any idea what could cause this?

Thanks so much for your support!

Hi!

I have a similar issue but couldn’t track it down. Did you find a solution?

It seams to me that using this method helps the problem:

      state: >
         {% set x1 = states('sensor.x1') | int %}
         {% set x2 = states('sensor.x2') | int %}
         {{ x1 + x2 }}

@criuz can you confirm also for your issue?

It happens when the state is non numeric, the int makes the value 0. Add an availability template to remove the spikes.

1 Like

Thanks definitely solved my issue.
For others, please not that the legacy sensor format uses availability_template: while the new version just uses availability:, see Template - Home Assistant