Problem with statistics sensor after 2024.11.0 update

I’ve got some statistics sensors that give me a change between the last and current values, they are no longer working since the 2024.11.0 update (worked on 2024.10.4). I can see them show a value for a fraction of a second then always goes back to zero.

It seems like it is broken if I set the sample_size to a value of 2 (which is what I want for comparing just the past 2 values).

The input value is being updated once per second (which i can see in the states).

  - platform: statistics
    name: pfSense NIC WAN In Counter Change Second
    entity_id: sensor.pfsense_nic_wan_in_counter_raw
    #Since scan_interval=1 we already are only doing per second
    state_characteristic: change
    sampling_size: 2
    max_age:
      minutes: 1
  - platform: statistics
    name: pfSense NIC WAN Out Counter Change Second
    entity_id: sensor.pfsense_nic_wan_out_counter_raw
    #Since scan_interval=1 we already are only doing per second
    state_characteristic: change
    sampling_size: 2
    max_age:
      minutes: 1

If I set sample_size to anything >2 it works again but I really want to only consider the change between the newest 2 values.

The old 2024.10.4 would work:

1 Like

Also experiencing strange issues with the statistics sensors since 2024.11.0 update, the logic definitely has changed.

In my case, I use a statistics sensor to track the delta change of the past 15 minutes for an entity whose state updates exactly every 1 min, no more no less (also verified in states).

Until 2024.10.4, a sampling_size of 16 or a max_age of 15 mins were just equivalent: I could set the sensor with the sampling_size alone, the max_age alone, or both configured, and get the same result.

But since 2024.11.0, using a sampling_size of 16 (alone or combined with max_age) gives a different result, smaller, which seems to cover a period +/- 2 to 4 mins instead of 15.

So the conclusion is that new samplings now get added to the internal buffer of the statistics sensor more frequently, even when the entity has not been updated (duplicating the same value). Not sure if it is intentional. But we cannot assume anymore that 2 sampling means 2 subsequent states.

The workaround for me was to set max_age only, without sampling_size limitation.