Template Sensor returns string insted of double

Hello,

I try to calculate the abs humidity in my bathrooms, cause I will try to open the window until the abs humidity is on a level that the rel. humidity is in between 40 to 60 % after heating the room again.

but I do get a String as response instead of a numeric value. This is the code I have integrated in my sensor.yaml file:

  - platform: template
    sensors:
      hum_abs_bad2og:
        value_template: >-
          {% set h, t = states('sensor.bad_2_og_humiditiy') | float, states('sensor.bad_2_og_temperature' | float ) %}
          {{ (h*6.112*2.1674*e**((t*17.67)/(t+243.5))/(t+273.15))|round(2) }}
        unit_of_measurement: 'g/m³'
        friendly_name: 'abs. humidity 2.OG'

correct

incorrect

Thanks, but this doesn’t solved the problem, but I think I have a general problem here.
even if i chnage the code to write a 1 as value, my Sensor has no value any more:

  - platform: template
    sensors:
      hum_abs_bad1og:
        value_template: <
          1
        unit_of_measurement: 'g/m³'
        friendly_name: 'abs. humidity 1.OG'

image

Should be

value_template: >

Thanks,

I’m really new to YAML.

I decided to use the Thermal Controll Plugin to calculate the absolute humidity.

But Thank you for supporting me.