Truncating value of template sensors to configuration.yml

I added these sensors and it works great!

# Calculates some values
template:
  - sensor:
      - name: "Daily COP heat energy"
        state: "{{ (states('sensor.hp_dailyheatingenergyproduced')|float / states('sensor.hp_dailyheatingenergyconsumed') |float )}}"
        unit_of_measurement: COP
        device_class: energy

  - sensor:
      - name: "Daily COP hot water energy"
        state: "{{ (states('sensor.hp_dhw_out')|float / states('sensor.hp_dhw_in') |float )}}"
        unit_of_measurement: COP
        device_class: energy

But, when the calculation is done above all decimals are shown. How can I truncate the value to only 2 decimals?

|round(2)

Apply this to the whole equation using parentheses. Otherwise you will only round the last state in the denominator.

1 Like