button-card: New display precision in entity is not taken into account...
Checklist
- I updated the card to the latest version available
- I cleared the cache of my browser
Describe the bug Today HA was updated to 2023.3 and with it a new function was added: possibility to set precision for entities. I have Xiaomi sensors which by default show humidity to one decimal (say: 49.1%) and temperature to two decimals (say: 23.13°C), which is too much. So i changed that into: humidity=zero decimals (=49%), temperature only one decimal (=23.1°C. In HA, “entities card” shows correctly 49% and 23.1°C, but in “custom:button-card” it still shows original values.
Version of the card Version: 3.4.2
To Reproduce This is the configuration I used:
type: custom:button-card
entity: sensor.greenhouse_23b8_humidity
show_state: true
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 7
- Comments: 37 (8 by maintainers)
Commits related to this issue
- fix: numerical states would not follow HA's format Fix #662 — committed to custom-cards/button-card by RomRider 3 years ago
- chore(release): 4.0.0-dev.9 [skip ci] ## [4.0.0-dev.9](https://github.com/custom-cards/button-card/compare/v4.0.0-dev.8...v4.0.0-dev.9) (2023-07-24) ### Bug Fixes * numerical states would not follo... — committed to custom-cards/button-card by semantic-release-bot 3 years ago
- chore(release): 4.0.0 [skip ci] ## [4.0.0](https://github.com/custom-cards/button-card/compare/v3.5.0...v4.0.0) (2023-07-29) ### ⚠ BREAKING CHANGES * **helpers:** If you were using any of the beta ... — committed to custom-cards/button-card by semantic-release-bot 3 years ago
- chore(release): 1.0.0 [skip ci] ## 1.0.0 (2025-05-20) ### ⚠ BREAKING CHANGES * **helpers:** If you were using any of the beta before `4.0.0-dev14`. Please replace all the calls to helper functions ... — committed to droans/button-card by semantic-release-bot 2 years ago
Fixed in next version
well, yes, I suppose that would be what I just suggested above: by default use the card options for those 3 parameters, unless set in the individual template. Imho, that would make a lot of sense, and be way simpler for the average button-card (user) if must be, under a localize object:
and then simply use
If no localize is set, use all defaults. if one needs individual options, use the format you have
with the undefined to skip one parameter
if you want 0 decimals, then yes, effect should be the same, but if you want the float number with some decimals, I’d stick with .toFixed() [but also: I’m not a programmer, so maybe there’s something I don’t know about those both ways 😉]
Thanks, i found one working command, too:
[Math.round(states['[[temperature]]'].state).toFixed(1) + '°C'](It’s template for decluttering card) i guess that “epsilon” was the culprit for non-working… I wonder what’s difference between two…@Protoncek I use this template with my pressure sensor:
state_display: "[[[ return parseFloat(states['sensor.4_out_pressure'].state).toFixed(0); ]]]"you can change number of decimals by changing 0 in toFixed() to other number .
A manual workaround is adding the following to the card configuration:
state_display: | [[[ return Math.round((Number(entity.state) + Number.EPSILON) * 100) / 100; ]]]