Picture of Raspberry Pi GPIO home automation
I had heard about GPIO pins on the raspberry pi and decided to do something with it. And with the holidays coming, wouldn't it be great to be able to turn on and off your light display from the web!  This is a pretty simple project that creates a web app for controlling lights.  It uses the Raspberry Pi for the internet connection and a wireless remote control to turn on and off the lights. The tricky thing is to connect the Raspberry Pi GPIOs to emulate pressing the buttons on the remote control.

Step 1: Parts

Parts needed:
• Raspberry Pi
• Remote controlled outlets
• Ribbon cable
• Solder

(Not shown)
• PCB board
• Resisters

• Soldering gun
• Dremel/Hacksaw
• Screwdriver
• Wire cutters
• Wire striper
• Multimeter
k.r11 month ago

i am running raspbian. can you simply give us

setup-web2py-ubuntu.sh because i am having problem setup apache 2.2 to 2.4 . please uploade somewhere or email me kotarajeshece@gmail.com

qkarthik4 months ago

internal error was made !!!

I have a remote controler where the button "pulls down" the micrcontroller line to the ground when it is pressed (opposite to your case of pulls up).

How can I do the wiring ?

Snellingkorey8 months ago

great idea, can you wire up the kettle and washing machine as well?

don't be silly Snellingkorey, that would take at least 2 Raspberrys and a Strawberry!

ManuelA310 months ago

In my case ,Installing web2py on a raspberry running raspbian, I had to modify a line on setup-web2py-ubuntu.sh


sudo a2ensite default


sudo a2ensite default.conf

Also, the auth types on the default.conf were on apache 2.4 format, whereas the setup script installed me apache 2.2 so I had to make changes according to http://httpd.apache.org/docs/2.4/upgrading.html#ru...

i am running raspbian. can you simply give us

setup-web2py-ubuntu.sh because i am having problem setup apache 2.2 to 2.4 . please uploade somewhere or email me mejlgago@gmail.com

xpark8 months ago

Can u tell me exactly how i can access this server from an outside network?


If I wanted to upscale this to more than just three switches, how would I do that?

davidbarcomb9 months ago

Great instructable, detailed and well explained. Keep up the good work

lzkill10 months ago

Hi pals!

The resistor used on this project are dependent on the RF controller? Why were these picked?

KentR210 months ago

How could i set this up to run locally, that is running the program directly on the pi without internet acess?

aswinmp11 months ago

My project is home automation and CCTV. After doing the cctv function using pi, we did the automation part. Upto step 7, everything went perfectly. After that, I cannot access pi using ssh or remote desktop. And I cannot access the web page.

What to do? Please help me!

I had trouble installing web2py but I think I got it solved by using this script instead:


and then running this at startup:

sudo uwsgi --master --die-on-term --emperor /etc/uwsgi --logto /var/log/uwsgi/uwsgi.log &

OliverL1 year ago


I have ssl problem :Hibakód: ERR_SSL_PROTOCOL_ERROR.

I use Chrome and Explorer, the problem is in both.

I have no idea :-(

Nice Job!!

Very detailed guide.

GeorgeB11 year ago

where do you download the home lights package

Hi matey, i'm from Australia and i need this model for a demo. can you please let me know if it is possible for you to post me a working model (whole kit) and guide me to make it work.Please, respond to this message on my email "rohitgoudponnam@gmail.com" is my gmail id.

Thanks and Regards


We already developed piece of hardware for home control. There are relays, digital inputs, 1wire, EEPROM, 0-10V.....

check indiegogo project:


Samginoya1 year ago


wen i write this in pi terminal :

sudo python /home/www-data/web2py/applications/Home_Lights/modules/GPIOServer.py

it show me:

python: can't open file '/home/www-data/web2py/applications/Home_Lights/modules/GPIOServer.py':

[Errno 2] No such file or directory

BennyTC1 year ago

that is a typo, delay there is 2 seconds :P

BennyTC1 year ago

Awesome project!
I intend to use it to control a door buzzer, so I added 5 second delay.

I had to change swap the output from "1" to "0", because I am using a brandless 8-relay board which operates as Active LOW (relays are turned on when output is "0").

In the hope it is of help to anyone, this is what I did:

changed the GPIOClient.py file's line 13 to this:

ON = chr(0)

and added the following lines to the GPIOServer.py file

line 3:

import time

line 12:

SleepTimeL =2

line 23: (this is after GPIO.output(pin,val))


cartiman1 year ago

I use the raspberry pi from china (red color), what can?


sadhvi1 year ago


we are interested in doing the home lighting automation which takes care of the central lighting system. so, could you please suggest how to proceed with the project.

email-id: nangunoorilaxmijoythi1@gmail.com


losgat1 year ago

Hi have it all setup and working as expected but is there any way to change the output for relays and not single button press applications ( using a relay that need to be powered constantly?

Traceback (most recent call last):

File "/home/www-data/web2py/applications/Home_Lights/modules/GPIOServer.py", line 29, in <module>


File "/usr/lib/python2.7/socket.py", line 224, in meth

return getattr(self._sock,name)(*args)

socket.error: [Errno 99] Cannot assign requested address


//What should I do with this error??Please Help..:)

gaelreinaudi made it!1 year ago

cool introduction!

peecee781 year ago

Hey - does anyone managed to adopt this web interface to work with 8 channel relay?

I wired it but on relay all i get is just a blink of LED i try to edit the settings - same result...

Please help

i think in your case the input voltage is not enough for the relay board so double check your input volt.

Sweeet!! Everything works except i have to be at home connected to my wi-fi for it to work. is that supposed to be that way?

amrnablus1 year ago

I have a question.

If i want to automate lights or AC, should this device be controllable via a remote controller in the first place or it's possible to do it with any hardware.

icemeth1 year ago

i have a problem in setting up the web2py setup. when i type sudo ./setup-web2py-ubuntu.sh it has and error and it says cannot find file destination though i have downloaded the setup file. and i cant update my raspi it also has an error. is it because i have a dynamic internet connection??pls reply i need your help..thanks

hughjeremy1 year ago
When I connect up the wires, it acts as if the button is being held down, and so it can't define which button is being pressed when multiple buttons are connected.

Long story short no matter if I turn them on or off, it doesn't make a difference!

Help would be so appreciated!
Awesome tutorial and project! Can't wait to fully try it out. I'm having one issue though. I don't have all of the proper hardware yet (I have everything but the remote outlets and a cut ribbon cable). But my problem is once I try to start the GPIOServer.py, it indefinitely says "waiting for connection...". Is this because I have nothing connected to the GPIO pins? I was hoping to run out later and get everything else I need, but I figured I would set everything software-related up first. I'm hoping this is the issue, and not the fact that my pi hates me, haha.

Anyways, thanks in advance for the response and, again, awesome instructable.

- Chronos
andyn5001 year ago
sorry man email is a.nolan@pss.ie

andyn5001 year ago
Hi I am very interested in your project its brilliant. I am new to computers and have very little understanding of electronics. Is there any chance of further instructions for this eg PCB board and what resistors you used if possible. further instructions diagrams etc.
Would be very helpful
Smarty45311 year ago
hello, awesome instruction guide everything is working except for the pictures for the buttons. when i go to the webpage they never shown up. im talking about the power bottons plz help thx
Screen Shot 2013-11-16 at 4.45.38 PM.png
sir,i need your help, can give me all detail about this project? code or anything about this..tq sir
jets_fi2 years ago
Has anyone tried doing this with remotes that are powered by 3v battery? You could power the remote with Pi then, right?

And not to forget thanking willq44 again!
sir,,i am studying b.tech(computers)....i want to do my final project on RASPBERRY PI..can you give the data and code about "Raspberry Pi GPIO home automation" ...if you give it to me then it would be helpful to my project....
my email id is : avinashcme@gmail.com
_Yvan_2 years ago
« PreviousNext »
Preview Your Comment
Hi, thanks for this very comprehensive tutorial. This instructable fits nicely into the kind of stuff I want to do as a hobbyist. It all works well untill I press "database administration" Under Model, I then get: Internal error Ticket issued: Home_Lights/ The ticket reads: type 'exceptions.TypeError'> define_tables() got an unexpected keyword argument 'signature; 47 auth.define_tables(username=False, signature=False) or clicking on other tabs stuff as Traceback (most recent call last): File "/usr/lib/pymodules/python2.7/gluon/restricted.py", line 205, in restricted exec ccode in environment File "/home/pi/web2py/applications/Home_Lights/models/db.py", line 47, in auth.define_tables(username=False, signature=False) TypeError: define_tables() got an unexpected keyword argument 'signature'. trying to get to :8000/Home_Lights/default/index brings up the same problem. Every error message hinges around unexpected keyword argument 'signature'. Do you think it might be do to my using different versions of programs or something like this. I know python is touchy about this: root@raspberrypi:~# python Python 2.7.3 (default, Jan 13 2013, 11:20:46) [GCC 4.6.3] on linux2 under fish://root@raspberrypi/etc/ there are 3 python folders,python2.7, python3, python3.2 Pitty, cause this happens to be exactly what I was looking for, and nowhere can I find such a thorough tutorial. I wish you can make a suggestion to make me go on. Thanks for sharing in any case Yvan
freakqnc2 years ago
willq44 or anyone has any pointer on how to change the behavior of the buttons to turn them into a relay "lick-->ON, click again-->OFF" instead of having them send a pulse to simulate the push of the button on the remote as it was needed in this project (bueller... bueller... ;D)? Thanks!
lribani2 years ago
hello, and thank you willq44 for the project, great project.
the only one problem i have is that i don't use wireless relè, but cable relè. So that when i push the web button to switch on lights, lights turn on for 1 second and immediatly switch off, the same then i push the button to turn off them.
How can i solve this problem?
many thanks
Have the same problem that Lorenzo Ribani described.

The current buttons act as a trigger which goes on and then almost immediately off. What should be modified to make each button a toggle that will behave following a pattern like: click-->ON, click again-->OFF (and so forth)

Thanks! :)
freakqnc2 years ago
Oh... and  wanted to ask whomever may know... does the service always need to be started manually issuing:

sudo python /home/www-data/web2py/applications/Home_Lights/modules/GPIOServer.py

or will web2pi start it automatically? If not how can it be started automatically each time the RPi boots?

Thanks! :)
freakqnc2 years ago
The python module is up to RPi.GPIO-05.2a and there have been several fixes to it worth installing that instead of using RPi.GPIO-04.2a. If you like me have typed into the terminal (I was in the Raspi via VNC) and get a 404 no matter how you spellcheck every single bit of the whole URL... then just use midori to get to the page where the file is, then right click on the file and copy the location... then go back to the terminal and you will no longer get a 404 there must be something wrong maybe with a dash character because I checked all the characters time and again and kept receiving a 404 if I was typing the URL myself... did I say nothing comes easy lately? Geez I need to burn some sage! ;P
freakqnc2 years ago
Well whaddayano... on mac there is a bit of an issue with the file web2py.app.Home_Lights.w2p.zip

To begin with it downloaded as FQ13R8YH8RK8Q4L.zip but that's no biggie since could be renamed, but the auto expansion of the downloaded zip kicked in and created the file properly named

The problem is that it was named: web2py.app.Home_Lights.w2p.app and showing as a MacOSX app with a forbidden sign over it (showing is incompatible with mac OSX. Well you'd think remove the .app extension? Not so fast! Won't let you. So I went to the info (Command-i) and unlocked (via the lock icon at bottom left of the info pane (in OS 10.6.8) and I was eventually able to change the name in the "Name & Extension" text area in the info pane... now it became a folder containing all the files that the package has inside! Obviously the app could not be recognized by the web2py package uploader.

Soooo... I got better zip (a mac utility used to open zipped and other compressed files) and used that to expand the content by dragging and dropping what listed to be the file contained by the zipped archive... the only file visible was one named "web2py.app.Home_Lights.w2p" so I dragged and dropped it on the desktop... NO GO... better zip complained about some kind of wrong password... then I decide instead to right-click on that web2py.app.Home_Lights.w2p file and selected "Extract here" from the contextual menu.... FINALLY! I got the file web2py.app.Home_Lights.w2p on the desktop which the uploader could see.... boy! nothing really comes easy lately! :)

By the way if you have problems logging into your admin area make sure you used HTTPS! Or you would get a 403/Forbidden. Even if getting the https error from your browser say ok and continue loading the page... you'll get a prompt for the admin pass hope that helps those who may get stuck there ;)
freakqnc2 years ago
Curious to know two things...

1) Will the pi be able to use this without being connected to the internet? I have to install in a location where there is no internet available and I am planning to access the pi via standalone wifi router.

2) What do you need on the pi just Raspbian or a LAMP or other software? Web2Py seems to be a complete framework that comes with its server/MySQL and what not... though the documentation states that it works with other webservers too so I am wondering if one needs anything besides the latest Raspbian OS (I'd install at least raspbian and VNC on it if nothing else is needed).

Thanks for the tutorial and for keeping it up-to-date! :)
jets_fi2 years ago
12V remote controller-people: solution found

As I cannot reply, I always need to comment (a bug with instructables, reply does not work with Chrome or Firefox).

Anyway, I found out that I should not have the battery in the remote controller while it is connected to the Pi. Pi will not read button presses if battery with the controller is present. Apparently it messes up the voltages etc. If connect to the Pi without battery, Pi will read buttons pressed correctly. But I wonder how I will power 12v controller with the Pi?

Well, as Willq44 replied somewhere here, it might just be possible to just power the remote with Pi. So, what I did as an experiment, I soldered a 3.3V (pin 1) to plus side of the battery connector in the remote. That gave me first success, but signal to the remote controlled plug was bad and it barely worked.. well, lack of power, I guess. So I tried 5V from the Pi (pin 2) and it started working. I do not know how much range will it have, but it works across the room. And that is all I need at the moment..

Phew, this has been quite an adventure :) Back to world of electronics, tin and soldering :)
jets_fi2 years ago
To reply to myself, I believe willq44 is using Revision 1 board, if I see it correctly from the picture. At least it is revision 1 board in the case project of willq44 :)

So just maybe, my problems are because of that. The pin states (or something) are a bit different.

At the moment, I have no idea how to fix it.. all help would be welcome.
jets_fi2 years ago
By the way, did you use Raspberry Pi Revision 1 or 2 board?
jets_fi2 years ago
Excellent project and thank you for great instructions! However, this project is driving me mad :) I believe I have a similar remote controller as "alfista2600". I am not a professional with electronics, but used to do all kinds of simple stuff when I was young and active radio amateur. I simply cannot make this work. I have checked and re-checked and everything should be just fine. I found out correct pins of the switches etc but no luck. All switches have one side that is connected to all the else. I even tried soldering ground wire to that common side. But then, when I plug it into Pi, the controller led just keeps on shining, which it should do only when a button is pressed. I soldered the ground back to Battery Minus. I am wondering, if I should find a ground point that is connected to the microcontroller, but I think that should not matter. All help is appreciated..
craigmawer2 years ago
Hi Guys
I got an strange problem with my button! assuming that when you switch the button to on it stays on, but in my case it comes on for a second and then goes off again. this is a fresh install of the pi OS and everything needed for the project to work, so there isn’t anything clashing I guess. I am using pin 11 for the led, although when i set it to other pins it does the same. Anyone got any ideas? Thanks guys
edmondwee2 years ago
hi, if I'm holiday and I'm far away, how would I be able to turn on or off the lights? also, would it be a stretch to put a webcam so that I watch what's happening in my home? thx
willq44 (author)  edmondwee2 years ago
you would have to route your website through your router to get an exteranl ip and a web cam could be a possibility but i haven't looked into it yer
I like it, how many channels can you control? I see you have it set up fro three right now.
willq44 (author)  amandaghassaei2 years ago
yes, three. The remote control has 3 channels. If your contrller has more, you can add more channels to the app simply by adding more lights to the database (there is even a button in the app to do it)
_soapy_ willq442 years ago
You could easily add a second remote on a different frequency or coding, and wire that in in the same way.
rab10792 years ago
Update: I did some digging around and found that there is a much newer version of RPi.GPIO, so I installed it and it appears to work - or at least it doesn't crash and the buttons change colour. I have yet to connect anything to my Pi. Just replace the commands on Page 7 of this tutorial with the following:

wget http://pypi.python.org/packages/source/R/RPi.GPIO/RPi.GPIO-0.4.2a.tar.gz
tar zxvf RPi.GPIO-0.4.2a.tar.gz
cd RPi.GPIO-0.4.2a
sudo python setup.py install

Then run the Server as before:

sudo python /home/www-data/web2py/applications/Home_Lights/modules/GPIOServer.py
willq44 (author)  rab10792 years ago
Yes it should work but I haven't been able to update the post yet thank you for your help. I have been in a bit of a lul until I saw that my instructible was in an article.
miles.frain2 years ago
This is a great tutorial!

One discrepancy I noticed while following along is that for the downloadable application was renamed from "Home_Lights" to "Lights". The change affects the following:

The application homepage is now found at:

The GPIO server script is now started with:
sudo python /home/www-data/web2py/applications/Lights/modules/GPIOServer.py

The index file ( /home/www-data/web2py/applications/Lights/views/default/index.html ) needs to be modified to point to the new locations of the on/off images. For example:
willq44 (author)  miles.frain2 years ago
I have found that only when you download the application it proves as a problem but for me it is the same
alfista26002 years ago
Hey man - Thanks for the tutorial. I've been back several times trying to do something similar, but I am much less skilled with electronics - better with software. I got a three outlet wireless remote set. The remote controls three outlets independently with six buttons. I've determined which leads on the microcontroller trigger the signal. It is battery operated with a 12v battery which puts out 15ma I believe (not great with a multimeter yet either). Do you have any advice as to if this is possible to control with the GPIO pins without a relay, and if so, what resistor config I would need to make it send the proper signal?
willq44 (author)  alfista26002 years ago
I haven't been able to update the instructable yet but I will be soon but based on what you have said. You could probably just connect the a wire from the pie to the input into the micro controller with power to the board with the battery. I hope this answered you question if any more just ask.
skelly192 years ago
Great article. I am having trouble figuring out my remote, could you lead some assistance. There are 5 channels on the remote, each controlled by a push button(non locking). Hit the button once it goes on hit it again it goes off. How can I wire my raspberry pi into this. I have included a picture of the back. Right above the R13 is one of the buttons. Any help would be greatly appreciated.
Here is the picture
2013-03-02 18.33.03.jpg
skbeez2 years ago
I get the same error as kaveh80 and rab1079... any help would be greatly appreciated.

... RPi.GPIO.InvalidDirectionException
rab10792 years ago
I have the same problem as kaveh80 - when I click on button I get the error listed below. I'm new to this and don't really know where to start looking, so would be grateful for any help.

pi@raspberrypi ~ $ sudo python /home/www-data/web2py/applications/Home_Lights/modules/GPIOServer.py
waiting for connection...
...connected from: ('', 35556)
Traceback (most recent call last):
File "/home/www-data/web2py/applications/Home_Lights/modules/GPIOServer.py", line 39, in
ret = gpio_setup(data[1:])
File "/home/www-data/web2py/applications/Home_Lights/modules/GPIOServer.py", line 13, in gpio_setup
File "/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.2.0-py2.7.egg/RPi/GPIO/__init__.py", line 94, in setup
raise InvalidDirectionException
freakqnc2 years ago
Congrats on the project... interesting way to solve your issues and thanks for introducing Web2PY to those of us who didn't know about it...

Problem for me is that this won't be applicable to a stand-alone system as in my case internet access is unavailable :(

The stand alone system would:
- have a ras-pi would running LAMP server
- have a minimal PHP/MySQL based authentication system
- have the ras-pi be connected to a router via wired connection
- have a relay module connected to the ras-pi's GPIO
- allow access to wifi devices (phones/tablets/etc) connecting to router
- let users connected to protected WLAN, access the web server
- serve a main page where upon login, will let users control a relay module

While the LAMP and connection of router and relay module poses no huge issues, the little web app that would need to be to trigger the proper GPIO output is a bit more difficult as I PHP doesn't come functions capable to interface natively with a system's GPIO so will have to be researched and made ad-hoc with a little help from the community out there :) (as I've found no ready to user free/commercial app yet).

Needless to mention that any and all help/suggestions addressing such an alternate case (stand-alone) would be very welcome and much appreciated, thanks! :)
kaveh802 years ago

I followed your instruction and I am getting error every time I try to turn on / off any of the lights. any suggestion?

pi@raspberrypi ~ $ sudo python /home/www-data/web2py/applications/Home_Lights/modules/GPIOServer.py
waiting for connection...
...connected from: ('', 54283)
Traceback (most recent call last):
File "/home/www-data/web2py/applications/Home_Lights/modules/GPIOServer.py", line 39, in
ret = gpio_setup(data[1:])
File "/home/www-data/web2py/applications/Home_Lights/modules/GPIOServer.py", line 13, in gpio_setup
File "/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.2.0-py2.7.egg/RPi/GPIO/__init__.py", line 94, in setup
raise InvalidDirectionException
Can you post exactly what hardware is needed to do this project and where I might purchase them?
willq44 (author)  biscuitbandit2 years ago
they are a general wireless remote and you local superstore like target will have them
is web2py a place made for GPIO RPI??
willq44 (author)  jackjackboom2 years ago
No it is not but I decided that if I could write and change my code any where in my house using a tablet or anything it would be very helpfull
Hello Friend, can you post more pictures of your circuit?
very thanks and great work!
willq44 (author)  bx16soupapes2 years ago
This was actually just a connecting board because I decided that if I ever wanted to add any thing this would be helpful
ben_b2 years ago
A nice, simple solution. The only change I would recommend is using an IC to protect your RPi from any interference / shorting from the remote board (especially if a mistake is made wiring it up.
Something like a CMOS 4016 (http://www.doctronics.co.uk/4016.htm) should do the trick nicely at negligible cost - just wire it up to be powered by the 3.3v out from the Pi and connect the GPIO to the enable pins. The switch pins function similarly to a relay and even if you burn one out the rpi should be isolated from the problem and the remaining switched on the chip will continue to work
I can't upload pictures from where I am at the moment but I'll drop a sketch of how do put the chip in if people are interested
willq44 (author)  ben_b2 years ago
I notices this about 5 weeks after and I added on but just forgot to updatenut thank you for reminding me
TexyUK2 years ago
the version of RPi.GPIO stated to install is very out of date and in any case, any recent versions of the Pi's Raspbian OS already has the latest version installed, so that stage is not needed.
Hope this helps,
willq44 (author)  TexyUK2 years ago
I have noticed this and this was the old version I have updated some of the software but all the code is very similar
a.streubel2 years ago
Hello willq44,
Thank you for your great and detailed tutorial.
I am trying to switch some relais. To do that i just need to put one gpio output high and low.
But unfortunately i dont know how i have to modify your code examples to do that (because you need inputs and outputs). Can you tell me what parts of your code i have to change to do that?
Thank you and goodbye
willq44 (author)  a.streubel2 years ago
In the database their is a spot to remove entry's just remove the two and if you look at the main code their is a spot that shows all the outputs of thr Rpi
Godrik2 years ago
Excellent! I think it will be my first test to take in hand my RPI. After I'll try to realize a thermostat managed with a web server.

very good work.
velankani2 years ago
can u tell me clearly ,which is the suiatbel controller
rmaldonado62 years ago
Just a couple days ago my brother and I were wondering about how to do something like this. Thank you willq44!
tarran12 years ago
This is great! Would it be possible to integrate this into something like Pushover (and hence IFTTT) so you can turn on lamps at sunset for example?
perdolis2 years ago
First of all, thank you, very nice!!!

I was trying to go the same following your manual... but I'm getting
[Errno 111] Connection refused when I try the app.

Any help?
xoanweb2 years ago
How can I customize ? I just create a new index.html , but I don't know where I have to upload it.

Please help !!!!
vlajkop2 years ago
Hi willq44,
In your second schematic don't you think that some electricity will be passed back to raspberry pi pins when buttons are pressed? Will that cause any problems with pi or if pins are switched to inputs can feedback be used to detect when button is pressed?
I like the use of the Pi here! I am doing a similar thing but have reverse engineered the protocol my outlets use and am implementing it on an ATTiny2313 with 315MHz transmitter from SparkFun. I have it hooked up to my home server/TV PC which is always on, but I've been looking for a way to control it remotely. I'll have to look into Web2Py, my coding background is in C/C++ and neither are great Web languages, but I've been learning Python and that could be quite useful. I would eventually like to integrate lights, webcams, possibly sprinkler system controller, and other stuff into one web interface off of my server or RasPi.