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.
Remove these adsRemove these ads by Signing Up

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

Step 2: Web Server setup

I choose the Web2Py framework for it’s ease of installation and use.  Installation is very simple.  Follow the instructions (repeated here) at

Connect your R-PI to the internet. Logon to your R-PI and enter the following at the command line:

chmod +x
sudo ./

Follow the instructions on the screen.  This step will take several minutes and you may see some errors in the process, but it seems to work anyway.  The mail configuration is not really important, you can just set it as “no configuration”.  When asked about your location and such, the values aren't critical, do your best.  The most important thing is to remember the admin password that you select during the installation

Once the installation is complete you should be able to connect to web2py server from your computer.  In your computer's browser enter the address to your Raspberry Pi.  It is very important that you used https when connecting to the web2py server.  Your URL will look something like:  or  https://rasberrypi

You may see a security warning in your browser.  That's OK,  you can safely ignore this warning.  If everything worked correctly, you should now see the welcome page for Web2Py.

1-40 of 82Next »

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

lzkill2 months ago

Hi pals!

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

ManuelA32 months ago

In my case ,Installing web2py on a raspberry running raspbian, I had to modify a line on


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

KentR22 months ago

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

aswinmp2 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 &

OliverL3 months 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 :-(

RobertCrabb13 months ago

Nice Job!!

Very detailed guide.

GeorgeB13 months 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 "" 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:

Samginoya4 months ago


wen i write this in pi terminal :

sudo python /home/www-data/web2py/applications/Home_Lights/modules/

it show me:

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

[Errno 2] No such file or directory

BennyTC4 months ago

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

BennyTC4 months 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 file's line 13 to this:

ON = chr(0)

and added the following lines to the file

line 3:

import time

line 12:

SleepTimeL =2

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


cartiman6 months ago

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


sadhvi8 months 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.



losgat9 months 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?

sahildhanda9 months ago

Traceback (most recent call last):

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


File "/usr/lib/python2.7/", 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!9 months ago

cool introduction!

peecee7810 months 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

sivaraaj peecee789 months ago

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?

amrnablus9 months 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.

icemeth11 months ago

i have a problem in setting up the web2py setup. when i type sudo ./ 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

hughjeremy11 months 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!
ChronosWolf11 months ago
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, 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

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_fi1 year 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 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 :
_Yvan_1 year 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/", line 205, in restricted exec ccode in environment File "/home/pi/web2py/applications/Home_Lights/models/", 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
freakqnc1 year 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!
lribani1 year 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! :)
freakqnc1 year 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/

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

Thanks! :)
freakqnc1 year 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
freakqnc1 year ago
Well whaddayano... on mac there is a bit of an issue with the file

To begin with it downloaded as 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: 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 "" 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 file and selected "Extract here" from the contextual menu.... FINALLY! I got the file 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 ;)
freakqnc1 year 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! :)
1-40 of 82Next »