Statistics sensor not accurate

Hi all

I have a DSMR Slimme Meter which reports the total electricity used.
I have created a statistics sensor to show the usage of the past 24h:

- platform: statistics
  unique_id: "KWH_1D"
  name: "KWH used 1 day"
  entity_id: sensor.electricity_meter_energy_consumption_total
  state_characteristic: change
  max_age:
    hours: 24
  sampling_size: 1440

Sometimes it works great, sometimes it shows a value way too low.
I have another power meter that measures my Panasonic heatpump (which I read using an esp connected via modbus), which I have a similar statistics sensor for, and that doesn’t seem to fail in the same way.

It doesn’t seem that the DSMR readings have “dropouts”.

What to do?

Thanks.

Use the Utility meter instead.

Thanks Tom, but is that actually the solution?
I mean; there must be something wrong (most likely that I’m doing something the wrong way), since it bounces between the right amount and the “way off” amount? But then again - it works with my other meter :thinking:

Check the state history of the sensor you are pulling the data from - does it intermittently go unavailable or unknown?

I’m not quite sure how to check state history, except to just read the history graph, which seems complete all the way from yesterday at 9pm till now.

I think that’s as good as you can do with statistics sensors. I can view my graph over a longer period of time (this is two weeks) and see gaps. There are no gaps on your history graph?

I don’t have any power measuring sensors in my own instance I can test with - all my statistics sensors do regularly go up and down so I can’t replicate the behaviour exactly.

This is my energy meter the last 24h:

I have even looked at it one hour at a time the last 24 hours (to zoom in :smiley:), and I see no gaps.

Sorry malbom, I’m all out of suggestions for this one.

If this sensor was defined in YAML, maybe try a duplicate one in the UI and see if that behaves as you expect, but past that, I can’t offer anything else, sorry!

Yes.

So no reliable option to show the last 24h?

increase your sample size for the statistics sensor. it’s 24 hours or 1440 samples. If you have over 1440 samples, it’s not going to use all 24 hours of samples.

Or use utility meter, which is designed to handle this type of calculation.

Okay, so if I just remove sample_size it should take 24 hours, if possible?

No, sample size is required. Calculate out the number of times your sensor updates in a given 24 hour period. Then double it. The max 24 hours will always be honored.

Thanks @petro, it seems to do the trick.
I think I will spend some time setting up the “Energy” area.