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!
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 %}
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