I had the reptile room set up with lights and heating controlled via electrical timers and the heating was done by an electric oil filled radiator with a thermostat on the front of it, I wanted a way of controlling the heat without having to go in to the room and change it every morning and evening plus it only had a dial on it numbered 1-5 and I didn't know what temperature that equated to.
With hibernation fast approaching I also wanted to log the temperature of the fridge to ensure that it was within an acceptable range.
First things first I looked into a way of getting the Raspberry pi to control the plug sockets, there were a number of ways of doing it using relay switches but I didn't want to mess around with mains electricity so when I came across THIS page I thought I would try something similar.
I ordered a set of 4 Remote Control Plugs (Energenie Remote Control Sockets) from amazon and a 433mhz Transmitter and Receiver from ebay.
I basically followed his guidelines on how to capture the codes by wiring the receiver up to the pi and connecting into the microphone socket on my laptop and captured the codes using audacity.
I then connected up the transmitter and grabbed his copy of switch.cpp. I had to change it a little to accommodate the energenie codes and also add a new option to turn them all off or all on.
You can grab my copy here
With the plugs working I needed a way of measuring the temperatures in the room so I ordered 3 temperature probes (DS18B20) and connected them up to the pi using this as a guide.
With the PI happily measuring the temperatures of the probes I worked out which was which and labelled them accordingly. Then put one in the tortoise room, one in the fridge and drilled a hole in the wall and dangled the other one outside.
I wrote a program (I chose python as the examples for the temperature monitoring were already provided in python and python was already on the pi) to log the temperatures and turn on/off the plugs based on the time and temperature. I set up cron to run the job every minute and added w1-gpio and w1-therm to /etc/modules on the pi.
A copy of the python script is here with comments to explain what each step does.
The cron job set to run every minute is as follows:
* * * * * python /home/pi/control.py >/dev/null
With the Pi happily controlling the plugs I wanted a way of checking it was behaving so I created a website and set the pi to upload the logs every 10 minutes.
I set up a SSH key on the pi and imported into my website so I didn't have to mess about with usernames and passwords then scheduled 2 cron jobs as below.
5,15,25,35,45,55 * * * * sleep 20 && bash /root/uploadlive.sh >/dev/null
1 0 * * * bash /root/uploadlogs.sh >/dev/null
The first line runs the uploadlive.sh script every 10 minutes, it waits 20 seconds (for the other script to finish) and then runs the script below
#!/bin/bash
The 2nd line runs at 1 minute past midnight every day and executes a script to upload the completed log for yesterday to my webserver and then reboot the pi (the wireless network has a habit of disconnecting unless I reboot it once a week, this keeps it connected). The code is below
host='pi@www.tortroom.com'
directory='/home/pi/public_html/logs'
scp /home/pi/logs/$(date +%Y-%m-%d).csv $host:$directory
#!/bin/bash
The website uses a JQuery calendar and graph and php to populate it based on the data available. The source is available on request.
host='pi@www.tortroom.com'
directory='/home/pi/public_html/logs'
scp /home/pi/logs/$(date +%Y-%m-%d -d "yesterday").csv $host:$directory
reboot
Any comments/suggestions drop me a message on facebook or email me at admin@tortroom.com
If you want to set up something similar and don't have a site to host it on I can stick it on here if you like.