Value_template all entities based on their units

Good morning all,

I did some research but I could not find the answer so I am asking some help to the community.

I have a bit less than 100 sensors that returns different values in different units (°C, % himiidity, % use, Mb, Gb, days, lux…) and I would like to have them rounded. I am looking for something similar to the format option for entity card (https://www.home-assistant.io/lovelace/entities/#format) but applicable to more sensor types

For example, all my temperatures have 2 decimals which is way too precise for me, I would need one decimal only. I have the same issue with humidity displaying 2 decimals but only need the integer value.

Currently I am creating one template per sensor which I find not very optimal for several reasons

  • Quite time consuming to create a new template_value every time I have a new sensor
  • My database is growing fast (unless I exclude manually the sensors which is not good in terms of maintenance)
  • I have a huge list of unused entities which is hard to find the ones that are not used due to newly added entities

Is there a way to have all entities formatted following a certain rule based on criteria ? (example: all entities with the unit °C to be rounded to one decimal).

Thank you

1 Like

Depending on the type of sensor, you should be able to define for example

value_template: {{ value|round(1) }}

per sensor.

Hi jivesinger,

That is what I am doing now but for all the reason I mentioned above I am looking for a more easy to maintain solution.

You shouldn’t have to do this. Humidity and temperature are rounded on the UI in just about every card. Are you trying to round it on the backend for some reason? If so, why?

Hi @petro,

I am trying to change it at the frontend level (UI), I currently have a lot of xiaomi sensors and they are shown with 2 decimals. I do not need that much details. I know i am picky but I would like to have something clean with only the information I need.

1 Like

I also would like to see this functionality just for rounding in the front end.

I’m looking for this feature too. My suggestion is to use an optional formatting string that could be added after the entity, in a similar fashion to this: https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings
Example: format string(Optional, default: “0.#”)