aldihome
(Leon)
March 11, 2021, 2:14pm
1
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
Integration sensor is working great for my power meter, which provides updates every 10 seconds, and is always doing something.
It’s no good for my gas sensor though, which provides updates every 15 minutes, and goes for long periods at 0 kW. Let’s say my gas usage has been 0 from 00:00 to 06:00. At 06:00 it jumps to 10 kW. The integration sensor interprets that as a Trapezium/Triangle gradually increasing from 0kW@00:00 to 10kW@6:00, or 30 kWh. Actually though, I’ve used 0 kWh.
[Capture] .
C…
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
aldihome
(Leon)
March 11, 2021, 2:57pm
3
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
aldihome
(Leon)
March 12, 2021, 2:33pm
5
The solution that allows maximum precision and accuracy and definitively avoids all spikes problems is to add to each new point acquired a very small value that changes sign each time (say +0.0001 and -0.0001) thus forming an average square wave zero added to the acquired values which does not affect the integral or even the data itself and forces Home Assistant to fill in the blanks of data in the database that lead to the accuracy of the integral itself. Also, trapezoidal integration is more a…
This would be the solution, that keeps the values real
The solution that allows maximum precision and accuracy and definitively avoids all spikes problems is to add to each new point acquired a very small value that changes sign each time (say +0.0001 and -0.0001) thus forming an average square wave zero added to the acquired values which does not affect the integral or even the data itself and forces Home Assistant to fill in the blanks of data in the database that lead to the accuracy of the integral itself. Also, trapezoidal integration is more accurate than right or left rectangular integration, so it is always preferable when used with this solution. To implement this solution, a template sensor can be used which adds the value saved in a global variable to each new point acquired by the sensor and, each time, multiplies the variable by -1, thus changing its sign.
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