core: Problem with statistics sensors in core-2021.12.0

The problem

I’ve just updated to core-2021.12.0 and have found the statistics sensors have less attributes than before.

I have the next sensor:

sensor:
  - platform: statistics
    name: stats_temperature_salon
    entity_id: sensor.sonoff_a48000f31d_temperature
    max_age:
      hours: 24
    sampling_size: 50

In core-2021.11.5 it had the next attributes:

sampling_size: 50
count: 26
mean: 22.6
median: 22.7
quantiles:
  - 22.04
  - 22.7
  - 23.12
standard_deviation: 0.57
variance: 0.32
total: 587.67
min_value: 21.74
max_value: 23.39
min_age: '2021-12-11T13:01:09.658738+00:00'
max_age: '2021-12-12T12:09:57.390473+00:00'
change: -0.38
average_change: -0.02
change_rate: -0.0
unit_of_measurement: °C
friendly_name: stats_temperature_salon
icon: mdi:calculator

while in core-2021.12.0, the attributes are:

state_class: measurement
age_coverage_ratio: 0.97
buffer_usage_ratio: 0.54
source_value_valid: true
unit_of_measurement: °C
icon: mdi:calculator
friendly_name: stats_temperature_salon

I think it’s a bug.

Thank you.

What version of Home Assistant Core has the issue?

core-2021.12.0

What was the last working version of Home Assistant Core?

core-2021.11.5

What type of installation are you running?

Home Assistant OS

Integration causing the issue

statistics sensor

Link to integration documentation on our website

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

Example YAML snippet

sensor:
  - platform: statistics
    name: stats_temperature_salon
    entity_id: sensor.sonoff_a48000f31d_temperature
    max_age:
      hours: 24
    sampling_size: 50

Anything in the logs that might be useful for us?

No response

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 39 (14 by maintainers)

Most upvoted comments

Seems to be related to #59867 which is a breaking change, but unfortunately not noted on the release notes

@ThomDietrich Great news… I think best case is to configure which attributes user need in statistic sensor.

I think exponential and linear decreasing weights cover almost all use cases (can you think of an use case for triangular moving average?). All time-related sensors will be causal systems, so I don’t think a weighting function which gives more importance to a past sample than the last one, like triangular, has practical utility. If input signal has spatial instead of temporal nature, maybe.

In the linear weighting, the parameter needed is the slope of the line. I think that the best and easier for the end user way to define it is with the weight of the oldest sample, with 0 as default.

In the exponential weihting, the parameter needed is of course the base of the exponential. If you put a default value, it should be about 0,75. I’ve tested the exponencial (really a simple geometric weigths without taking into accound the time spacing), and for values below 0.5, the output is very similar to input. For higher values, the output is a softener and delayed version of input (softer with higher values). For values higher than 0.95, the output is a slow varying trend of the input.

For reference:

  • 0.2: output similar to input.
  • 0.4: output similar to input with softened peaks.
  • 0,75: output similar to 8-samples unweighted average.
  • 0,99: output similar to 60-samples unweighted average.

Hey all, the breaking change is now added to release notes: https://github.com/home-assistant/home-assistant.io/pull/20666/files Sorry for the confusion. The example given by @newlund is correct, but really, just check the documentation for all relevant details https://www.home-assistant.io/integrations/statistics/

The mean sensor works fine, but I’m getting “unknown” for change sensors. Just wondered whether there is a bug

@THE-AP05TLE I’m not sure I understand. Please post your config and what you would expect. All characteristics are systematically tested.