I have so many templates only for rounding sensor values. Why do sensor entities have no option to set decimals? Advantages:
no annoying doublicates
less templates ( i do not like templates)
less recorder storage ( less decimals, less changes)
mrand
(Marc Randolph)
October 1, 2022, 4:28pm
2
If we had limited votes, this would definitely get one from me.
Templates are powerful - but IMO, also over-relied on in HA. There must be a better way if the goal is to improve usability.
4 Likes
tom_l
October 1, 2022, 4:30pm
3
Lets keep the original idea simple so it has a chance of being actioned. If you can come up with specific examples please create your own WTH.
Dashboard entities could definitely do with a precision option. +1
5 Likes
allan
(Allan)
October 1, 2022, 4:44pm
4
This one feature would remove the need for around half of my templates so a+1 from me
2 Likes
Thanks for this WTH. Now I don’t have to submit this one myself
Definitely a vote
1 Like
timmo001
(Aidan Timson (Timmo))
October 2, 2022, 8:14pm
6
Yeah I’ve came across the need to round values recently, on the dashboard though, as I’m a fan of precision.
Should maybe have an option in the card config as well as at entity level
2 Likes
Most likely there are arguments for both the backend and the frontend. I have for example various light and humidity sensors (eg. 45553.56lx or 54.54%) where backend would make more sense, as the decimals are absolutely useless.
Sidenote:
In my case allowing value templates for knx and modbus would do the backend job as well.
farmio
(Matthias Alphart)
October 3, 2022, 7:03am
8
For information, here the link to the same topic of WTH2020, 11th most voted topic:
In Lovelace it is currently not possible to define the amount of decimals displayed for sensors. If you want to define / limit the amount of decimals displayed you will need to use the code editor -> use a template.
2 Likes
I have lots of battery sensors and it drives me up the wall that some have a decimal and some don’t. I’d love to get rid of all decimals as it really doesn’t add any value on a battery percentage. There is at least one card that allows changing the “precision” (as it is called in the card) - meaning the number of decimals, but I believe it should be native functionality.
careingemt
(Careingemt)
October 18, 2022, 9:56pm
11
@aruffell … wondering if you can help me accomplish this
Hello,
I have configured lights in lovelace dashboard using custom button-card. I can change the light or light group color by accessing color-wheel with more-info command.
Is there is any way to assign one button-card with single color and clicking on button shall change the color of the light/light-group.
In action->call-service/service is not changing the color of the light.
Any help is highly appreciated. thanks
e-raser
November 14, 2022, 11:01pm
13
That’s great news. That will hopefully finally make my GUI more readable. Too much useless precision kills readability sometimes. Played around with CSS a lot, no chance. Looking forward to see this arriving
TrilIiard
(Tril Iiard)
January 19, 2023, 5:56pm
14
Seconds year this has to come now.
The first PR appeared Thank you Home Assistant Developers
home-assistant:dev
← home-assistant:sensor_customize_precision
opened 09:17AM - 17 Jan 23 UTC
<!--
You are amazing! Thanks for contributing to our project!
Please, DO N… OT DELETE ANY TEXT from this template! (unless instructed).
-->
## 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.
-->
Allow customizing sensor state precision:
- Default precision is 2 decimal digits, if the sensor's state is a numerical string, a `float` or a `Decimal`
- Some combinations of device class and unit have different display precisions
- Integrations can influence the display precision by setting a new property `native_precision`
- If the sensor state is an `int`, the default precision is 0 decimal digits
- The display 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
- 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 to setting a negative precision
- Integrations are encouraged to drop rounding for display and instead set property `native_precision`
- Conversion of a number to string does no longer
TODO:
- Documentation update
- Frontend update
## 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!)
- [ ] New feature (which adds functionality to an existing integration)
- [ ] Deprecation (breaking change to happen in the future)
- [ ] 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:
## 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.
-->
- [ ] The code change is tested and works locally.
- [ ] Local tests pass. **Your PR cannot be merged unless tests pass**
- [ ] There is no commented out code in this PR.
- [ ] I have followed the [development checklist][dev-checklist]
- [ ] The code has been formatted using Black (`black --fast homeassistant tests`)
- [ ] Tests have been added to verify that the new code works.
If user exposed functionality or configuration variables are added/changed:
- [ ] 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`.
<!--
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+-status%3Afailure
<!--
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
6 Likes
jnsears
(Nick Sears)
January 20, 2023, 11:09am
16
That’s nice, but it looks like that’s happening at the sensor level, so you’ll have to toss away the extra digits when the data comes in (if I understand the code correctly).
I really want to keep the extra precision on the backend for later analysis and calculations.
It must just be a difference in style or something but personally as a developer, I would never have even thought of rounding the numbers anywhere but within the frontend at the time of display. Not sure why the HA devs seem opposed to rounding on the frontend?
1 Like
jnsears
(Nick Sears)
January 20, 2023, 1:24pm
17
I just found this. It seems like it’s going to be a pretty good workaround, at least for the entities card. Hopefully I can find something similar for gauges.
The same here. The digit rounding setting should be tied to the UI only to be useful.
Rounding will be supported with 2023.2. Thank you very much, I already did beta testing and it works perfectly. It can be defined on both integration and entitiy level, but I think this approach is fine. All my templates could be removed!
Edit: It had been removed in the last second, what a pity… Hopefully next month…
4 Likes
Sorry for the maybe “dumb” question, but how can I do the check in an integration code if HA 2023.2 is installed and hence do not round the value only in that case?
EDIT: I mean, how to check that HA is newer enough to support the native_precision
property, otherwise return the custom-rounded string?