How can I limit the display value of a sensor?

Hello, pretty new to Home Assistant. I would like to know how to limit my temperature displays to 1 or 2 decimal places. Thank you.

cards:
  - entity: climate.entryway_thermostat
    name: Thermostat
    type: thermostat
  - cards:
      - entity: sensor.bedroom_temperature
        name: Bedroom
        type: sensor
      - entity: sensor.hue_motion_sensor_1_temperature
        name: Kitchen
        type: sensor
    type: vertical-stack
type: horizontal-stack

You limit it in the integration definition not the Lovelace card.

1 Like

I believe you have to create a new template sensor to format to your liking (if you’re unable to format (per @tom_l’s comment above) in the integration itself.

1 Like

That will usually work but the correct way is shown by Phil here:

1 Like

Thank you, don’t know why search fu was unable to find those previous threads.

I experience this template workaround as non-intuitive.

A sensor stands for data, a card/badge stands for representation of that data to the end-user. I don’t want to limit the digits in the integration as you then lose accuracy.

The process is non-intuitive, as I must create a new (forked) sensor with the only purpose to represent the value on a card in lovelace. This gives me a bad user experience. For my solar panels, I now need to have two template sensors: one for the badge (zero digits) and one for a sensor card (1 digit). This means extra data in your database/list with all sorts of “postfix sensors” (e.g. sensor.solaredge_current_power, sensor.solaredge_current_power_0digits and sensor.solaredge_current_power_1digit). You could consider as database pollution, but at least increased maintenance of your data.
I don’t want to ignore that there are other use cases that justify the creation of a template sensor, but to my opinion it should be an option on the card to simply limit the number of digits.

It now works, but hope that in the future it would be possible to enhance this.

15 Likes

It is a feature that has been requested. You can vote for it here:

1 Like

Since March this is available via the UI: sensor display precision.