42

What I would like to see is the cheapest way possible to control my lights using my Raspberry Pi.

What I imagine to control it

I build an interface on my smartphone by which I can send commands to my Raspberry Pi. The Raspberry Pi would then send a package (or something else) to a thing I can put inside my power socket (so I don't see it). Note that this thing should be connected through Wi-Fi (how else is it going to receive the message from my Raspberry Pi?).

What is this thing and what is the cheapest possible way possible, as I am planning to connect a dozen or so lights?

Rick Hoving
  • 657
  • 1
  • 8
  • 7

7 Answers7

22

I'm using these items:

  • Receivers ON-OFF to control my lights (you typically put a device in the walloutlet or instead of the walloutlet). They work in the 433 MHz band (ISM).

Out of the box you have a remote control which sends a signal to the receiving device and switch it on or off.

In my case, I created this situation:

  • Created an HTML site on my Raspberry Pi (/switch.html)
  • I call that page on my smartphone
  • On the page are four buttons (I control four devices / lights)
  • When I click a button, it asynchronously fires a call to /switch.php (the .php is on the Raspberry Pi)
  • The switch.php calls a switch.py program which controls the 433 MHz sender (see below)
  • The 433 MHz sender does the same thing as the out of the box remote control.

This is the sender, that is, the replacement for the standard remote control: 433 MHz Wireless Transmitter Module Superregeneration for Arduino

I also created a scenario for out-of-house use.

I didn't want to connect my Raspberry Pi via my homerouter directly to the Internet, so I built myself another webpage (at my own domain) which does not control the Raspberry Pi directly, but it sends an email to a (known only to me) email (Gmail) address.

The Raspberry Pi checks that email account every 10 minutes to see if there is any email. In that email I for instance say A on or B off.

So when we get home late and the lights are already off, we navigate to the site on my mobile (plans are to make it an Android app), click the button, the page gets posted and at the server an email gets sent, and in the next 0-10 minutes the Raspberry Pi checks the email, sees four new emails (A on, B on, C on and D on) and switches the lights on.

How to get started

So, to get started, these are the things I've done to get it all working. In my case, I programmed the control of the 433 MHz sender in Python (which is an easy language if you already know how to program).

First you install the rpi.gpio libary.

This library is used to control the little pins on your Raspberry Pi from your Python script. See Install RPi.GPIO Python Library.

Then you can optionally read the article Tutorial: How to use your Raspberry Pi like an Arduino, it's about what you can do with the rpi.gpio library, for instance blinking LEDs.

It's not mandatory for the Elro light switching however.

Then you get the awesome code for the Elro commanding by HeikoHeiko, at http://pastebin.com/aRipYrZ6. You paste that code in a file named 'switchelro.py'.

You then change the string on line 94 to your own jumper settings (as you have set in your remote control and the walloutlet device. Check wether the combination remote-walloutlet device works before trying it with the Raspberry Pi. If it doesn't work with the standard components, it will probably fail with the Raspberry Pi too).

You then change the number of the pin your sender is attached to on line 97.

The pin number can be gotten from RPi Low-level peripherals and in File:RPi P1 header.png.

You have to use the 1..26 count (the black image), not the GPIO34, GPIO24, etc. (green image).

Then you type this on the command prompt:

sudo python switchelro.py 2 1

which means 'turn on B' (following this schema: A = 1, B = 2, C = 4, D = 8, E = 16 for the first number, and 1=on, 0=off for the second).

I changed the repeat = 10 on line 30 to repeat = 20 in the beginning (I don't remember why) and that works. I never retried it with the setting '10'.

Peter Mortensen
  • 2,004
  • 2
  • 15
  • 18
Michel
  • 1,124
  • 4
  • 14
  • 21
  • 1
    oh, and the price.. here in the Netherlands a set of 3 walloutlet receivers (which you click in the walloutlet, and the light goes into the receiver) with remote control costs 15 euro. The 433 Mhz sender costs about $5 – Michel May 22 '13 at 08:07
  • That sounds exactly what I'm searching for! Could you please send me the project files? (The switch.html, switch.php and, the switch.py) My email is in an above answer. Also, where can I buy the on-off2 receiver in the Netherlands? The website you provided does not provide any prices. – Rick Hoving May 22 '13 at 08:22
  • Excellent post- Can you add where you found the source for the commands you send via serial ? Are you usign a library? How do you target the devices? +1 – Piotr Kula May 22 '13 at 08:48
  • @Michel Where you can buy those for that cheap? – Piotr Kula May 22 '13 at 08:49
  • @ppumkin I get your point, I can't find them either for this price anymore. Used to be sold at the Gamma (Dutch store). Found a few boxes at the Leen Bakker (Dutch store) a while ago, and they where at Ibood a few weeks ago. But I must agree, can't seem to find them at regular shops for that price anymore. – Michel May 22 '13 at 09:29
  • I'll put some sources at it tonight. There is a library to control the GPIO pins (RPI.GPIO) and a Python class which sends the right signals to the RPI.GPIO library. You can configure the letter (which you click on the remote) and the jumpersettings in the Python class. – Michel May 22 '13 at 09:34
  • Found the previous model line here http://www.home-easy.nl/3-schakelaars-met-afstandsbediening-2315 for 16 euro's. I'm using that (previous) model line too. – Michel May 22 '13 at 09:40
  • @Michel Nice one! But did you ever control them using a 433 transceiver? Do you know the codes to send? :) – Piotr Kula May 22 '13 at 09:42
  • Yep, I have this one working at my house (copied from my 'previous orders') http://www.miniinthebox.com/433mhz-wireless-transmitter-module-superregeneration-for-arduino-green_p411875.html – Michel May 22 '13 at 09:48
  • The real difficulty of sending the right data on the 433Mhz band is done in the Python class which I will attach later (and was not written by me ;-)) – Michel May 22 '13 at 09:50
  • Added the steps to get you started. – Michel May 22 '13 at 18:31
  • @Michel this is a great tutorial, could you send me the code you have please? Please send it to rickhoving7@hotmail.com – Rick Hoving Jun 18 '13 at 11:58
  • Can we program the 433 MHz sender thru C# .NET/Mono? – Nitin Sawant Mar 17 '15 at 10:56
  • How the A = 1, B = 2, C = 4, D = 8, E = 16 pins are mapped to multiple recievers? (I mean how the sender uniquely identifies multiple on-off recievers?) – Nitin Sawant Mar 17 '15 at 11:43
  • 1
    @Nitin In my system you can set the dipswitch on the receiver (the 5 on/off switchers) and 5 letters (A .. E). So with the code default_key = [1,0,0,0,1] from the http://pastebin.com/aRipYrZ6 code you control the dipswitches and with the pin property in the def __init__(self, device, key=[1,1,1,1,1], pin=4): code you control the A .. E (a=1 .. e=16) – Michel Mar 17 '15 at 13:32
  • 1
    @Nitin Don't know how to control it with C#. Looking forward to that too, because the latest PI will run Win10 and hopefully it will run C# as well. That said, whilst I am a C# programmer, Python is an easy learn – Michel Mar 17 '15 at 13:33
6

What you're looking for is a Solid State Relay or mechanical Relay. The idea is that a small amount of current at a low voltage (such as from your RPi) can be used to trigger the flow of a larger amount of current at a higher voltage (such as a lamp).

I would recommend $12 SainSmart 8 Channel DC 5V Relay Module for Arduino Raspberry Pi, as it's already been manufactured into a board with ready to use screw terminals. It has build in FETs to source the extra current required for mechanical relays to be triggered. There are different boards from the same company, in a wide variety of layout/number of relays. The one I sent is 8 channels, so it might not be sufficient for your needs, although there are 16 channel versions available. They're generally cheaper than buying multiple relay's separately, and making hooking up to them easy.

There are 4 connections required:

  • A common ground (that's shared to all relays) that connects to the RPi
  • Separate inputs powered by individual RPi GPIO lines (to trigger relays)
  • A high voltage input
  • A high voltage output

The high voltage inputs/outputs are the connections that are made or broken by the relays in accordance to their input lines.

I already have an AWESOME C program for remotely switching GPIO pins over SSH. If you'd like I can give you the source code, or even explain how it works.

Pro Backup
  • 105
  • 4
Alexander
  • 600
  • 6
  • 18
  • How can I say no to an AWESOME program. Although C is not in my repertoire of languages, I can at least look at the code over time. – Rick Hoving May 21 '13 at 08:59
  • If your question has been answered, please click the checkmark below the voting arrows. – Alexander May 22 '13 at 06:09
  • @XAleXOwnZX can I see this Awesome code too? Perhaps you should open a "Does anyone have an AWESOME C program for remotely switching GPIO pins over SSH" question then answer it. – puk Sep 30 '13 at 06:21
  • I'll need your e-mail address, I'll send it and post the question+answer tomorrow – Alexander Oct 01 '13 at 04:28
  • can I connect the rPi to this relay board directly? Or do I need add a resistor/transistor in between? And also is it fully isolated? so that in case something happens, my pi or electric appliance is still safe? – avi May 27 '14 at 18:09
  • @avi, the board already contains the FETs (field effecr transitions) needed to source the current needed to trigger the relays, so you can hook up directly. And yes, theyre isolated – Alexander May 27 '14 at 18:15
  • @XAleXOwnZX do you have any detailed blog post/youtube video of this project? I would like to know more and learn! – avi May 27 '14 at 18:18
  • No, sorry, but there are many out there on using relays to control mains appliances – Alexander May 27 '14 at 18:18
6

The thing is called X10, it's an industry standard for most home automation tasks, including controlling lights. The control signal is sent over the same power line your appliances are connected to.

To be able to control everything from the computer, you might want to read about X10 Computer Interfaces from OpenRemote web site. The model you're most probably are after is CM15A with USB interface, that has Linux support.

Also, it might be a good idea to check ebay for X10 enabled wall sockets and screw in lamp modules, these can be bought quite cheaply, in the $10-20 range.

lenik
  • 11,541
  • 1
  • 30
  • 37
2

my system is cheap: EUR 43.- (receiver + transmitter) see below.

for home automation I simply attach an 3.3V compatible 868,35MHz FS20 transmitter to the RPI:

http://www.elv.de/elv-fs20-uart-sender-fs20-us-komplettbausatz.html

this transmitter interfaces directly (by 4 wires only) to RPI's GPIO ports (3.3V, GND, TXD, RXD) and is simply controlled via the serial line interface.

you now can control the huge range of FS20 devices like switches, toggle switches, dimmers, timers, radios. multi-channel-receivers etc. by transmitting some bytes over RPI's UART serial console interface.

FS20 system overview:

http://www.elv.de/fs20-funkschaltsystem.html

(unfortunately the website is available in German only)

I personally prefer plain CLI for controlling my home devices. Should you prefer some GUI you may have a look here:

http://fhem.de/fhem.html

fortunately in English :-)

Though very flexible the FS20 system is very cheap. Sample costs for a simple on/off switch:

switch itself: http://www.elv.de/elv-funk-schaltsteckdose-fs20-st.html EUR 22,95

UART transmitter: http://www.elv.de/elv-fs20-uart-sender-fs20-us-komplettbausatz.html EUR 19,95

I recommend to control the RPI itself by a wireless keyboard. For this you optionally may buy this ingenious little thing:

RT-MWK03[Wireless 2.4 Ghz] (http://www.riitek.com/en/product-detail-428.html)

sparkie
  • 435
  • 3
  • 9
1

I wrote a detailed blog post on how to control outlets wirelessly using a raspberry pi. Check it out: http://timleland.com/wireless-power-outlets/

Tim
  • 121
  • 1
  • 4
0

I have a differente approach: I am using Busware's CUL USB dongle (supports FS20 + HMS + FHT + other protocols and devices), and implemented my own Java API to abstract the devices and allow easy automation via a Java application.

In case anybody gets interested on my little project: http://www.paulo-lima.org/hans

0

While not exactly cheap, here's my solution:

http://www.everyhue.com/?page_id=38#/discussion/707/raspberry-touchpad-some-success

Basically, you use the Philips Hue (wifi-controllable, programmable multicolor LED lights) together with a RPi and a touchpad. The USB touchpad surface acts on the color and brightness dimensions, while the mouse buttons toggle the lights on and off. Cost is RPi + Wifi dongle ($11) + cheap USB touchpad ($15) + Philips Hue set ($200 for bridge and 3 lights, then $60/light).