Xiaomi Battery Level adjustment template | Need help with rounding

Wondering if I could get some template help please as my batteries levels from all of my Xiaomi gateway sensors report the battery level about 15% higher than actual I first insert then too low once onine for a few days. To try and get the value about right, I’m multiplying the reading by x

I have the following template which works but no amount of tweaking can get the rounding right. Anyone got any advice on that?

      smoke_sensor_entry_foyer_battery:
        friendly_name: Smoke Entry Foyer Battery
        value_template: "{% if states.binary_sensor.smoke_sensor_entry_foyer %}
            {{ states.binary_sensor.smoke_sensor_entry_foyer.attributes.battery_level | int * 1.13}}
          {% else %}
            unknown
          {% endif %}"
        unit_of_measurement: '%'
        device_class: battery

image

N.B The one that reports correctly (?) is not connected to my Xiaomi gateway but to deCONZ via a Conbee II. Sadly, these report 100% all of the time until it’s tool late and then only update once the batteries have nearly died.

      smoke_sensor_entry_foyer_battery:
        friendly_name: Smoke Entry Foyer Battery
        value_template: "{% if states.binary_sensor.smoke_sensor_entry_foyer %}
            {{ (states.binary_sensor.smoke_sensor_entry_foyer.attributes.battery_level | int * 1.13)| round(2) }}
          {% else %}
            unknown
          {% endif %}"
        unit_of_measurement: '%'
        device_class: battery

?

1 Like

Thank you! I was missing the () around the first statement calculation. I struggled to see what was different until I spotted your added brackets. Appreciate your help as always.

1 Like