Sonoff Integral creates some wack values

Hi All,

i have a strange issue specifically when it comes to to energy (kWh) on Sonoff devices using the Sonoff LAN plugin. I am hoping to get this one resolved.

I have 2 scenarios where the same thing seems to happen.

  1. Integral sensor calculating the energy over time.
  2. Feeding the raw data to InlfuxDB and use grafana to the integral.

From the Sensors.yaml i have the following

  • platform: integration
    name: “Geyser 63A Energy”
    unique_id: “geyser_energy”
    source: sensor.sonoff_1001d9505f_power
    unit_prefix: k
    round: 3

By looking at the image below, from 2 to 3 the Geyser consumed 18kWh, which is physically not possible, as this is a 3kW element

By looking at the raw graph of power over time, you can see the geyser ran just under an hour.

At this timeframe from Grafana this shows 2.97kWh, which is perfect.

Looking at the second time at 14:30 the geyser switched on you can see the the geyser power is incorrect again. But this time Grafanas data is also incorrect, this made me dig a little deeper.

In Grafana i have this query SELECT integral(“value”)/3600000 FROM “W” WHERE (“entity_id”::tag = ‘sonoff_1001d9505f_power’) AND $timeFilter GROUP BY time(1h) fill(0)

This works well with non Sonoff plugin devices. but looking below from grafana at grouped data, you can see at 14:00, there is an incorrect calculation.

Grouping this by minute. I saw something interesting.

  1. There is a big gap in data, there seem to be no data when the unit is in the off state.
  2. The moment the unit switches on, it is asif the integral just goes wack and sends wack data (14:30 : 9.60 kWh).

Is there a way around this, from grafana i even tried forcing the missing data as 0 values to try and force this, but no success.

This seems to be an integral issue with missing blocks of data or possibly a sonoff plugin that might be causing issues.

apologies for the lack of images, can only embed one 1 image

Honestly just skimmed your post, but it smells of using the default integration method of trapezoidal versus left sum.

at first i thought the same thing,
added a left method integral as way which is now under estimating.

Digging deep i found that when the sensor is in a off state it only periodically in hours send a 0, this seems to break the integrals.

I also trigger to force a 0 if the sensor is in a offstate

- trigger:
    - platform: time_pattern
      hours: "*"
      minutes: "*"
      seconds: 10
    - name: Geyser Power
      unit_of_measurement: W
      device_class: power
      state: >
        {% if is_state('sensor.sonoff_1001d9505f_power', 'off') %}
        {% endif %}

Now this works well, we have occasional load shedding which makes the sensor unavailable. How can this be addressed