The first time I got interested in home automation, was when browsing the arduino libraries. That was all about X10, which communicates over power lines. There are switches that can replace the regular light switches and are pretty cheap in the US. If you want such switches here in Switzerland, you’ll be surprised how expensive they are. And routers with X10 to make it accessible from your smart phone start at CHF 400. But what is easier to get here are the plugs with 433Mhz rf controllers. I got a set with one remote and three plugs for CHF 15 at hornbach. Then I ordered two different transmitters from China. One with the nRF905 chipset and an SPI interface. And one for sort of bit banging. I thought the one with SPI was going to be easier to use. I also found some code to interface it. But first I had to know what I need to send.
My first Idea was to use the DVB-T dongle with GnuRadio to sniff the rf protocol. Well, I’m not so proficient with GnuRadio. So far I only followed prepared recipes. I could tune in on 433Mhz and saw that there was indeed a signal, but I had no clue of how to decode it. So I looked around for projects that used GnuRadio on 433MHz. I found one, but that was code only. I was more interested in something for GnuRadio Companion, as that’s easier for beginners. I will have a closer look at this project, as I really want to learn more about GnuRadio.
Then one day, I searched the afore mentioned project for rf sniffing, and found something that could make the whole thing a lot easier: a 433Mhz library for arduino. It uses the simple transmitter that I also happened to order. And a quick test with an Arduino proved that it works with my power plugs.
The range was initially a bit reduced, until I connected a short cable to the antenna pin. It was still not great, so I calculated the length for lambda/4, cut a wire to 17cm and now I have excellent range.
I wanted to use an alix that’s running the whole day anyway to control it. It has no GPIO pins directly accessible that I could use for bit banging, but I already had a cable with the i2c bus running out of the case. Using an Arduino would be overkill, so I picked an AtTiny. Last time I tried to use Arduino libraries directly on an AtTiny I had trouble, and also linking C and C++ code for the AtTiny usually leads to problems. I’m sure they would be fixable. But instead, I did what I usually do for the AtTiny’s: I ported the library to C. I must say, I really much prefer C++, but the i2c library that I also use is in C. Appart from these style issues, the code worked well from the beginning. I tested it on the alix as well as on a RaspberryPi.
Now I was looking for a simple web application framework. Most web stuff I did in the past was using Wt, it is excellent if C++ is involved, or you otherwise prefer C++. But for this project it seemed like overkill. Looking around and testing some frameworks, I settled with flask.Â What I needed was not a lot different from the quick start guide. The website displays Icons that you can click to switch the devices on or off. I didn’t want a full deployment with a webserver. For this project I aim for simplicity. Just like Wt, flask can run it’s own little local webserver. To keep it running after I terminate my ssh session, I start it inside a tmux session.
To use the remote control from anywhere outside the home wifi range, first open a tunnel: “ssh -L 5000:alix:5000 homeServerAddr” and then point the browser to http://localhost:5000. If you don’t happen to run debian on your rooted android phone, I think you can also open a tunnel with ConnectBot.
As usual, the code is available from github.
Here’s the material bill for the project:
- linux system with i2c. e.g. raspberrypi B : EUR 33
- 433MHz transmitter : USD 2.75
- AtTiny45 : CHF 3.75
- RF switching power plugs : CHF 15