2015-05-11 build a humidity monitoring and dehumidifier device
In the summer the humidity level in our cellar is regularly too high. That means that the moisture in the air is condensing at the cool walls or on other cool things stored there. When moisture is condensing mold is formed easily. And this is of course undesirable.
Physically its easy what happens: the moisture in the room air is condensing on surfaces which are cooler than the dew point.
When the dew point temperature is getting dangerously in the region of the room temperature a dehumidifier should be turned on to get the air dry. A dehumidifier is a device with a ventilator and a much cooler surface inside. The warm and humid air is blown over the cooled surface, the water condenses inside and then is transferred to a water drain in the cellar.
So what I need is the following:
- 2x DHT-22 Temperature/Humidity Sensors (for room and wall temperature)
- 1x Raspberry Pi 2 B
- 1x Raspberry Pi Wireless USB Stick
- 1x Dehumidifier (WDH-520HB)
- 1x Programmable Power Strip with USB connection (Energenie EG-PM2)
In principle the check_hum.sh script is checking every minute if the dehumidifier should be started.
To read out the two DHT-T 22 sensors a one wire interface at the GPIO
port of the raspi is used. I wrote a c programm using the
wiringpi
library.
The power strip with the attached dehumidifier is then
controlled over USB
with sispmctl.
The data is then stored in a textfile like this:
2021.01.24 21:50:50 T 12.00 H 39.20 TD -1.44 TW 10.90 L_ON 0 2021.01.24 21:51:52 T 12.00 H 39.20 TD -1.44 TW 10.90 L_ON 0 2021.01.24 21:52:54 T 12.00 H 39.30 TD -1.40 TW 10.90 L_ON 0
- T ... temperature
- H ... humidity
- TD .. due point
- TW .. temperature at the wall
Its then possbile to print the data in a cgi-script like this:
#!/bin/sh
gnuplot plot.g > /var/www/cgi-bin/humidity.png
cat humidity.png
Where plot.g looks like this:
set terminal png size 1024,768
#stats 'humidity.dat'
set xdata time
set timefmt "%Y.%m.%d %H:%M:%S"
set format x "%d.%m.%Y"
set xrange [ time(0) - 7*86400 : time(0) + 10000 ] #x days back in time
set xtics nomirror rotate by -45
set bmargin 8
set grid xtics ytics
set key at screen 0.95,0.5
set style line 1 lt 2 lc rgb "red" lw 3
set title "Humidity and Temperature in the last 7 days\n ".strftime("%a %d.%b.%Y %H:%M", time(0) + 7200)
temp = `tail -n 1 humidity.dat | awk '{print $4}'`
hum = `tail -n 1 humidity.dat | awk '{print $6}'`
td = `tail -n 1 humidity.dat | awk '{print $8}'`
twall = `tail -n 1 humidity.dat | awk '{print $10-3.5}'`
#calc time and currrent money spend
on_minutes = `grep "L_ON 1" humidity.dat | wc -l`
on_hours = on_minutes/60.0
costs = on_hours*0.6*0.25
set label 5 sprintf("Time dehumidifier was on since start: %3.1f h, overall costs: %3.2f Euro", on_hours, costs) at screen 0.33, 0.915 font "Arial,10"
plot '< tail -n 20000 humidity.dat' u 1:6 t sprintf("%3.2f%% rel. humidity", hum) w l,\
'< tail -n 20000 humidity.dat' u 1:4 t sprintf("%3.2f °C room temp", temp) w l,\
'< tail -n 20000 humidity.dat' u 1:($10-3.5) t sprintf("%3.2f °C wall temp (-3.5°C offset)", twall) w l,\
'< tail -n 20000 humidity.dat' u 1:8 t sprintf("%3.2f °C dew point", td) w l,\
'< tail -n 20000 humidity.dat' u 1:($12==1?$12*55:50) t 'dehumidifier on/off' lc rgb "black" ps 1 w l
show label
The source code can be found here