Can I change the value for this sensor?

Hello all,
I have a sensor ( made by me ) that reports temperature, humidity and pressure via mqtt.
( For whom interessed is an ESP8266 with a BME280 and few lines of arduino code ).
Problem, as well known and documented, is that the temperature reported by this sensor is sligthly higher than the real temp.

I can compensate that in firmware but I would like to learn if I can do this in configuration.yaml as it could be useful fo other needs.

The sensor is defined like this:

mqtt:
  sensor:
    - name: "Temperatura Esterna"
      state_topic: "homeassistant/fuori_uno/temperature"
      unit_of_measurement: "C"
      device_class: temperature
      unique_id: temp_fuori_uno

In this way I can use it in dashboard and everything is fine.
I’ve tried to add this line:

      value_template: "{{ value - 1.5  }}"

but it does not work.
Is there a way to get the desired result ?

Thanks in advance

Pierluigi

Your value might actually be a string, so maybe using something like this might work:
"{{ (value | round(1)) - 1.5 }}"

value_template: "{{ value|float(0) - 1.5 }}"

Thanks all for the reply.
So I was almost there, but not really :slight_smile:

What’s the difference between the round(1) and the float(0)?

|round(1) rounds a number to one decimal place. This will not work on states as they are strings. States are always strings. Only attributes can have other object types.

|float(0) attempts to convert a string to a floating point number. If it can’t convert the string to a number it replaces it with the specified default value, zero in this case…

You should always define a default value for filters. If you don’t and the filter is not supplied the correct object type on start-up then the template will fail to load.

1 Like

Just to let everyone interessed know, I also had to add a format to the expression:

      value_template: "{{ '%02f' | format (value_json.power * ( 1.06 )) | round(2) }}"

due to what I’ve discovered ( here in forum ) be called “epsilon” error ( or something like this ).
Basically some times the value displayed was something like “348.6700000001” ( with lot of decimal instead of two ) and the "’%02f’ | format " fixed this.

Maybe can help someone other :slight_smile: