Integral of the power spiking, when turning on my Tuya smart plug

Hi i have a Tuya smart plug, that also reports me the power. I used localtuya to connect to it and this template to grab the current power consumption:

- platform: template
    sensors: 
      akku_current_consumption:
        friendly_name: "Akku W"
        unit_of_measurement: 'W'
        value_template: "{%if states.switch.akku.state %}{{ states.switch.akku.attributes.current_consumption }}{% endif %}"

But when trying to sum the used power as kwh with this integration:

And here is the relevant part of my configuration:

- platform: integration
    source: sensor.akku_current_consumption
    name: akku_kw
    unit_prefix: k
    round: 2

It spikes, every time i switch it on:

As you can see in the screenshot, the consumption of the plugged device are steady max of 500W, but somehow the integral jumps up once by 0.8kwh and the second time by 1.4 kwh in one second.

Here is my UI configuration:

- type: vertical-stack
        title: Akku
        cards:
          - entities:
              - entity: sensor.akku_current_consumption
            type: history-graph
            hours_to_show: 24
            refresh_interval: 0
          - entities:
              - entity: sensor.akku_kw
            type: history-graph
            hours_to_show: 240
            refresh_interval: 0
          - type: button
            tap_action:
              action: toggle
            entity: switch.akku
            icon_height: 32px

What am i doing wrong? Or is there a problem with the “integration” integration?
Also why is the integral like a step function and jumping and not steady?

The problem could be connected to

Did you gry the left method yet as suggested in the docs:

In case you have an appliance which produces spikey consumption (like an on/off electrical boiler) you should opt for the left method to get accurate readings.

1 Like

I am currently testing this, as i found the other topic just after posting. So far no spikes.

But as i understand, this version slightly underestimates the power consumption?

Maybe, I’m not so much up doing calculus right now :sweat_smile:

This would be the solution, that keeps the values real

Hey, sorry for bumping this post. Did you end up implementing the solution suggested here? I also have a couple of tuya smart plugs which are connected through localtuya, but I’m a total newbie when it comes to templating and would really appreciate it if you could share you implementation