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 don’t know if this is a bug or a desired feature … In that case, how do I get the min_value
, max_value
, …?
Thank you.
2 Likes
nylund
(Nicklas Nylund)
December 12, 2021, 7:48pm
2
I have the same problem. Have read the breaking changes in this release but can’t find anything related to the statistics sensor.
1 Like
Thank you. I’ve just reported there.
nylund
(Nicklas Nylund)
December 13, 2021, 8:27am
5
Got mine working again. A change in how the statistics sensor works:
home-assistant:dev
← ThomDietrich:statistics_additional_characteristics
opened 12:21AM - 18 Nov 21 UTC
<!--
You are amazing! Thanks for contributing to our project!
Please, DO N… OT DELETE ANY TEXT from this template! (unless instructed).
-->
## Breaking change
Statistic characteristics are no longer available as state attributes, hence users will need to adapt their configuration by adding sensors exposing the wanted characteristics. Additional template sensors to expose attributes are not necessary anymore.
The following state attributes have been removed and are now available through the configuration parameter `state_characteristic`:
`sampling_size`, `count`, `mean`, `median`, `quantiles`, `standard_deviation`, `variance`, `total`, `min_value`, `max_value`, `min_age`, `max_age`, `change`, `average_change`, `change_rate`.
## Proposed change
<!--
Describe the big picture of your changes here to communicate to the
maintainers why we should accept this pull request. If it fixes a bug
or resolves a feature request, be sure to link to that issue in the
additional information section.
-->
Adds a few new values/attributes to the statistics sensor.
Statistic characteristics are no longer available as attributes, hence users will need to adapt their configuration.
**Attributes:**
* All characteristic attributes are removed, see the breaking change section for details
* Added `age_coverage_ratio`
* Added `buffer_usage_ratio`
* Added `source_value_valid`
**Characteristics:**
* Added `average_linear`
* Added `average_step`
* Added `average_timeless`
* Added `distance_absolute`
* Added `distance_95_percent_of_values`
* Added `distance_99_percent_of_values`
* Added `noisiness`
* Renamed `average_change` to `change_sample`
* Renamed `change_rate` to `change_second`
* Renamed `max_age` to `datetime_newest`
* Renamed `min_age` to `datetime_oldest`
* Renamed `max_value` to `value_max`
* Renamed `min_value` to `value_min`
* the mathematical results of old and renamed characteristics are unchanged.
All attributes and characteristics are documented in the [docu PR](https://github.com/home-assistant/home-assistant.io/pull/20347).
**Rationale for renaming:** Some old names (like `max_age`) were ambiguous. Also, as this is a breaking change, users will need to reconfigure their `statistics` sensors, look at documentation and build a new valid setup. A better opportunity to deal with this won't come up.
## Type of change
<!--
What type of change does your PR introduce to Home Assistant?
NOTE: Please, check only 1! box!
If your PR requires multiple boxes to be checked, you'll most likely need to
split it into multiple PRs. This makes things easier and faster to code review.
-->
- [ ] Dependency upgrade
- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New integration (thank you!)
- [x] New feature (which adds functionality to an existing integration)
- [x] Breaking change (fix/feature causing existing functionality to break)
- [ ] Code quality improvements to existing code or addition of tests
## Additional information
<!--
Details are important, and help maintainers processing your PR.
Please be sure to fill out additional details, if applicable.
-->
- This PR fixes or closes issue: fixes #
- This PR is related to issue:
- Link to documentation pull request: https://github.com/home-assistant/home-assistant.io/pull/20347
## Checklist
<!--
Put an `x` in the boxes that apply. You can also fill these out after
creating the PR. If you're unsure about any of them, don't hesitate to ask.
We're here to help! This is simply a reminder of what we are going to look
for before merging your code.
-->
- [x] The code change is tested and works locally.
- [x] Local tests pass. **Your PR cannot be merged unless tests pass**
- [x] There is no commented out code in this PR.
- [x] I have followed the [development checklist][dev-checklist]
- [x] The code has been formatted using Black (`black --fast homeassistant tests`)
- [x] Tests have been added to verify that the new code works.
If user exposed functionality or configuration variables are added/changed:
- [x] Documentation added/updated for [www.home-assistant.io][docs-repository]
If the code communicates with devices, web services, or third-party tools:
- [ ] The [manifest file][manifest-docs] has all fields filled out correctly.
Updated and included derived files by running: `python3 -m script.hassfest`.
- [ ] New or updated dependencies have been added to `requirements_all.txt`.
Updated by running `python3 -m script.gen_requirements_all`.
- [ ] For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
- [ ] Untested files have been added to `.coveragerc`.
The integration reached or maintains the following [Integration Quality Scale][quality-scale]:
<!--
The Integration Quality Scale scores an integration on the code quality
and user experience. Each level of the quality scale consists of a list
of requirements. We highly recommend getting your integration scored!
-->
- [ ] No score or internal
- [ ] 🥈 Silver
- [ ] 🥇 Gold
- [ ] 🏆 Platinum
<!--
This project is very active and we have a high turnover of pull requests.
Unfortunately, the number of incoming pull requests is higher than what our
reviewers can review and merge so there is a long backlog of pull requests
waiting for review. You can help here!
By reviewing another pull request, you will help raise the code quality of
that pull request and the final review will be faster. This way the general
pace of pull request reviews will go up and your wait time will go down.
When picking a pull request to review, try to choose one that hasn't yet
been reviewed.
Thanks for helping out!
-->
To help with the load of incoming pull requests:
- [ ] I have reviewed two other [open pull requests][prs] in this repository.
[prs]: https://github.com/home-assistant/core/pulls?q=is%3Aopen+is%3Apr+-author%3A%40me+-draft%3Atrue+-label%3Awaiting-for-upstream+sort%3Acreated-desc+review%3Anone
<!--
Thank you for contributing <3
Below, some useful links you could explore:
-->
[dev-checklist]: https://developers.home-assistant.io/docs/en/development_checklist.html
[manifest-docs]: https://developers.home-assistant.io/docs/en/creating_integration_manifest.html
[quality-scale]: https://developers.home-assistant.io/docs/en/next/integration_quality_scale_index.html
[docs-repository]: https://github.com/home-assistant/home-assistant.io
1 Like
Thank you!
I’ll change my sensors then. the problem is that in this way I need three times more sensors, as I use mean
, min_value
and max_value
from each sensor.
Themsk
(Dragoș Custură)
December 15, 2021, 1:38pm
7
Can you give an config example how to get the value_max from a sensor?
I realy do not understand how it works now or how to create new sensors for attributes that i have on statistics sensors.
Here it is:
sensor:
- platform: statistics
name: temperature_entrance_hall_max
entity_id: sensor.sonoff_a48000c2_temperature
state_characteristic: value_max
max_age:
hours: 24
sampling_size: 50
3 Likes
For whoever ends up here. All changes are covered in the documentation article.
retel
(Peter Norlander)
December 18, 2021, 11:06am
10
I have the same setup, where you able to fix this? Or did you set it up as three different sensors?
You now need three different sensors. One for each statistical value.
1 Like
retel
(Peter Norlander)
December 19, 2021, 6:50pm
12
Ok, thanks for letting me know.