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

Most upvoted comments

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; ]]]