Template Sensor Issue: Weird Rounding and Output

Hey everyone, I’ve been trying to set up a template sensor to adjust my temperature readings, but I’m running into some strange issues. Let me walk you through what’s happening and see if anyone has some insights or solutions.

So, I’ve got an MQTT sensor pulling temperature data from an ESP8266 device. It’s set up like this:

yaml

  • platform: mqtt
    state_topic: “Temp1/Salon/Temperature”
    name: “salon_temperature”
    unit_of_measurement: “°C”
    expire_after: 180

This sensor is then used in a template sensor to apply an offset of -2.5°C. Here’s the template I’m using:

yaml
temperatura_salon:
friendly_name: “Salon”
unit_of_measurement: ‘°C’
value_template: >-
{{ states.sensor.salon_temperature.state | float - 2.5 }}

The issue is that the results I’m getting are all over the place. Instead of a clean, rounded value, I’m seeing numbers like 22.46500437445, which doesn’t make much sense for a temperature reading. To make things even weirder, when I use the template editor to preview the results, I get two different values: one that looks correct (ORG) and another that’s off by a decimal place (MOD). It’s like the template is doing something unexpected behind the scenes.

I’ve tried tweaking the rounding settings, but nothing seems to fix the issue. For example, when I add round(1) to the template, the value still doesn’t behave as expected. It’s almost like the template is introducing some kind of calculation error that I can’t pinpoint.

Has anyone else encountered something like this? I’m wondering if there’s a bug in the template sensor logic or if there’s a workaround I can try. Maybe there’s a different way to structure the template or a setting I’m missing that could smooth out these weird rounding issues.

If anyone has any suggestions or has faced a similar problem, I’d love to hear how you resolved it. Let’s see if we can crack this one together!

Cheers, [Your Name]