Problem Riemann, Utility meter

Hello everyone,
I try to describe my Problem in detail
I have an photovoltaik System which produce some kWh each day measured with shelly 1pm
I have an shelly em3 which measured my whole house
The Problem with the em3 is i Dont have a total returned value only Every Channel Single returned values.
So i calculate Channel 1 + Channel 2 + Channel 3 in watts
I have create an template sensor which only sums up/calculate the negative Values in Watts.

With riemann integration i convert that Watts in kWh.

The Riemann.kwh i use in Utility Meter for daily/monthly reset.

Yester first of month it worked well but today my returned value from Riemann is way higher than produce kWh.
I have a huge Spike in Riemann daily Utility Meter, but i Dont know why
Here come somepicture (only 1 because of New User)
Einspeisung W Positive is the template sensor
einspeisungkwh is the Riemann integration

Show the configuration for your summation template sensor.

The issue is that when the sensors become unavailable (like immediately after a restart) the |float filter will return 0 for the unknown state.

So your utility meter sensor goes from some value to zero then back to some value, doubling the utility meter reading.

This can be rectified by including a test for unknown in the template or by using the availability_template option.

First i create the sensor for whole power consumption it can be positive and negative

  - platform: template
    sensors:
      gesamtleistung_zaehler:
        friendly_name: "Gesamtleistung Zähler"
        value_template: "{{ (states('sensor.shellyem3_8caab56197d0_channel_a_power')|float + states('sensor.shellyem3_8caab56197d0_channel_b_power')|float + states('sensor.shellyem3_8caab56197d0_channel_c_power')|float)|round(3) }}"
        unit_of_measurement: "W"

After that i take only the negative values

  - platform: template
    sensors:
      einspeisung:
        friendly_name: "Einspeisung W Positiv"
        value_template: "{% if states('sensor.gesamtleistung_zaehler') | float < 0.0 %}{{ states('sensor.gesamtleistung_zaehler') | float * -1.0 }}{% else %}0.0{% endif %}"
        unit_of_measurement: "W"

Then i use riemann integration

  - platform: integration
    source: sensor.einspeisung
    name: einspeisungkwh
    unit_prefix: k
    round: 2

After that standard utility meter
That picture shows my problem very good.
Yesterday the red circle was right slowly increase when i produce more than i consume.
Today the blue circle jumps. After set to 0 it jumps even higher. After the last set to 0 i restartet home assistant and it stays where it should stay
123123123

This should prevent it happening again:

  - platform: template
    sensors:
      gesamtleistung_zaehler:
        friendly_name: "Gesamtleistung Zähler"
        value_template: "{{ (states('sensor.shellyem3_8caab56197d0_channel_a_power')|float + states('sensor.shellyem3_8caab56197d0_channel_b_power')|float + states('sensor.shellyem3_8caab56197d0_channel_c_power')|float)|round(3) }}"
        unit_of_measurement: "W"
        availability_template: "{{ 'unknown' not in [ states('sensor.shellyem3_8caab56197d0_channel_a_power'), states('sensor.shellyem3_8caab56197d0_channel_b_power'), states('sensor.shellyem3_8caab56197d0_channel_c_power') ] }}"
  - platform: template
    sensors:
      einspeisung:
        friendly_name: "Einspeisung W Positiv"
        value_template: "{% if states('sensor.gesamtleistung_zaehler') | float < 0.0 %}{{ states('sensor.gesamtleistung_zaehler') | float * -1.0 }}{% else %}0.0{% endif %}"
        unit_of_measurement: "W"
        availability_template: "{{ states('sensor.gesamtleistung_zaehler') != 'unknown' }}"

Thanks nice i will reply tomorrow if it fixed my problem

12345456

ok problem is not solved ^^ today i got again these jumps.
These is the riemann integration sensor

Good morning, I have the following problem with Riemann sensors on Energy dashboard. The solar system is measured by a sensor in Watts:

- platform: template
    sensors:
      produzione_fotovoltaico:
        unique_id: produzione_fotovoltaico
        friendly_name: Produzione fotovoltaico
        device_class: power
        unit_of_measurement: W
        value_template: "{{ state_attr('sensor.una_stato_sistema', '11') | int }}"

Then the Riemann is applied to convert from W to kWh:

  - name: Produzione fotovoltaico kWh
    platform: integration
    source: sensor.produzione_fotovoltaico
    unit_prefix: k
    round: 3
    method: left

And a statistic is created:

- name: Statistica produzione fotovoltaico
    platform: statistics
    entity_id: sensor.produzione_fotovoltaico_kwh

However each day, just at the first hour, I get a wrong integral sum:

prod_wrong

Then the rest of the day is OK. I think that when solar is not generating any power (sensor value always zero from 7pm to 8am next day) the integral sum is still “summing” something. On SQLite browser in fact, I get a big “jump” of the statistic value.

How to solve?
Thank you!

2 Likes

@bri87 Could you already fix it?

Any updates on this? I am observing the same issue with the Riemann Summation

I’ve the same issue.
With every sensor that stay for a “long” time at 0.
Sometimes I get a jump in the integration that never should happen.
I’ve workaround it by force update also the 0 every minute. But it should also work without it in my opinion.

Hi all,

are there any updates on this matter?

I am asking because it seems I have the same issue.
My hardware setup is pretty the same as mentioned in the initial thread. Shelly 1PM for a photovoltaic system and a Shelly EM3 for measuring the whole house.

I created a template sensor that shows me only positve values [W] when I take power from the grid.
[Image #1 - Sorry. Since I’m a new user I am not aloud to add more than one image into my threads]

In case the photovoltaic system produces enough power I will no longer take energy from the grid.
So the value of the template sensor becomes 0 W.
I marked these periods in the following image
[Image #2 - Sorry. Since I’m a new user I am not aloud to add more than one image into my threads]

To convert this template sensor from W to kWh I also use a Riemann sum sensor.
And the issue is now clearly visible. When the [W]-template sensor stays too long on a zero value the following integration value is wrong. This behavior creates a jump in the curve (see red marking).

The final result is a wrong energy dashboard.
[Image #3 - Sorry. Since I’m a new user I am not aloud to add more than one image into my threads]

Any ideas how to fix this?
Thanks!

Image#1

Image#2

Hello, I have a similar problem with calculation. Have you solved this problem?

Similar problem here, any suggestions or could it be a bug?

Unfortunately have the same issue, any updates?

Without showing your sensor definitions, it is impossible to tell what causes it for you. Two things generally go wrong causing this:

  • failing to use an availability template
  • not using left method for the Riemann sum integration.