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 a year ago
- Reactions: 6
- 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 a year 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 a year 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 a year ago
Fixed in next version
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; ]]]