Add blog post about sensor rounding (#1649)

* Add blog post about sensor rounding

* Adjust language
This commit is contained in:
Erik Montnemery 2023-01-25 08:56:11 +01:00 committed by GitHub
parent c1972a3d13
commit 5273e7f3eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,23 @@
---
author: Erik Montnemery
authorURL: https://github.com/emontnemery
title: "Sensor entity can now do rounding of numerical values"
---
`SensorEntity` can now do rounding of a numerical `native_value` when it's converted to the sensor state. This is implemented as a part of [core PR #86074](https://github.com/home-assistant/core/pull/86074). The rounding is opt-in by integrations setting the `native_precision` property. It is recommended that this property is set by integrations because it ensures the number of decimals is reasonable also after unit conversion.
A summary of the changes, copied from the PR description:
- By default, no rounding is done
- Integrations can influence the state precision by setting a new property `native_precision`
- The state precision is influenced by unit conversion
- Converting from a smaller to a larger unit increases the display precision
- Converting from a larger to a smaller unit decreases the display precision if the integration has set `native_precision`
- Minimum precision when converting from a larger to a smaller unit is 0, i.e. there's no rounding to tens, hundreds etc.
- User can override the display precision from the frontend
- There's no minimum precision, i.e. rounding to tens, hundreds, etc. is possible by setting a negative precision
- Integrations are encouraged to drop rounding for display and instead set property `native_precision`
- Trailing zeroes are added to the sensor state's string representation to match the precision if:
- The precision is set by user
- The `native_precision` property is not `None`
- Unit conversion is done