Precision for Entities in Home Assistant

Markus Brückner

Home Assistant has had the ability to set the display precision of sensor value for a while. If you click on the sensor entity (in the Settings > Devices & Services > Entities) and then the little cogwheel for the entity's settings, you'll see something like this:

The settings of an entity called "Akkuladung" (battery charge) in Home Assistant. The settings contain a drop-down for "Display precision"

Except if you don't…

The entity in question here is the charge of my home battery in percent. This is ingested via the MQTT integration with the following configuration:

mqtt:    
sensor:
- unique_id: "battery_charge"
name: "Battery Charge"
state_topic: "N/[...]/system/0/Dc/Battery/Soc"
value_template: "{{ value_json.value }}"

Problem now was, that I couldn't set the display precision because the drop-down simply wasn't available. Took me a while to figure out: apparently the UI only allows you to configure the precision, if the sensor has a unit_of_measurement value like this:

mqtt:    
sensor:
- unique_id: "battery_charge"
name: "Battery Charge"
state_topic: "N/[...]/system/0/Dc/Battery/Soc"
value_template: "{{ value_json.value }}"
unit_of_measurement: "%"

Suddenly the precision setting in the UI becomes available and my cards no longer display things like "95.4562334" instead of the more reasonable "95.5 %".