#Dewpoint Calculation
1 messages · Page 1 of 1 (latest)
A template sensor can do the calculation.
{% set T = states('sensor.temperature_in_celsius')|float(0) %}
{% set RH = states('sensor.humidity_in_percent')|float(0) %}
{% set a = 18.678|float %}
{% set b = 257.14|float %}
{% set c = 234.5|float %}
{% set gamma = log((RH / 100) * e ** ((a - T / c)*(T / (b + T))))|float %}
{{ ((b * gamma) / (a - gamma))|round(1) }}
For temperatures in °C
{% set T = (TF - 32) / 1.8 %}
{% set RH = states('sensor.humidity_in_percent')|float(0) %}
{% set a = 18.678|float %}
{% set b = 257.14|float %}
{% set c = 234.5|float %}
{% set gamma = log((RH / 100) * e ** ((a - T / c)*(T / (b + T))))|float %}
{% set D = ((b * gamma) / (a - gamma))|round(1) %}
{{ D * 1.8 + 32 }}
For Fahrenheit (quick and dirty conversion back and forth between C and F).
Was too lazy to re-do the full calculation for Fahrenheit.
Is there any addon already that will create these for me when the necessary entities are available?
i wonder what a, b and c are
Constants you don't want to know in detail 
However there are also HACS intergrations like the one code-in-progress linked or "Thermal Comfort" which can calculate dewpoints (and other stuff).
Thank you.
I had chatgpt clean up your code, hope you don't mind. 😄
# In configuration.yaml or sensors.yaml
template:
- sensor:
- name: "Dew Point"
unique_id: "dew_point_sensor"
unit_of_measurement: "°F"
state_class: measurement
device_class: temperature
state: >
{% set temp_fahrenheit = states('sensor.temperature_in_fahrenheit')|float(0) %}
{% set temp_celsius = (temp_fahrenheit - 32) / 1.8 %}
{% set relative_humidity = states('sensor.humidity_in_percent')|float(0) %}
{# Magnus-Tetens approximation constants #}
{% set magnus_constant_a = 18.678 %}
{% set magnus_constant_b = 257.14 %}
{% set magnus_constant_c = 234.5 %}
{# Calculate gamma #}
{% set gamma = log((relative_humidity / 100) * e ** ((magnus_constant_a - temp_celsius / magnus_constant_c) * (temp_celsius / (magnus_constant_b + temp_celsius)))) %}
{# Calculate dew point in Celsius #}
{% set dew_point_celsius = (magnus_constant_b * gamma) / (magnus_constant_a - gamma) %}
{# Convert dew point to Fahrenheit and round to 1 decimal place #}
{{ (dew_point_celsius * 1.8 + 32)|round(1) }}```
didn't test it yet, will fix if it's bad (in a couple of hours)
i do now. 🤣
template:
- sensor:
- name: "Dew Point Celsius"
unique_id: "dew_point_celsius_sensor"
unit_of_measurement: "°C"
state_class: measurement
device_class: temperature
state: >
{# Fetch temperature and humidity #}
{% set temperature_c = states('sensor.temperature_in_celsius')|float(0) %}
{% set humidity_percent = states('sensor.humidity_in_percent')|float(0) %}
{# Magnus-Tetens approximation constants #}
{% set a = 18.678 %}
{% set b = 257.14 %}
{% set c = 234.5 %}
{# Calculate gamma using the Magnus formula #}
{% set gamma = log((humidity_percent / 100) * exp((a * temperature_c) / (b + temperature_c))) %}
{# Calculate dew point in Celsius #}
{% set dew_point_c = (b * gamma) / (a - gamma) %}
{# Round the dew point to 1 decimal place #}
{{ dew_point_c|round(1) }}
i asked it to clean up more and do celcius only
I wonder, is there an "open windows" addon already?
i might create one if it doesn't as my first project
I compare the absolute humidity between inside and outside for a binary sensor to show when it is good to open windows.
dewpoint_outside < dewpoint_inside = open windows, right?
I compare the absolute humidity in g/m³. I want to open windows, when the outside air is dryer than inside. Otherwise the relative humidity wouldn't drop.