Project: Using a Raspberry Pi to connect Alexa to your hot water (Part 1)
By Rodhán
- 5 minutes read - 929 wordsThis is part 1 of a multipart series with the end goal of being able to ask my Amazon Echo, “is there enough hot water for a shower?"
Introduction
People in Ireland often think to themselves… I’d like to have a shower, but will there be enough hot water or do I need to turn on the immersion? If you have never lived in Ireland, you might not know that many Irish homes have a hot water tank (in a “hot press”) with an electric coil sticking into it that essentially heats the water in the tank like a kettle. This is called an immersion, and it is often controlled manually (and according to the Irish Times, a quarter of us regularly forget to turn it off!).
Details
There are other ways to heat domestic water, but for better or worse, this is often how we do it. The hot water is kept in a copper “cylinder”, and the switch allows you to choose which immersed heating element you want to turn on, the small one for a sink full of water, or the big one for a bath full of water.
There are all sorts of timers and thermostats and off the shelf options for automating the heating of water or making it more convenient, but what I want to build is a simple way to know if there is currently enough hot water for a shower, or if I need to turn on the immersion.
“Done is better than perfect” - an aside and a disclaimer: I gave a talk a few months ago at the Digital Hub Developer Lunch and Learn where I talked about how, in some ways, I have been “working on” this very project for many, many years, as did my father before me! But then it was time for a change - time to actually get it done. I kept the words “done is better than perfect” in my mind and I pushed on through and got it done. So this is a disclaimer. It’s far from perfect, but it’s done!
Stage 1: Set up the hardware, and read the temperature
The goal for this first stage of the project is simply to be able to read the current temperature of the outside of the hot water tank at a particular point. It doesn’t have to be particularly precise or accurate of a temperature reading, just something that we can look at over time work out when there is enough hot water for a shower, or when we need to heat it up some more.
All we need is a sensor, and some way to eventually upload the temperature readings to the internet. There are a few different options that I could have chosen, but for this build I went with a Raspberry Pi and the Maxim DS18B20+ temperature sensor. The Pi is easy to configure and if this project doesn’t work out, can easily be repurposed for some other use. And you can’t beat the simplicity and versatility of the 1-wire, pre-calibrated, addressable temperature sensor.
Parts
Once I had settled on the parts list, I wanted to get going as soon as possible so I ordered everything from local supplier Radionics:
I already had a power supply and plenty of wire so once the order was delivered was ready to start the build. My Raspberry Pi came with a preinstalled NOOBS SD card so I got a stock install of Raspbian and configured it to connect to my wifi and was ready to work on the build.
The Build
Really we just need to provide power to the temperature sensor, and connect the data pin to the Raspberry Pi’s GPIO Pin 4. There seems to be some debate over whether it is really necessary, but a lot of tutorials say you need a pull-up resistor in parallel between VCC and GPIO so, even though it complicates things slightly, I went with that too.
Logically it all looks like the Fritzing diagram above, but in reality I didn’t use a breadboard and instead soldered the components directly to the end of a 2 metre length of CAT-5 cable to allow me to easily get the temperature sensor into position on the hot water tank.
Testing the Sensor
Before we can start reading the temperature from the sensor, we need to enable GPIO on the Raspberry Pi by adding dtoverlay=w1-gpio
to the /boot/config.txt
file. See 1-WIRE at Raspberry Pi GPIO Pinout for details.
After rebooting the Raspberry Pi, we should now be able to query the sensor and see the readings. By running ls -l /sys/bus/w1/devices
we can see everything on the 1-wire bus, which should include our temperature sensor, with a name beginning with “28-“.
And finally, we are ready to read the temperature from the sensor. Using the name from our previous step, run the equivalent of cat /sys/bus/w1/devices/28-00000a03f654/w1_slave
which will give us the following output:
$cat /sys/bus/w1/devices/28-00000a03f654/w1_slave
50 01 4b 46 7f ff 0c 10 e8 : crc=e8 YES
50 01 4b 46 7f ff 0c 10 e8 t=21000
The magic number there is 21000
, which, when we divide by 1,000, is the temperature of the sensor in degrees celsius. 21℃. IT WORKS!!
What’s Next?
In the next part of the series (coming soon!) we will look at how to get this temperature reading off the Pi and into the cloud, and then see how to get Alexa involved. Stay tuned :)
Meanwhile, I’ll leave you with this: