How to round sensor value with percent?

Hello,

I would like to ask you for help with rounding the value of the sensor, which has as a unit of percentage.
For sensors with other units, rounding works, but not for this.

  - platform: template
    sensors:
      zustatek_vody_studna:
        value_template: "{{ (states('sensor.vyska_hladiny_studna') | float * 100) / 420 | round(0) }}"
        friendly_name: "Zůstatek vody"
        unit_of_measurement: "%"

Výstřižek

That is because you round 420.

  - platform: template
    sensors:
      zustatek_vody_studna:
        value_template: "{{ ((states('sensor.vyska_hladiny_studna') | float * 100) / 420) | round(0) }}"
        friendly_name: "Zůstatek vody"
        unit_of_measurement: "%"
1 Like

Great. Thank you for your quick help!