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
2 Likes

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.

8 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

1 Like

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:

Thanks for the code. I was using

This started throwing errors with core update 2025.1.0 SEE ISSUE HERE

Initially this macro was not working but I accidentally added the custom_templates/ folder into custom_components/ instead of the config/ folder

I named my sensors the same as my previous home-assistant-dewpoint sensors

Then commented out my previous configuration under

sensor:
  - platform: dewpoint
    sensors:

OLD SENSOR CONFIGURATION

sensor:
  # Sensors Dewpoint Temperature - HACS Home Assistant Dewpoint
  # - platform: dewpoint
    # sensors:
      # dewpoint_outside:
        # temperature: sensor.netatmo_devonport_tas_indoor_outdoor_temperature
        # rel_hum: sensor.netatmo_devonport_tas_indoor_outdoor_humidity
      # dewpoint_living_room:
        # temperature: sensor.air_conditioning_temperature
        # rel_hum: sensor.air_conditioning_humidity
      # dewpoint_downstairs:
        # temperature: sensor.air_conditioning_downstairs_temperature
        # rel_hum: sensor.air_conditioning_downstairs_humidity
      # dewpoint_airport:
        # temperature: sensor.devonport_airport_temp
        # rel_hum: sensor.devonport_airport_humidity
      # dewpoint_upstairs:
        # temperature: sensor.netatmo_devonport_tas_indoor_temperature
        # rel_hum: sensor.netatmo_devonport_tas_indoor_humidity

NEW SENSOR CONFIGURATION
I used the right click and Generate UUID At Cursor function in Studio Code Server to create new unique_id:'s
NOTE: this is under template: now not sensor: as previous configuation.

template:
  - sensor:
# Template Dew Point Sensors - Utilising custom_templates/macros.jinja
template:
  - sensor:
    - name: "dewpoint_outside"
      unique_id: 2fac14a6-affd-4985-88d6-67b3cff34e3f
      unit_of_measurement: "°C"
      icon: mdi:thermometer-water
      state: >
        {% from 'macros.jinja' import calculate_dew_point %}
        {{ calculate_dew_point('sensor.netatmo_devonport_tas_indoor_outdoor_temperature', 'sensor.netatmo_devonport_tas_indoor_outdoor_humidity') }}

    - name: "dewpoint_living_room"
      unique_id: c5e921de-47d2-4338-9158-8097911df43e
      unit_of_measurement: "°C"
      icon: mdi:thermometer-water
      state: >
        {% from 'macros.jinja' import calculate_dew_point %}
        {{ calculate_dew_point('sensor.air_conditioning_temperature', 'sensor.air_conditioning_humidity') }}

    - name: "dewpoint_downstairs"
      unique_id: b28b88fa-df92-446b-bc4a-1c49f1cf1443
      unit_of_measurement: "°C"
      icon: mdi:thermometer-water
      state: >
        {% from 'macros.jinja' import calculate_dew_point %}
        {{ calculate_dew_point('sensor.air_conditioning_downstairs_temperature', 'sensor.air_conditioning_downstairs_humidity') }}

    - name: "dewpoint_airport"
      unique_id: 28411b07-5c1b-47e6-bf1c-f7fc1f04cda2
      unit_of_measurement: "°C"
      icon: mdi:thermometer-water
      state: >
        {% from 'macros.jinja' import calculate_dew_point %}
        {{ calculate_dew_point('sensor.devonport_airport_temp', 'sensor.devonport_airport_humidity') }}

    - name: "dewpoint_upstairs"
      unique_id: a6b570a9-bef8-4c12-9855-2712285e2f75
      unit_of_measurement: "°C"
      icon: mdi:thermometer-water
      state: >
        {% from 'macros.jinja' import calculate_dew_point %}
        {{ calculate_dew_point('sensor.netatmo_devonport_tas_indoor_temperature', 'sensor.netatmo_devonport_tas_indoor_humidity') }}

Hi everyone!

I noticed some amazing discussions here around creating dew point calculations using code and custom setups. While those approaches are incredibly powerful and flexible, I wanted to share a simpler alternative for anyone looking to avoid coding and templates.

I’ve recently uploaded a Dew Point Integration for Home Assistant to GitHub. It’s available to install via HACS as a custom repertory, and everything is configured through the UI, so no YAML or custom template code is needed.

The integration calculates the dew point temperature using the Arden Buck equation, ensuring accurate results. It also supports multiple locations – you can easily create dew point sensors for different areas by adding more sensors via the UI.

If this sounds like something that could simplify your setup, feel free to check it out:

Of course, the template-based solutions are still fantastic for more advanced use cases, but if you’re looking for a plug-and-play option, this might be helpful.

1 Like

I wish I had of had this a few days ago.

I just installed it and it matches exactly what the above template is giving me. Even though the Arden Buck equation seems to be taking in more variables. ***Correction I am using the Arden Buck equation in the equation I used from this post, excluding the P.

Very easy to use and install.

It seems you can only load one dewpoint sensor, are you able to create multiple dew point sensors?

Already using template, but this simplifies the process. Well done.

1 Like

You can add more then one in the integration, just press add entry in the Dew Point integration page

@Stimo Ah ok. Maybe something to add in your docs. Great work btw.

1 Like

Sure thing, added a tip in the documentation

1 Like