24h Average sensor incorrect?

Hello all,

I’m experiencing something weird.
Recently, I hacked an IKEA PM2.5 sensor by adding an ESP8266 and added it to HA via ESPHome.
So far so good. It works as expected.

Now, I tried to add a 24h average sensor for it. I installed Average Sensor from HACS and added the sensor to my HA config.yaml.
It came up and seems to work fine, but then I noticed this: During the time I was away from home, the sensor value went down to 10. Average was 70. The average should be dropping hard, but strangely enough, it stays sortoff stable. And then hours later, it starts dropping off hard, while the primary sensor value has remained relatively constant all that time.

Am I overseeing something? Or misunderstanding the use of the ‘Average Sensor’?
Thanks!



Anyone? After running it for a while I see it was not a fluke. It consistently doesn’t seem to average correctly.

Sensor value is a stable 6 for hours. And average stays stable (even rising slightly) @ 70…

Could it have something to do with the fact that HA does not register new sensor values if they are the same as the previous one?

You could try asking the integration developer here:

I think the problem is that when the value doesn’t change compared to the previous value, HA does not register it. And so, the average sensor also doesn’t register it.
So when the sensor value is stable @ 10ug/m3 for a couple hours, the average sensor only gets 1 value. So 5 hours of 10ug/m3 is being treated equally to 5 seconds of changing value.

I will ask about it on the integration page. Thanks.

Why are you using a custom integration to do this when statistics integration is built in and arguably better?

Unless something has changed recently, I disagree.

The core integration does not take into account the time the state exists, just the number of state changes. The third party one does take time into account.

e.g. say you had a sensor that was 1.0 all day except for one state change to 0.0, the core integration gives this an average of 0.5, the third part one gives 0.999…

haha, that’s why I said arguably

it’s the cover your ass phrase :slight_smile:

1 Like

Also, statistics was completely reworked. It may do what you want now. Check out the new state_characteristics

Yeah I’m aware of that, hence my arse covering phrase :slight_smile:

I haven’t look at them, however there’s 3 average methods now. I would assume state_characteristic: average_step is what OP would want to use.

I think average_timeless was the original method.

Yeah it does indeed appear to no longer have the issue if you use either average_linear or average_step.

Nice.