# 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"
``````

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"
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"
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.