home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
74.06k stars 31.08k forks source link

Statistics broken with minimal sample_size in 2024.11.x #131679

Open mmiller7 opened 3 days ago

mmiller7 commented 3 days ago

The problem

Since 2024.11.0, the statistics platform seems broken with a sample_size of 2 set (which should compute on only the most recent 2 data-points). This worked correctly up thru 2024.10.4. The buffer usage always stays at zero.

Example code:

In this example, the source sensor is SNMP with update interval between 1 and 5 seconds.

sensor:

  - platform: statistics
    name: pfSense NIC WAN In Counter Change Second
    entity_id: sensor.pfsense_nic_wan_in_counter_raw
    state_characteristic: change_second
    sampling_size: 2
    max_age:
      minutes: 2
  - platform: statistics
    name: pfSense NIC WAN Out Counter Change Second
    entity_id: sensor.pfsense_nic_wan_out_counter_raw
    state_characteristic: change_second
    sampling_size: 2
    max_age:
      minutes: 2

Expected behavior: compute change between last 2 intervals, as long as there have been at least 2 samples within max_age

Actual behavior: sensor initializes without errors but remains "unknown" with buffer usage of zero.

Additional interesting notes: Setting sample_size to 3 makes it work.

What version of Home Assistant Core has the issue?

core-2024.11.3

What was the last working version of Home Assistant Core?

2024.10.4

What type of installation are you running?

Home Assistant OS

Integration causing the issue

statistics

Link to integration documentation on our website

https://www.home-assistant.io/integrations/statistics/

Diagnostics information

No response

Example YAML snippet

sensor:

  - platform: statistics
    name: pfSense NIC WAN In Counter Change Second
    entity_id: sensor.pfsense_nic_wan_in_counter_raw
    state_characteristic: change_second
    sampling_size: 2
    max_age:
      minutes: 2
  - platform: statistics
    name: pfSense NIC WAN Out Counter Change Second
    entity_id: sensor.pfsense_nic_wan_out_counter_raw
    state_characteristic: change_second
    sampling_size: 2
    max_age:
      minutes: 2

Anything in the logs that might be useful for us?

No errors in logs.  Sensor sets up correctly but never renders any data (shows every update with value "unknown" and last updated time reset with each input value update)

Additional information

Expected behavior: compute change between last 2 intervals, as long as there have been at least 2 samples within max_age

Actual behavior: sensor initializes without errors but remains "unknown" with buffer usage of zero.

Additional interesting notes: Setting sample_size to 3 makes it work.

Screenshot of sensor from previous working version: image

Screenshot of sensor after updating to 2024.11.x (all versions since 2024.11.0 seem affected) image

home-assistant[bot] commented 3 days ago

Hey there @thomdietrich, mind taking a look at this issue as it has been labeled with an integration (statistics) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `statistics` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign statistics` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


statistics documentation statistics source (message by IssueLinks)