Absolute humidity for a humidor

I’ve set up a humidor with a d1mini and esphome. It works great but I’d like to improve efficiency so here’s my problem: Cigars should be kept at 70% at 70 F, but if temperature change the relative humidity will change too. By example if the temp is 72 then the humidity should fall to 65% to prevent mold in the humidor.

Below is my working code without temperature compensation.Would appreciate your help:

esphome:
  name: humidor

esp8266:
  board: d1_mini_lite

# Enable logging        79% et 76 % l'hiver à 21 degrés   /     73 et 70% à 23 degrés l'été
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "7+2yQ8N0O+2yn27dW9/jexA3I5SeOZmMW0B5hFLFQjM="

ota:
  password: "7592708290e37053aefa61e87bc08ac1"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
 

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Humidor Fallback Hotspot"
    password: "L2mkODdAsJlq"

captive_portal:

i2c:
  sda: 4
  scl: 5
  scan: true
  id: bus_a

switch:
  - platform: gpio
    pin: GPIO0
    name: "humidificateur_cigares"  
    id: humidificateur

sensor:
  - platform: htu21d
    temperature:
      name: "Température humidor"
      id: temp
    humidity:
      name: "Humidité humidor"
      id: hum
      on_value_range:
        - above: 73.0
          then:
            - switch.turn_off: humidificateur
        - below: 70.0
          then:
            - switch.turn_on: humidificateur
    update_interval: 5s
font:
  - file: "Arial.ttf"
    id: arialfont
    size: 16

binary_sensor:
  - platform: gpio
    pin:
      number: D7 
      mode:
        input: true
        pullup: true
    id: bouton
    name: bouton    

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x32"
    reset_pin: D5
    address: 0x3C
    lambda: |-
     if (id(bouton).state) {

     } else {
     it.printf(0, 0, id(arialfont), "Humidite: %.1f", id(hum).state);
     it.printf(0, 16, id(arialfont), "Temperature: %.1f", id(temp).state);       
     }

How is this accomplished? dehumidifier? What is the expected action when the temp rises?

The humidity is always higher inside the humidor than outside. So the humidifier should stop working until 65% is reached. With this code the humidifier works about 10 seconds 6-7 times a day. Also, the temperature slows down or rise up very slowly.

Might be worth checking out the Thermal Comfort custom integration:

It can calculate Absolute Humidity (among a ton of other things), which I use for several automations.

1 Like

This is not true. Absolute humidity stays same if you change temperature. Relative humidity RH changes with temperature.
So if you have sealed container with air RH=70% and T=70F and you raise temperature to 72F your relative humidity becomes 66% while absolute humidity remains same 12.9g/m3. Your sensor gives you relative humidity and temperature.

But what would you like to adjust? Cigars are usually kept at RH 68-72%

1 Like

You are right. Absolute humidity stays the same forgive me. In fact my sensor (htu21d) reads RH (or am I wrong again?) and the temperature here in Canada fluctuates between winter and summer due to the fact that we have to switch from heating to air conditionning in the summer. All I want is a code that follows these changes in temperature and adjust the humidity in consequence.

Regards.

Have you considered using your sensors in conjunction with a generic hygrostat template? I use these everywhere where I control humidity, it gives a nice UI (similar to thermostats) and then instead of trying to control humidity via code, I just tell the virtual humidifier which already has the smarts to turn on/off humidifiers as needed.

2 Likes

I don’t want to rewire all that stuff. I tought it would be easier to change the code like; if the temp is 72 than set humidifier to 67%, if 73 than set it to 63% and so on…

I know nothing about cigars, but if you want a constant absolute humidity (which I’d find hard to believe) you can use the Thermal Comfort integration to convert RH to AH (or alternatively you could do the calculation yourself):

Both AH and RH can be used with a generic thermostat. But that is on HA, not on the ESP. There you have:

It mentions temperatures, but there’s no reason it can’t be used with humidity. Doing it on the ESP means it will keep working even if HA is down.

Thermal Comfort also works from HA, but the formula to convert temp+hum to absolute humidity can also be found online should you need it.

ESPHome has a Absolute Humidity sensor to calculate AH.

1 Like

I believe that you want to do opposite. You shouldn’t look for constant absolute humidity! That would cause condensation, mold etc. You should keep constant RH near to 70% independently from temperature changes.

And RH is what your sensor gives, so your code got very simple :wink:


I begin to get a little confused…

I think these is only recommended rh/t (not matching) min max zone for ok cigar storage.
Anyway, absolute humidity is just a parameter to do calculations, there is no element in nature that follows that anyhow. For example, grain storage in silos, mold growth in houses, hardwood flooring, cannabis growing… whatever, is related to RH. It’s the % of actual water vapor in air compared to max possible water vapor in air. 100% would be full condensation, so pure liquid water. Nature doesn’t do calculations or coding.

“if the temp is 72 than set humidifier to 67%, if 73 than set it to 63% and so on…”
Try that towards lower temperatures and you will see…

Trust me, I’m an engineer, I like cigars and I come from country colder than yours. :wink:

:sweat_smile: Dindn’l like cigars …?

1 Like

I didn’t know it existed, I think it’s the best solution in my case. With the help from bme280 environment example in the cookbook I’m in business. Thanks !

SHT30 sensors may be better for humidity.

1 Like

And SHT40 even better…

And SHT45 best :rofl:

1 Like

Thank you everybody for your help and for your sense of humour :wink: you made a very happy cigar aficionado.