A humidity sensor/switch for your air humidifier with a Raspberry Pi
Summary: Get a TX433N transmitter and a DHT11 humidity sensor, stick them into your Arduino's GPIO (GPIO17 and GPIO4 respectively), and connect your humidifier to a Brennenstuhl or Elro remote power switch.
Set the remote power switch to "A 1". Then check out this repository jeorgen/pi-control-mains-switches to your Raspberry Pi and run the humi.py script with "sudo python humi.py". Read on for more details.
Problem
The winter is getting mighty cold and with that comes dry indoor air. I have a Bionaire air humidifier that is manually switched on or off.
The previous one I had, had a built in continuous dial for when it should switch on and off depending on the humidity, but this one hasn't. So I want to connect a hygrostat (like a thermostat but for humidity) to it, giving a nice even humidity indoors, whether the winter temperature outside is +4 degrees centigrade or -15 degrees.
Solution
Power control
I do not want to mess with constructing things myself with relays and such things when running high voltage (240V mains). In fact I do not want to have anything to do with 240V that I have soldered or installed in any other way. Luckily there is a plethora of ready-made remote power switches that you can get at any DIY store. They come with a remote control and can go for €10 for three switches and one remote in a package.
The TX433N transmitter works at the same frequency as many of these switches, and the control.py script in jeorgen/pi-control-mains-switches should work with Brennenstuhl (tested with model RCS 1000) and Elro switches and probably many other brands of switches.
The TX433N transmitter needs to get connected to to 5V, ground and a GPIO pin in the GPIO socket on the Raspberry Pi (GPIO17 in my setup, see GPIO: Models A+, B+ and Raspberry Pi 2 - Raspberry Pi Documentation). The TX433N also runs with 3.3V but the Pi does not supply much current for those 3.3V pins (<50mA). So use a 5V pin instead.
I set my Brennenstuhl RCS 1000 to be switch number 1, listening to the A channel in its DIP switch configuration. So all DIPs at 0, except DIP 1 and 6. Of course you can change the python script for other settings.
Humidity sensing
The DHT 11 is a cheap humidity sensor whose most endearing quality is that I can buy it over the counter in the local Kjell.com stores here. I would have preferred its more expensive sibling the DHT22. As with the TX433N, plug it in to the 5V connection in the GPIO slot. Then use GPIO 4 for the signal (GPIO: Models A+, B+ and Raspberry Pi 2 - Raspberry Pi Documentation).
Here is some more documentation on pinouts, levels and example scripts that I nicked code from: DHT11 Humidity & Temperature Sensor Module | UUGear
The first DHT 11 I bough refused to leave the 20-21% range which was clearly wrong, so I exchanged it and the new one believes it to be about 35% relative humidity which is still wrong but I can work with that. You may want to adjust the humidity settings in the humi.py script to your liking.
If you want to know more about humidity sensors and their quality, a guy has put in a lot of time in order to check if some inexpensive humidity sensors actually are accurate (spoiler: They are surprisingly good).
Instead of varying concentrations of a particular salt I use saturated solutions of several different salts. Depending on the solubility of a particular salt, a different relative humidity will be generated in equilibrium with the solution.
Read more: Link - Test and Calibrate DHT22 / AM2302 / RHT03 hygrometers
Compare DHT22, DHT11 and Sensirion SHT71
The scripts
The humi.py script fails to get a humidity reading most of the time due to not having correct timings in the script and being interrupted by the OS I believe, with the current way the script works. ADAFruit has a python repository that has better performance (https://github.com/adafruit/Adafruit_Python_DHT.git it uses C or C++ as well, see dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging.pdf ), but for a hygrostat one does not need fast measurements, probably once every 20 minutes is enough. With the somewhat faulty DHT 11 sensor I had first 90% of all readings failed and with the one I have now I'd say 95% of readings fail. But it does not matter really, if you poll it say every 5 seconds.
It is very satisfying to hear the Pi switch on and off the humidifier.
Links to python software not used in project but that fulfil the same tasks, with C extensions
- lexruee/pi-switch-python: Pi Switch is a Python library for the Raspberry Pi to control 315/433MHz remote controlled power sockets. Switching on and off sockets
- List_KnownDevices · sui77/rc-switch Wiki Devices for the above link
- https://github.com/adafruit/Adafruit_Python_DHT.git Humidity monitoring