Value_template error mqtt temperature and barometric pressure conversions

I’m trying to take the values from my weather station which are posting to my mosquitto broker. The temperature is in F and the pressure is in inHg. I’m trying to use a value_template to convert these to MKS units or C and kPa respectively. I have battled with this for hours and it is not making any sense to me. I am new to HA so I’m probably missing something obvious, but any help would be appreciated. Here is my sensors.yaml:

- platform: mqtt
  name: "SOC"
  state_topic: "weather/soc"
  unit_of_measurement: '%'

- platform: mqtt 
  name: "Indoor Temperature" 
  state_topic: "weather/inTempC"
  unit_of_measurement: '°C'

- platform: mqtt 
  name: "Indoor Humidity" 
  state_topic: "weather/inHumidity"
  unit_of_measurement: '%' 

- platform: mqtt
  name: "Outdoor Temperature"
  state_topic: "weather/outTemp"
  unit_of_measurement: '°F'

- platform: mqtt
  name: "Outdoor Humidity"
  state_topic: "weather/outHumidity"
  unit_of_measurement: '%'

- platform: mqtt
  name: "Barometric Pressure"
  state_topic: "weather/pressure"
  unit_of_measurement: 'kPa'

- platform: template
  sensors:
    outdoor_temperature_c:
      friendly_name: "Outdoor Temperature"
      unit_of_measurement: '°C'
      value_template: "{{ (states('sensor.outdoor_temperature') | (float-32)/1.8) | round(1) }}"
    barometric_pressure_kpa:
      friendly_name: "Barometric Pressure"
      unit_of_measurement: 'kPa'
      value_template: "{{ (states('sensor.barometric_pressure') | (float+0.83)*3.38639) | round(1) }}"

Also the rounding is not working as expected.

Read here


I’m using this to convert from F to C.
{{ ((states('sensor.temperature_f') | float -32) * 5 / 9) | round(1) }}

Thanks, I think I had some missing brackets or in the wrong place, but for some reason my rounding is not working at all. I’m still getting temperature and pressure with all the sensor’s sig digits. Aside from the value_template is there something that needs to be done in the sensor panel itself?

Show us the code of the template please.

This is in my sensors.yaml. Does it have to be in the configuration.yaml? I have a pointer to the sensors.yaml inside the configuration.yaml.

- platform: template
  sensors:
    outdoor_temperature_c:
      friendly_name: "Outdoor Temperature C"
      unit_of_measurement: '°C'
      value_template: "{{ ((states('sensor.outdoor_temperature') | float - 32) * 5 / 9) | round(1) }}"
    barometric_pressure_kpa:
      friendly_name: "Barometric Pressure kPa"
      unit_of_measurement: 'kPa'
      value_template: "{{ (states('sensor.barometric_pressure') | float + 0.83) * 3.38639 | round(1) }}"

If you read the link to templating that i posted, you will see that

The default priority of operators is that the filter ( | ) has priority over everything except brackets.

so in the barometric template you round 3.38639 to 2 decimal places and then multiply it with (states(‘sensor.barometric_pressure’) | float + 0.83)

{{ ((states('sensor.barometric_pressure') | float + 0.83) * 3.38639) | round(1) }}

should work.

The temperature template works for me.

One tip:
Copy and paste your templates {{ .... }} in Dev Tools/templates and you can play with them.

yeah I discovered that utility but for some reason it’s not rounding off at all?? Weird.