# Integration sensor wrong / inaccurate

Can you elaborate why left (or right) seems to not “jump” upwards in the graph, while trapezoidal does (or seems)?

Well its probably coming from the average.

You have to realize that home assistant suppresses ‘same’ states. So take a look at simulated state changes in home assistant. This is essentially an hour of nothing, 15 minutes of something, then nothing for an unforseen duration.

Heres what our state changes look like.

state change time state
1 0 0
2 3600 3000
3 4500 0

Putting that through the equation…

area = ((old + new) * elapsed) / 2
added value = area / (unit_prefix * unit_time)

where:

var description
old old state
new new state
elapsed time between state collection
unit_prefix configured via unit_prefix, where k = 1000
unit_time configured via unit_time, where h = 3600

we end up with the following amount added for each state change tick

change trap left right
1 -> 2 1.5 0.0 3.0
2 -> 3 0.375 0.75 0.0

Now if we extend the time where there is no watts being drawn between state change 1 and 2…

state change time state
1 0 0
2 10800 3000
3 11700 0
change trap left right
1 -> 2 4.5 0.0 9.0
2 -> 3 0.375 0.75 0.0

as you can see, trap doesn’t have the large spikes. Left and right do.

In the end, these all are probably inaccurate for your situation. But the calculation is doing it’s job. All in all, its definitely meant for curves and not flat peaks like you have. Or use left, not right.

I suggest you move to

Utility meter needs an energy sensor, not a power sensor. I.e. the output of the integration sensor.

So it’s a 3kW electric water heater ?
Not quite sure why it’s sometimes 3kW and sometimes 2.9kW.
Is there a controller to modulate this or do you live outside a major conurbation (city/urban area) so your voltage sometimes sits down; to drop your consumption ?
That’s down to 216v - quite a drop !

Though 207v 206.8v is permitted

Ah ok,

So then @Valentino_Stillhardt, i would stick with ‘left’. Based on the math, its my opinion that it fits your setup the best.

But I think that’s what he’s got. I think it’s actually a 3000 Ws (instantaneous) reading.

But I’m completely unfamiliar with the (utility meter) component so…

It depends on what the OP can get out of the stats, but maybe petro is right

No his original boiler sensor is in W (power). He is using the integration sensor to calculate Wh (energy). Which it looks like he is already feeding to the utility meter to get a daily reading.

But it’s a 3kW heater, the reading is 3,000 so it’s a 3,000 Ws reading to be integrated over the period and divided by 3,600 to convert ‘whatever’ into kWh
What have I missed ?

It is not 3000Ws energy. It is 3000W instantaneous power.

Just because the scan_rate is 3 sec does not convert the unit from W to Ws. It just means the reading updates every 3 sec. Set the scan rate to 10 sec and it will still read 3000W, just less often.

This is a power sensor not an energy sensor. Integrating the power sensor over time gets you energy, which is what Valentino is having trouble with.

Yes but ‘if’ it was every second it would be a constantly updated W reading giving a Ws value
Instead it updates every 3 sec and will change according to the current power consumption.
So it’s safe to ‘assume’ that it’s valid for the other 2 seconds as well.
Though an instantaneous reading is power, it is also a reading of energy, a Ws, therefore 1/3600 th of a Why can’t we (integrate and divide by 3600) or (divide by 3600 and integrate) to get kWh ?
The above is correct and all the dimensions work out this ‘should’ be doable.
Usually the integration is done in the meter but ‘maybe’ this can be done via stats ?

Basically I’m agreeing, aren’t I ?

Yes but ‘if’ it was every second it would be a constantly updated W reading giving a Ws value

No. It would still be instantaneous power read every second, measured in W.

It is not a reading of energy.

To get that you have to integrate power with respect to time.

Do the calculations balance the units of measurement (dimensions) and you’ll see the the equations work out as stated.

I’m not arguing about the conversion of Ws to kWh.

The sensor reads in W. NOT Ws. Reading a power sensor every second does not make it an energy sensor.

Yes it does.
Which bit about it being a 3 kW electric heater escapes you in this calculation ?
How many Watts do we read - 3,000
What happens when we sumate (or integrate) this over 1 hour (or 3600 seconds)?
And then divide it by 3600 to convert it to kWh.?
We get 3 kWh
Oooooh what about that for a coincidence

Any instantaneous reading can be interpreted a ‘second’ reading eg volt second (but what’s the point?)
But amp second can be converted to couloms and that to capacitor charge characteristics

How do you think that energy meters do it.?

That only works if you assume the load is constant.

Which - looking at the graph in the first post - it is not. There is some variation.

Guess it depends on how accurate Valentino is happy with.

The OP has not given us much in the way of data to reverse-engineer his values
We have assumed the 3kW presumably based on a device plate.
I have assumed he’s in Continental Europe because of his name
Thus I have guessed that his nominal supply voltage is 220v
Mine is supposed to be 230v +10%/-6% but instead it’s 254v (and very stiff) So miles off.
The 3kW is just the plate reading, it actually depends on the levels of nickel, chromium and iron in the wire (with any contaminates). Also how the guy on the drawing machine monitored the wire diameter (a Monday or a Friday)
But assuming his normal voltage is 220v with a 3kW element then we can calculate the current
From that we calculate the resistance, from that we can calculate the voltage drop to give 2900W instead of 3000W so we know it (the voltage) is within his tolerance and rural supplies droop under heavy load (not stiff) this is reflected in his readings.
So if I can monitor the power and the time the switch is on (and nothing in the above prevents me) then I can calculate energy and do it in kWh.
Your contention that it may not be accurate is true if the power drops half a second after the last reading, so I miss the power reduction to 2.9kW (very trivial) or worse, the switch turns off -… -…
But as long as I’m counting seconds on: against instantaneous W, then that too is trivial.
Admittedly if there is no ‘switch’ and its a thermostat built into the heater, then the only ‘integration’ that can be performed is on the 3 sec update of the power meter, and if the switch is off for a portion of that 3 secs, it would produce a value I would not rely on. But the do you need accuracy or just a general indication.
All said and done this does not allow ‘me’ to solve the issue, just prove that there is sufficient information for someone who can do the integration, to do so.

Edit: regarding the accuracy issue. Having observed the power readings on my fibaro light switches I see that they report the arithmetic mean of their sample time. So assuming the same of the device valantino is using, then accuracy should actually be quite good.

I really appreciate the attention all of you gave! Some more information which might be lacking:

It can very well be due to voltage, good observation…

It’s not very stable…

For those who asked: It’s an electric heater with a CT clamp on, like this one below:

The device measures in Watts. Not Ws or Wh, just instantaneous W usage. It “reads” the clamp sensor every 3 seconds in order not to miss any major spike or something which could, in long term, influence in the calculation.

The heater/boiler turns on and off by itself, having an simple internal temp sensor (which I don’t have access to). I just measure the current flowing through and want an estimate of the day/month. But I can’t believe that from one day to another it spiked to 90kWh and had almost no use.

Pretty sure that’s coming from the approximated integration calculation. If you look at my post, it will show you where it’s coming from. I.E. The large durations prior to a state change are adding a huge bias. As I stated before, switching to ‘left’ with your relatively square output from your watt device should get you a much better/ more accurate result.

1 Like

I am testing with “left” and it seems to be better than the default “trapezoidal” one. Instead of spikes, it climbs on usage, which it probably also should.

This seems like it matches 3kW.

1 Like