WTH is it not possible to define amount of decimals displayed for sensor readings in Lovelace

Architecture discussion is currently ongoing

1 Like

my first ever post here will be this :)) don’t know if it comes in handy but I use the code below with custom button card, for a Xiaomi Mi Plug (Zigbee) via the Xiaomi Lumi Gateway. Just try to switch ‘sensor…’ with whatever entity you’re using.

type: custom:button-card
hold_action:
action: more-info
color_type: card
icon: mdi:power-socket-eu
entity: switch.plug_lumi
name: Mi Plug
label: |
[[[
var pwr = Math.round(states[‘sensor.load_power_lumi’].state * 100) / 100;
return ‘’ + (pwr ? pwr : ‘0’) + ’ W’;
]]]
show_label: true
.
.
.

image

Later edit:

OR you can use the below code that enables you to use how many digits you like using toFixed(digits).

[[[
var pwr = (Math.round(states[‘sensor.load_power_lumi’].state * 100) / 100).toFixed(2);
return ‘’ + (pwr ? pwr : ‘0’) + ’ W’;
]]]

2 Likes