Monday, December 23, 2013

Raspberry Pi Home Security + Automation - Phase 2

Update: I was able to get the RF outlets to work using a cheap transmitter from Ebay. So the below method is just here for documentation purposes.Check out my post here

I added more functionality to my system described in my earlier post here. As part of phase 2, I added internet controlled outlet/switch control via the Pi. This is an easy way to convert an RF outlet switch to a web controlled one.

I picked up a remote + 3 RF outlet switches  (433Mhz) from Ebay which are manufactured by DB-Tech.

Remote control outlet switch socket

There is a single button to toggle the outlet on/off. My initial intent was to use a RF receiver to decode the code sent by the remote and replicate it. I tried several methods including the ones outlined here to use your PC soundcard + Audacity to decode your waveforms, but my attempts were unsuccessful.

So I opened up the remote and it looks like this: (ignore the wires - that is something I added, as you will see later in the post)

It uses 3 simple buttons and a PT2262 Encoder. It comes with 12V battery to power it. The datasheet of the encoder can be found here. I noticed that the supply voltage is rated at 4-15V and I tried to power the circuit via the Raspberry Pi GPIO. I was pleased to discover that it works for voltages slightly below 4 as well!

So I soldered  3 wires to the switches by tracing the pins that would be normally be connected to the +ve of the 12 V supply.  The other end of the wires are driven by 3 Pi GPIO. I used a crocodile clip to connect the Pi GND line to the -ve supply of the circuit (normally connected to the battery -ve).

This solution does not scale too well with the number of outlets, so I have to find something better eventually.

The next steps are pretty straightforward and involve adding new macros to the existing webiopi interface (from phase 1) to control those GPIO. I found that a delay of 0.5 sec between driving a high and low provides enough time for an outlet to be switched on/off.

I also have cron jobs that run python scripts to power these outlets on/off at different times automatically. This can be really useful for repetitive tasks like switching on/off a light every night or turning on an electric kettle every morning.

The end result is an internet controlled home automation system that lets you power on/off different electrical devices.

Here is the updated web server interface:

Just in time for Christmas, here is a short video showing how I turn on my Christmas Tree lights using the interface on a phone.