Calculate (and display) absolute humidity calculated from sensor for relative humidity

Why use a macro here? Adds unnecessary code and you’re converting strings all over the place. Also, when you do this you can drop the entity_id list because the entities are inside the states() method which the parser looks for.

sensor:
  - platform: template
    sensors:
       hum_abs_3:
         value_template: >-
           {% set h, t = states('sensor.hum_3') | float, states('sensor.temp_3') %}
           {% if not h or t == 'unknown' -%}
             'unknown'
           {%- else %}
            {% set t = t | float %}
            {{ (h*6.112*2.1674*e**((t*17.67)/(t+243.5))/(t+273.15))|round(2) }}
           {% endif %}
         unit_of_measurement: 'g/m³'
         friendly_name: 'abs. humidity'
10 Likes