A better mold sensor

The core mold sensor:

uses an outdoor temperature and a calibration factor to determine the temperature of a cold spot that may be subject to condensation. This method does not work well at all.

I placed a temperature sensor outdoors and on my cold aluminium framed single glazed window. I used a template sensor to calculate the calibration factor as per the documentation. I saw widely varying values from 2 to over 15 over a number of days.

I believe the issue is thermal inertia of the window during fast outdoor temperature changes.

As I now had an actual temperature sensor on the cold object I wanted to edit the source of this sensor and develop a local variant that uses a sensor rather than calculating the critical temperature for use in the calculation.

Unfortunately I failed. I’m just not that good at Python. (Someone competent please create a PR for this!)

So instead I developed this template sensor. Instead of using

  • indoor temperature and humidity sensors
  • outdoor temperature sensor and a calibration factor

it uses

  • indoor temperature and humidity sensors
  • a temperature sensor on the cold object

There are two places in the template (state and availability) where you must enter your own entity_ids for these three sensors:

  - sensor:
      - name: Lounge Condensation Chance
        unit_of_measurement: "%"
        state_class: measurement # only include this if you want long term statistics
        state: >
          {# ### CHANGE THESE THREE SENSORS ### #}
          {% set room_temp = states('sensor.lounge_room_temperature')|float(0) %}
          {% set room_humid = states('sensor.lounge_room_humidity')|float(0) %}
          {% set crit_temp = states('sensor.lounge_window_temperature')|float(0) %}
          {# ### -------------------------- ### #}
          {% set MK2 = 17.62 %}
          {% set MK3 = 243.12 %}
          {% set alpha = MK2 * room_temp / ( MK3 + room_temp ) %}
          {% set beta = MK2 * MK3 / ( MK3 + room_temp ) %}
          {% set dewpt = MK3 * ( alpha + log( room_humid / 100 ) ) / ( beta - log( room_humid / 100 ) ) %}
          {% set alpha_crit = MK2 * crit_temp / ( MK3 + crit_temp ) %}
          {% set beta_crit = MK2 * MK3 / ( MK3 + crit_temp) %}
          {% set crit_humidity = e ** ( ( dewpt * beta_crit - MK3 * alpha_crit) / ( dewpt + MK3) ) * 100 %}
          {{ ([0,crit_humidity,100]|sort)[1] }}
        availability: >
          {# ### CHANGE THESE THREE SENSORS ### #}
          {{  has_value('sensor.lounge_room_temperature') and
              has_value('sensor.lounge_room_humidity') and
              has_value('sensor.lounge_window_temperature') }}
        icon: >
          {% if this.state|float(0) == 0 %}
          {% elif this.state|float(0) > 70 %}
          {% else %}
          {% endif %}

How well does it work?

I don’t know yet. It is summer here and too hot for condensation to form, but it should be better than the core sensor.

It operates the same way, sensor > 70% → condensation may form on the object being monitored.


From reading the core mold sensor documentation I always had my doubts. You proved me right that I didn’t have much faith in the cold surface temp estimation.

My first thought would be to use outside temp with indoor dew point, assuming the cold surface would get close to outdoor temp. But what you’re doing seems better. I think you’re right that the cold surface is too slow to respond to outside changes. I will try your sensor, but I’ll need to get my hands on an extra temperature sensor.

My first use case would probably be to try to limit the cost on a dehumidifier that is in my shed now because it is way too damp (had a leakage there recently). The dehumidifier can be pretty power hungry and this seems a better way to control it than on humidity level alone. The hygrostat inside it is pretty far off underestimating the humidity. Thanks for this!

One thing strikes me though, why not just one temp/hum sensor in the coldest spot? If the temperature reaches dew point, risk gets higher? I always assumed the original sensor was trying to estimate dew point at the cold spot using indoor temperature/humidity and outdoor temp.

If I have the extra sensor I can try to correlate with the acrual dew point measurement at the cold spot.

I just copied the mold sensor source to a template sensor and made some changes.

The way it originally worked assumed there was no way to measure the temperature of the cold object and estimated this from the outdoor temp and calibration factor. People are much more likely to only have room and outdoor sensors.

The original sensor calculates the indoor dewpoint (from the room temp and humidity) then calculates the condensation chance using this dewpoint and the dewpoint at the cold object, assuming the air around it is the same as in the rest of the room. It also has attributes for the room dew point and critical temp.

My template does essentially the same thing but substitutes an actual temperature sensor for the estimated temperature.

Reasons for not using just one temp and humidity sensor:

  1. It’s difficult to find a dual sensor (temp and humidity) that is suitable for surface contact temperature measurement. A DS18B20 makes a great surface temperature sensor but has no humidity.

  2. I already have room temp and humidity sensors. And surface contact sensors.

  3. It was easy just to adapt the source of the existing sensor.

You could indeed just calculate the dewpoint of the cold object using two sensors (temp of the object and humidity of air around it). But you would still need a third sensor to measure the room air temperature to give you some indication if you were approaching the cold object dewpoint.

I’m using the sensor for the same thing. I run my room dehumidifiers if it is likely that condensation will form on my single glazed windows. I found that I needed to fudge the calibration factor (the default of 2 is pretty good) and only listen to what this sensor is saying if the outdoor temp falls below 10°C. This worked in 90% of cases. There was a very small amount of condensation only on a couple of days last winter.

Hopefully with this improved sensor I will not need the 10°C condition in my automations and I will have closer to 100% reduction in condensation.