Template sensor: round(2) not working

How can I get the sensor to consistently round to two decimals? I presume my yaml is incorrect because it’s not working as intended.

template:
  - sensor:
      # Combine FSR foot sensors on master bed
      - name: "Foot FSR Output"
        unique_id: "foot_fsr_output" 
        state_class: measurement
        state: >-
          {{ ( states ('sensor.master_bed_top_foot_fsr') | float(0)
           + states ('sensor.master_bed_bottom_foot_fsr') | float(0) )
           / 2 | round(2) }}'
        unit_of_measurement: 'V'

 

fsr1


fsr2


fsr3


fsr4

It’s order of operations.

The way you are writing the template you are only rounding the integer 2 at the end.

If you want the whole result rounded then you need to enclose everything before the round in parentheses

Thank you.

1 Like