Is there a way to force round(3) to always display 3 decimal places?

There are always EspHome and HA updates and every time it literally takes over an hour going through all my dashboard displays to reset the decimal places and some no longer have that option and it has to be done in YAML code using round(). But with round(3) the displayed data will shift around from 3 decimal places to 2 decimal places moving elements as the position affects other elements. Is there a way to force round(3) to constantly show to 3 decimal places even when a number, for example, goes from 3.222 to 3.220 ?

I ONLY have 3 battery packs with 16 battery cells each so ONLY 48 of these along with the many other data elements of my solar system:

01.&nbsp;&nbsp;&nbsp; {% if states('sensor.yambms_shunt_basen_bms_1_cell_voltage_max_cell_number') == '1' %} <font color="red">{{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_01') }} V</font> {% elif states('sensor.yambms_shunt_basen_bms_1_cell_voltage_min_cell_number') == '1' %} <font color="#3090C7">{{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_01') }} V</font> {% else %} {{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_01') }} V {% endif %} &nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp; {% if states('sensor.yambms_shunt_basen_bms_1_cell_balancing_bitmask')[0]=='1' %}<font color="yellow">bal. ON</font>{% else %}bal. off{% endif %}

By searching the forums I found I can replace my display base decimal point settings with YAML code like this:

<center>Max Cell : <b><font color=red>{{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_max') | upper }}</font>

becoming:
<center>Max Cell : <b><font color=red>{{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_max')|round(3) | upper }}</font>

Add a unique_id to these sensors, either in the template that created them or using customize. Customizing entities - Home Assistant

Then in the UI select the entity and set the precision displayed.

In the future there are better ways to display YAML…
How to format code or use the</> key in the post editor.

An old microcontroller display trick might also work here.
Add 0.0001 to your value before using round(3). This might also add trailing zero’s

Well I had a try and this seems to work

I used a sensor for the solar inverter voltage as trail.

{{ “%.3f” | format(states(‘sensor.growatt_3000mtl_voltage’) | float + 0.0001) }}

Result becomes: 245.600
It was 245.6

Show a screensot

I would like to do that but I have a few problems. First if i look at the code at the top of this thread I see that the dashboard used includes html tags. I have only a phone to use and I can only open HA remotly with the companion app. There I can only see the yaml of a dashboard page.

I can add this to developer tools - template page in the companion app and there i get the result that the thread ownersl describe but when changing it gives there it gives the desired output

{{ (states('sensor.growatt_3000mtl_voltage') | float + 0.00001) | round(3) }}

{{ "%.3f" | format(states('sensor.growatt_3000mtl_voltage') | float + 0.0001) }}

Hopefully the thread owner could test this by changing the code one of these places.

<center>Max Cell : <b><font color=red>

{{states('sensor.yambms_shunt_basen_bms_1_cell_voltage_max')|round(3) | upper }}

</font>


I tried changing:
states(‘sensor.yambms_shunt_basen_bms_1_battery_power’)|round(2)

to
states(‘sensor.yambms_shunt_basen_bms_1_battery_power’)|round(2)| float + 0.01

but every now and then the display goes from 52.65 V to 52.640029751 V
so it’s even worst than switching between “52.69 V” to “52.7 V”

Man, this all worked fine when I started using HA and then one of the HA devs decided to change how things were displayed and broke all the display defaults.

In the OverView dashboard which shows all of my device entities I can find the individual entities which need display decimal adjusting and adjust them but when I have a card with a grid of entities I can’t set the individual entity display resolution.

It seems any of my entities in my dashboards which are individual elements will let me set the UI decimal place displayed but that option is not available when I pack/group things together and only YAML code manipulates the displayed parts of the grid card.

Like I posted, it needs a unique_id in order to set the precision in the UI.

Ok, I’ll see about figuring out where to create the unique ID and see if it works.

And then the fun would begin figuring out how to generate unique IDs for a few dozen entities or getting the authors of my ESPHome devices to update their templates. This has been an ongoing problem since around the middle of the year so I’m guessing they’re not fond of the idea or else they would have done it long ago.

Here’s one grouping I’m dealing with:

But the main grouping will be all the BMS battery cells and I plan on adding another display of battery cells since I’ve added a balancing module which also displays battery cell voltages and line resistance so 16 of each per battery. ugh.

I looked at the page you referenced and the ID they are talking about is the sensor ID which are all unique already.

sensor.yambms_shunt_basen_bms_1_cell_voltage_01
sensor.yambms_shunt_basen_bms_1_cell_voltage_02
sensor.yambms_shunt_basen_bms_1_cell_voltage_03
sensor.yambms_shunt_basen_bms_2_cell_voltage_01
sensor.yambms_shunt_basen_bms_2_cell_voltage_02
sensor.yambms_shunt_basen_bms_2_cell_voltage_03
sensor.yambms_shunt_basen_bms_3_cell_voltage_01
sensor.yambms_shunt_basen_bms_3_cell_voltage_02
sensor.yambms_shunt_basen_bms_3_cell_voltage_03

So I don’t understand how changing the IDs would enable me to set a display resolution in a grid card showing a group of sensors which all have unique IDs already.

Here is one tab of my energy system display which somewhat shows all the grid card groups. It would be a shame to have to break everything into individual entities just to get the display precision stable and correct.

1 Like

The unique_id is an attribute that is used by the UI to allow control of things. I’m not talking about the entity_id or the device_id. unique_id is it’s own thing.
See my original post.

1 Like

I just noticed this link.
It may be something you can use instead
https://community.home-assistant.io/t/bms-battery-cells-card-visualize-individual-cell-voltages-of-battery-storage-systems-hacs/967641

1 Like

Thanks for the inspiration! :slight_smile: I will try to build a similar view for my card. Give me a few days. I think I can do it. Do you have a separate sensor for each cell to monitor cell balance? I think that will be my biggest problem.

My Dashboard shown started live as this one and I changed the sensor entries to match my system. The battery cells individual sensors.

As you can see, my battery cell voltage sensors do have Unique IDs because if they did not, according to the link you posted, there would not be the reset icon next to the entity ID field.

And I can set the display precision of individual bms battery cell voltage entities but when displayed in a grid card I can not and they all display with the full stored precision unless I add something to the YAML code for the grid card at each entity listing. Like that ‘round(3)’ mentioned in my first post. But rounding sucks because it does not fix the precision and the displays will shift all over the place as things like 3.399 become 3.4 instead of 3.400.

Set the precision right here:
image

That will only set it for that display element AND it gets lost after a system update which drives me nuts because I’ve done this a half dozen times but the last update also changed what the battery cells are showing. And that UI 'settings" icon is not available for the entire grid card and it will not set it for everywhere else the entity is displayed like in the image where I showed all 3 battery packs each with a grid card display showing 16 battery cell voltages out to like 16 digits.

and here’s the YAML code for that grid card, just the left half(8 battery cells):

<center>01.&nbsp;&nbsp;&nbsp; {% if states('sensor.yambms_shunt_basen_bms_1_cell_voltage_max_cell_number') == '1' %}  <font color="red">{{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_01') }} V</font> {% elif states('sensor.yambms_shunt_basen_bms_1_cell_voltage_min_cell_number') == '1' %}  <font color="#3090C7">{{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_01') }} V</font> {% else %} {{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_01') }} V {% endif %} &nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp; {% if states('sensor.yambms_shunt_basen_bms_1_cell_balancing_bitmask')[0]=='1' %}<font color="yellow">bal. ON</font>{% else %}bal. off{% endif %} <br> 02.&nbsp;&nbsp;&nbsp; {% if states('sensor.yambms_shunt_basen_bms_1_cell_voltage_max_cell_number') == '2' %}  <font color="red">{{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_02') }} V</font> {% elif states('sensor.yambms_shunt_basen_bms_1_cell_voltage_min_cell_number') == '2' %} <font color="#3090C7">{{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_02') }} V</font> {% else %} {{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_02') }} V {% endif %} &nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp; {% if states('sensor.yambms_shunt_basen_bms_1_cell_balancing_bitmask')[1]=='1' %}<font color="yellow">bal. ON</font>{% else %}bal. off{% endif %} <br> 03.&nbsp;&nbsp;&nbsp; {% if states('sensor.yambms_shunt_basen_bms_1_cell_voltage_max_cell_number') == '3' %}  <font color="red">{{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_03') }} V</font> {% elif states('sensor.yambms_shunt_basen_bms_1_cell_voltage_min_cell_number') == '3' %} <font color="#3090C7">{{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_03') }} V</font> {% else %} {{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_03') }} V {% endif %} &nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp; {% if states('sensor.yambms_shunt_basen_bms_1_cell_balancing_bitmask')[2]=='1' %}<font color="yellow">bal. ON</font>{% else %}bal. off{% endif %} <br> 04.&nbsp;&nbsp;&nbsp; {% if states('sensor.yambms_shunt_basen_bms_1_cell_voltage_max_cell_number') == '4' %}  <font color="red">{{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_04') }} V</font> {% elif states('sensor.yambms_shunt_basen_bms_1_cell_voltage_min_cell_number') == '4' %} <font color="#3090C7">{{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_04') }} V</font> {% else %} {{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_04') }} V {% endif %} &nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp; {% if states('sensor.yambms_shunt_basen_bms_1_cell_balancing_bitmask')[3]=='1' %}<font color="yellow">bal. ON</font>{% else %}bal. off{% endif %} <br> 05.&nbsp;&nbsp;&nbsp; {% if states('sensor.yambms_shunt_basen_bms_1_cell_voltage_max_cell_number') == '5' %}  <font color="red">{{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_05') }} V</font> {% elif states('sensor.yambms_shunt_basen_bms_1_cell_voltage_min_cell_number') == '5' %} <font color="#3090C7">{{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_05') }} V</font> {% else %} {{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_05') }} V {% endif %} &nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp; {% if states('sensor.yambms_shunt_basen_bms_1_cell_balancing_bitmask')[4]=='1' %}<font color="yellow">bal. ON</font>{% else %}bal. off{% endif %} <br> 06.&nbsp;&nbsp;&nbsp; {% if states('sensor.yambms_shunt_basen_bms_1_cell_voltage_max_cell_number') == '6' %}  <font color="red">{{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_06') }} V</font> {% elif states('sensor.yambms_shunt_basen_bms_1_cell_voltage_min_cell_number') == '6' %} <font color="#3090C7">{{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_06') }} V</font> {% else %} {{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_06') }} V {% endif %} &nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp; {% if states('sensor.yambms_shunt_basen_bms_1_cell_balancing_bitmask')[5]=='1' %}<font color="yellow">bal. ON</font>{% else %}bal. off{% endif %} <br> 07.&nbsp;&nbsp;&nbsp; {% if states('sensor.yambms_shunt_basen_bms_1_cell_voltage_max_cell_number') == '7' %}  <font color="red">{{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_07') }} V</font> {% elif states('sensor.yambms_shunt_basen_bms_1_cell_voltage_min_cell_number') == '7' %} <font color="#3090C7">{{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_07') }} V</font> {% else %} {{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_07') }} V {% endif %} &nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp; {% if states('sensor.yambms_shunt_basen_bms_1_cell_balancing_bitmask')[6]=='1' %}<font color="yellow">bal. ON</font>{% else %}bal. off{% endif %} <br> 08.&nbsp;&nbsp;&nbsp; {% if states('sensor.yambms_shunt_basen_bms_1_cell_voltage_max_cell_number') == '8' %}  <font color="red">{{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_08') }} V</font> {% elif states('sensor.yambms_shunt_basen_bms_1_cell_voltage_min_cell_number') == '8' %} <font color="#3090C7">{{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_08') }} V</font> {% else %} {{ states('sensor.yambms_shunt_basen_bms_1_cell_voltage_08') }} V {% endif %} &nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp; {% if states('sensor.yambms_shunt_basen_bms_1_cell_balancing_bitmask')[7]=='1' %}<font color="yellow">bal. ON</font>{% else %}bal. off{% endif %} <br></center>```

That precision is set and loaded from the config, you do not have to reset it dozens of times. You likely just need to refresh your page if you’re seeing different sig figs.

That would be great but I don’t find that factual. Here is my dashboard from Nov 25th 2025

and here it is now after updating my HA and I’ve done a hard reset of cache and data:

I checked a dozen of the cell entities and they all have the UI set for 3 decimal places.