BlogThe start of DIY home automation: replacing the thermostat

The following errors were encountered: Please rectify them and try again.

Since forever I've always been enamoured with the idea of home automation, but it's always been beyond my reach for one reason or another. Lately the blocking factor has been that I'm renting so I can't really pull apart the makings of the house. Fortunately, however, the house I'm in now has a wireless thermostat, which means I can control the heating without any intrusive measures as it uses the 433MHz band.

I have managed to replicate the wireless signal that the thermostat sends to the boiler for both the on and off commands with a Raspberry Pi and a cheap 433MHz receiver and transmitter. This instructables article was instrumental in understanding what I needed to do in order to get the job done. This blog post was also very helpful. The code from the Instructables article was very useful in order to record and inspect the signal sent by the thermostat.

Here's what I picked up:

On signalOn signal

Unfortunately I don't have a picture for the off signal.

If you looked at the Instructables article you can see that my graph doesn't look nearly as clear cut. There doesn't seem to be a clear sign of a 1 or a 0. The pattern I saw was that each rising and falling edge is either 450(±50) or 900(±100) microseconds apart. So in order to replicate that signal I made a loop that inverted the pin output on the GPIO on each iteration and put in a delay of 400 microseconds multiplied by either 1 or 2 to represent the delay between each signal inversion. I chose 400 microseconds to account for the delay inherent in a non-realtime OS. Here's the Python code I knocked up to test the signal:

  1. import time;
  2. import sys;
  3. import RPi.GPIO as GPIO;
  4.  
  5. sendPin=24;
  6.  
  7. GPIO.setmode(GPIO.BCM);
  8. GPIO.setup(sendPin, GPIO.OUT);
  9.  
  10. onCode = [1,1,1,1,1,1,1,1,1,1,1,1,2,2,1,1,1,2,2,1,1,2,2,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,2,2,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,2,1,1,1];
  11. offCode = [1,1,1,1,1,1,1,1,1,1,1,1,2,2,1,1,1,2,2,1,1,2,2,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,1,1,1,1,2,1,1,1];
  12. code=offCode;
  13.  
  14. if (sys.argv[1]=="on"):
  15. code=onCode;
  16.  
  17. signal=False;
  18. for t in range(3):
  19. for i in code:
  20. signal = not signal;
  21. if (signal):
  22. GPIO.output(sendPin,1);
  23. else:
  24. GPIO.output(sendPin,0);
  25. time.sleep(0.0004*i);
  26. GPIO.output(sendPin, 0);
  27. time.sleep(1);
  28. GPIO.cleanup();

To use it I just called the script and added either on or off as an argument to determine the command to send to the boiler. The 'for t in range(3):' bit is because the thermostat sent the command 3 times, probably to be sure the command was received. I do have interest in finding out what exactly is being sent and how to properly encode and decode it, but I spent a while trying so at this point I don't care as long as I can control the boiler.

The next phase is to get a temperature sensor. I've gone for the DS18B20 as it appears to be the easiest to use with a Pi. Once I have that I'll knock up a little script to monitor the temperature and control the boiler. I'll leave that running to see how it fares while I work on the actual code that will do the monitoring of events to fire the boiler.

The end goal is to have a Pi to serve up device data and send out device commands. There will be a JSON web service on my web server Pi that I can talk to from either a web UI or mobile app that will send off commands to a service running on the device Pi. The web service will keep data in a database that has a set of triggers and conditions for each trigger. I will either use Cron or a small script to keep and eye on the conditions in order to fire the triggers. I then want to extend this service out to other home automation devices via Z-Wave for things like lights.

Posted on Sunday the 6th of March 2016