Limit Significant Figures

Is there a way to limit the decimal places reported on sensors or in Home Assistant overall?

The since last boot and CPU temperature are good examples where a limit would be helpful.

2 Likes

With a template, use the round(0) function:

{{ states.sensor.my_cpu_sensor.state | round(0) }}

For 96 °F

{{ states.sensor.my_cpu_sensor.state | round(1) }}

For 96.4 °F

I have found that some sensor values will always display as a float, so even with round(0) you sometimes end up with .0 after the value, but that is not the case for all sensors.

2 Likes

You’ll need something like this:

{{ "%01d"|format(states.sensor.my_cpu_sensor.state|int) }}
{{ "%02d"|format(states.sensor.my_cpu_sensor.state|int) }}

For 1 or 2 decimals :wink:

PS: It annoyed the hell out of my lazy self when I saw this, I can only guess the good reasons behind it but it helped me getting much deeper into templating and so much sensors, oh joy!

cc @silvrr

2 Likes

This answer worked for me. Cheers