Rounding sensor output

Hi all,

I’m wondering if someone can explain the following.
I have multiple Hue Motion detectors around the house. I’ve also started monitoring their temperature readings to get an idea of the various room temperatures.

I’ve calibrated with a physical thermometer, to get a better idea of room temp, and then created another sensor with the offset accounted for. This has all gone well, and now I have temperatures close enough to actual. However, two of my sensors are returning excessive numbers following the decimal point. Eg. instead of reading 16.93 it is reading 16.9299999999999998.

It’s not a huge problem as such, I just want to know how to fix it, if that’s possible. I’ll include my code below. I’m operating on a RPi3 on HA version 0.101.3

# Raising Landing Temperature reading by 2 degrees to bring it inline with actual
      landing_temperature_calibrated:
        friendly_name: "Landing Temperature"
        unit_of_measurement: "°C"
        value_template: "{{ float(states('sensor.landing_sensor_temperature')) + 2 }}"
 value_template: "{{ ( states('sensor.landing_sensor_temperature')|float + 2 )|round(2) }}"

Will give you 2 decimal places. Adjust as you see fit.

1 Like

Perfect, I’ll give that a shot