Dew Point/Temperature Sensor, my configuration.yaml

Hi,

Having had some troubles finding existing examples online, I thought to share my configuration.yaml to compute dew point/temperature according to the Arden Buck Equation.
According to Dew point - Wikipedia this equation provides high accuracy.
I verified my code against this online dew point calculator (Dew Point Calculator) and they do match. Pls note, sensor.temperature_X and sensor.humidtiy_Y should be ideally entities of the same device (e.g. Aquara Temperature/Humidity sensor) or they have to belong to devices located in the same room/zone.

sensor:
  - platform: template
    sensors:
      temp_dew_XY: 
        value_template: >-
          {% set T, RH = states('sensor.temperature_X'), states('sensor.humidity_Y') %}
          {% if not (T == 'unknown')  or (RH == 'unknown') %}
            'unknown'
          {%- else %}
            {% set T = T | float %}
            {% set RH = RH | float %}
            {% set a = 6.1121 | float %}
            {% set b = 18.678 | float %}
            {% set c = 257.14 | float %}
            {% set d = 234.5 | float %}
            {% set e = 2.71828 | float %}

            {% set P = a*e**((b-T/d)*(T/(c+T))) | float %}
            {% set gamma = log((RH / 100)*e**((b-T/d)*(T/(c+T)))) | float %}
            {% set dew_temp = ((c * gamma) / (b - gamma))|round(3) %}
            {{ dew_temp}}
          {% endif %}
        unit_of_measurement: "°C"
        friendly_name: "Dew Temperature"

Please, let me know in case of comments/questions/suggestions for improvements!

Cheers,
ilMitch

4 Likes

There’s a nice custom_component that calculates a lot more things without much code typing.

3 Likes

Cool! thx for the recommendation! I would love to be able to write that level of python code!

Thanks, this is very an interesting sensor. I changed the code to a template sensor:

template:
  - sensor:
    - name: dew temperature 
      state: >
        {% set T, RH = states('sensor.ecodan_room_temperature_zone_1'), states('sensor.comfoairq_inside_humidity') %}
        {% if (T == 'unknown')  or (RH == 'unknown') %}
          unknown
        {% else %}
          {% set T = T | float %}
          {% set RH = RH | float %}
          {% set a = 6.1121 | float %}
          {% set b = 18.678 | float %}
          {% set c = 257.14 | float %}
          {% set d = 234.5 | float %}
          {% set e = 2.71828 | float %}
          {% set P = a*e**((b-T/d)*(T/(c+T))) | float %}
          {% set gamma = log((RH / 100)*e**((b-T/d)*(T/(c+T)))) | float %}
          {% set dew_temp = ((c * gamma) / (b - gamma))|round(3) %}
          {{ dew_temp}}
        {% endif %}
      unit_of_measurement: "°C"
      unique_id: "20230306161301"
      icon: mdi:water-percent-alert
1 Like

Hi there.

I liked this, but needed dew point calculations for various rooms. Turns out, the new macros syntax is pretty neat to make multiple template sensors with a macro function.

Here’s how it works on my side.

Step 1: Create a new folder custom_templates/ in your configuration folder, if it doesn’t exist already.

Step 2: Create a new file custom_templates/macros.jinja:

{% macro calculate_dew_point(entity_temperature, entity_humidity) %}
  {% set T, RH = states(entity_temperature), states(entity_humidity) %}
  {% if (T == 'unknown') or (RH == 'unknown') %}
    unknown
  {% elif (T == 'unavailable') or (RH == 'unavailable') %}
    unavailable
  {% else %}
    {% set T = T | float %}
    {% set RH = RH | float %}
    {% set a = 6.1121 | float %}
    {% set b = 18.678 | float %}
    {% set c = 257.14 | float %}
    {% set d = 234.5 | float %}
    {% set e = 2.71828 | float %}
    {% set gamma = log((RH/100)*e**((b-T/d)*(T/(c+T)))) | float %}
    {% set dew_point = ((c * gamma) / (b - gamma)) | round(1) %}
    {{ dew_point }}
  {% endif %}
{% endmacro %}

Step 3: Create your template sensors like this:

template:
  - sensor:
    - name: "Kitchen - Dew Point"
      unique_id: kitchen_dewpoint
      unit_of_measurement: "°C"
      icon: mdi:water-percent-alert
      state: >
        {% from 'macros.jinja' import calculate_dew_point %}      
        {{ calculate_dew_point('sensor.kitchen_temperature', 'sensor.kitchen_humidity') }}

P.S.: The P formula from the original code got removed in step 2, as it wasn’t used for the dew point result.

5 Likes

Hey @ilMitch, thanks for the code. Is there any reason for choosing 3 digits for rounding the result? Shouldn’t 1 digit be good enough?

1 Like

can someone give me advise how to set it up? as a beginner?

Hi. My previous post from July 2023 explains it step-by-step.

1 Like

Just found your post. Worked a treat. Thanks. Just what i was looking to do.
AKE40 - Follow Hzz’s steps.
Use file editor to create the folder and file
Alter template instructions to add and check your sensor variables in developer tools / templates
Then copy the data into a create sensor template helper.
The State part is the most important
Mine was…note only change is sensor names.
For other rooms - other sensor names

This is working really well for me but I don’t need 3 decimal places so just changed the config from round(3) to round(1) and bingo :wink: