Introduction: Raspberry Pi WEMO Control Center
This project provides a webpage and automated interface for controlling Belkin's WEMO light switches and plug switches using the Miranda library.
At the end of the project you will have a webpage that can show real time state of all WEMO switches. Clicking the lightbulbs will toggle the state of the WEMO switch.
The backend sqlite database which stores the states of the WEMO switches can pave the way for all kinds of automated triggers including turning switches on/off at sunset or sunrise as shown in the last step.
Step 1: Setup WEMO Switches and Plugs
The only two devices which work with this project are Belkin's WEMO Light Switch and Belkin's WEMO Plug; all other WEMO devices are unsupported at this time, mainly because full automation is available via this app without the need for the WEMO motion sensors etc.
Record the MAC addresses which are physically printed on each of the switches/plugs and use those MAC address to setup a static IP address for each WEMO device on your Wireless router.
Note: the process for configuring a static IP address is going to be different on each router.
Once static IP assignment has been setup for the WEMOs proceed to setup your WEMOs via manufacturer recommended WEMO app for IOS or android.
Step 2: Install Raspbian on Your Raspberry Pi
Download the image provided here -->
https://www.raspberrypi.org/downloads/raspbian/
Follow the instructions to install the image and get your raspberry pi booted which is outside of the scope of this document.
Step 3: Setup Apache to Execute Python Scripts
Install the following dependencies:
sudo apt-get install apache sudo easy_install pip sudo pip install pip --upgrade sudo pip install peewee
Read the document here:
https://docs.python.org/2/howto/webservers.html
Confirm that your apache installation can handle python scripts by referencing the sample script at the link above.
The CGI-BIN directory used to place your test python scripts can be found at "/usr/lib/cgi-bin" on Raspbian, Debian, and Ubuntu systems.
Note: this part can be tricky in some cases. There are some good suggestions in the comments.
Step 4: Download GitHub Code
If you do not have GIT installed already, install it with:
sudo apt-get install git
Then download the code using:
git clone https://github.com/ericpulvino/wemocontrol
Make sure all python files are executable with:
chmod 755 ./wemocontrol/*.py
Step 5: Configure WEMO Information
Edit the top of your ./wemo_backend.py file to setup a storage location for database and also make nicknames for your WEMOs and their IP addresses.
db = SqliteDatabase('/home/pi/wemocontrol/database.db') # IP address, shortname (for internal references), Long Name (For Display) wemos = [ ("192.168.1.6","driveway","Driveway"), ("192.168.1.7","kitchensink","Kitchen Sink"), ("192.168.1.8","musicroom","Music Room"), ("192.168.1.9","frontporch","Front Porch"), ("192.168.1.10","backporch","Back Porch"),]
Note: You should have already setup your WEMOs to have static IP addresses that do not change
Run the following commands to setup the database and populate it with some initial values:
python ./wemo_backend.py ./send_wemo_commands.py multiupdate
Execute the ./wemo_backend.py file, this will create and initialize the backend database at the specified location while the next command will update the database with the state of each of the switches.
Step 6: Setup WEMO Control Center Website
Place a symbolic link to the wemo_control2.py file in your cgi-bin folder:
sudo ln -s -T /home/pi/wemocontrol/wemo_control2.py /usr/lib/cgi-bin/wemo_control2.py
Step 7: Browse to Website
Access Pi's website at:
http://[IP of Raspberry Pi]/cgi-bin/wemo_control2.py?key=raspi123
Confirm that control of the WEMO switches is possible by clicking on various lightbulbs.
Yellow means switch is On.
Black means switch is Off.
Red means that switch state cannot be determined.
Note: The webpage is refreshed periodically. Combined with the crontab on the following instruction the website will be refreshed to reflect the freshly collected state of the WEMO switch.
Step 8: Optional: Setup Automation
Setup a Crontab to update state of various WEMOs at your interval of choosing.
My sample crontab is provided below.
----------------------------- ### SAMPLE CRONTAB ### -----------------------------
# m h dom mon dow command ################################## #Update WEMO States (Every Minute) ################################## * * * * * /home/pi/wemocontrol/send_wemo_commands.py multiupdate
############################### #TURN ON and Failsafes (For Power Outtage) ############################### #00 16 * * * sunwait sun down 34.918917N 79.455301W && /home/pi/wemocontrol/send_wemo_commands.py frontporch.on kitchensink.on driveway.on 00 21 * * * /home/pi/wemocontrol/send_wemo_commands.py frontporch.on kitchensink.on driveway.on 00 18 * * * /home/pi/wemocontrol/send_wemo_commands.py frontporch.on kitchensink.on driveway.on backporch.on musicroom.on 00 00 * * * /home/pi/wemocontrol/send_wemo_commands.py backporch.on
############################## #TURNING OFF (and failsafes) ############################## 30 1 * * * /home/pi/wemocontrol/send_wemo_commands.py kitchensink.off 00 5 * * * /home/pi/wemocontrol/send_wemo_commands.py frontporch.off kitchensink.off driveway.off backporch.off musicroom.off #00 4 * * * sunwait sun up -0:15:00 34.918917N 79.455301W && /home/pi/wemocontrol/send_wemo_commands.py frontporch.off kitchensink.off driveway.off backporch.off musicroom.off
You may notice above that I occasionally make calls to a program called sunwait; this program takes latitude and longitude coordinates as arguments and can calculate the sunrise/sunset and a whole slew of other important times given the a date and location. I am using the original version hosted here.:
https://www.risacher.org/sunwait/
This can be very easily downloaded and compiled for the Raspberry Pi with the following commands.
wget https://www.risacher.org/sunwait/sunwait-20041208....
sudo apt-get install build-essential
tar -zxvf ./sunwait-20041208.tar.gz
cd ./sunwait-20041208/
make
sudo ln -s -T /home/pi/sunwait-20041208/sunwait /bin/sunwait

Participated in the
Raspberry Pi Contest
29 Comments
6 years ago
They will not let me retire this article. It is very out of date. Self support only :(
6 years ago
Hi, i can run :
/cgi-bin/wemo_control2.py?key=raspi123
but when i click on WEMO icon i get a ""Internal Server Error"" on this url
/cgi-bin/wemo_control2.py?key=raspi123&allof=0
any advice ?
Reply 6 years ago
Did you ever figure it out? I have the same problem...
Reply 6 years ago
Hi, no i didn't, let's keep in touch... Maybe it can come from the WEMO connection not the program.
8 years ago
I am getting the following error:
sudo python ./wemo_backend.py
Traceback (most recent call last):
File "./wemo_backend.py", line 222, in <module>
db.connect()
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3268, in connect
self.initialize_connection(self.__local.conn)
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3185, in __exit__
reraise(new_type, new_type(*exc_args), traceback)
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3266, in connect
**self.connect_kwargs)
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3485, in _connect
conn = sqlite3.connect(database, **kwargs)
peewee.OperationalError: unable to open database file
##########################
Please help with this error as I am a novice programmer with python.
Waiting for replies...
Reply 8 years ago
Inside the wemo_backend.py file there is a location specified for the database file.... this location may not exist on your box. I would modify this to wherever you would like to store the database. You could try the location I specified below.
#old location
/home/pi/scripts/WEMO/database.db
#New location
/home/pi/wemo_database.db
Reply 8 years ago
This worked!! TY :)
The database has been created now but, 403 forbidden error is given by server..
ERROR MESSAGE:
*************
FORBIDDEN
You dont have permission to access /cgi-bin/wemo_control2.py on this server.
Apache/2.2.22 (debian) Server at 192.168.0.103 Port 80
***********************
Is it because of any errors with Apache ?
I was able to see the test page at the initial step..
seems like I need your help again ..
Reply 7 years ago
bro....could you please tell me how did you solve this permission issue for wemo_control2.py? which you have mentioned here...thanks in advance
Reply 7 years ago
Did you ever fix this issue? I have this issue too and have not found how to fix it. Ridiculous that there's no one who knows how to fix it...
Reply 7 years ago
Basically it is a permission issue.I am now suggesting you a step which worked for me.
1.Instead of giving symbolic link to the wemo_control2.py file in cgi-bin folder in step 6,copy and paste the entire files in the home/wemocontrol folder to usr/lib/cgi-bin folder.This fixed the permission issue for me.Thanks!!
Reply 8 years ago
This is an issue with your apache configuration, visit the link in step 3 to fix your apache config.
Reply 8 years ago
<class 'peewee.OperationalError'>Python 2.7.3: /usr/bin/python
Tue Oct 20 18:30:37 2015
A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.
*******************
errors
**********************
<class 'peewee.OperationalError'>: unable to open database file args = ('unable to open database file',) message = 'unable to open database file'
#################################################################################################################################
This is the error page that comes when I am clicking the icons at the wemo webpage. I am attaching the screenshots of the error page. I thought its access issue for db and played with it. but cudnt figure it out.
Reply 7 years ago
I have the same issue, but I was only able to get that far when I started doing chmod/chgrp settings, etc. So here is my /usr/lib/cgi-bin:
pi@raspberrypi:/usr/lib/cgi-bin $ ls -l
total 8
-rwxrwxrwx 1 root root 171 Sep 11 00:50 testit.cgi
-rwxrwxrwx 1 root root 171 Sep 11 00:49 testit.py
lrwxrwxrwx 1 root root 37 Sep 11 00:40 wemo_control2.py -> /home/pi/wemocontrol/wemo_control2.py
pi@raspberrypi:/usr/lib/cgi-bin $ ls -ld /home/pi/wemocontrol/wemo_control2.py
-rwxrwxrwx 1 pi pi 3893 Sep 10 22:39 /home/pi/wemocontrol/wemo_control2.py
This works:
http://192.168.1.172/cgi-bin/testit.py
This doesn't:
http://192.168.1.172/cgi-bin/wemo_control2.py?key=...
Any ideas?
Thanks,
Scott
Reply 8 years ago
Have the same issue, where you able to resolve this?
Reply 8 years ago
Thanks @ericpulvino .. :)
Reply 8 years ago
My bad.. those errors where because of the permissions issue. I am good to go now. Thanks for your help once again :) Looking forward for more projects from you ..
Reply 7 years ago
I have a problem with this step
"python ./wemo_backend.py
I get this error
python: can't open file './wemo_backend.py': [Errno 2] No such file or directory
./send_wemo_commands.py multiupdate"
-bash: ./send_wemo_commands.py: No such file or directory
It seems that I have no database. Is it a SQL database I have to create?
Run Rasbian jessie
7 years ago
Hi,
I can't get the images to display. Everything else works but I'm getting a 404 not found for all of the images. Permissions and owner are all the same for all files in this project.
What directory should they be in?
Thanks.
7 years ago
This was really an amazing stuff.Big thanks@ericpulvino bro for this project...:)
Almost all the issues I have faced in this project were rectified via the comments section itself.
sudo chmod 777- Finally the most helpful command in the last step at last...ha..ha...if you give permission access Read,Write,Execute to all the folders involved in this project.you are easy to go....
If anyone knows how to integrate MySQL with this project to store the data and to view it in phpmyadmin?....kindly share the code and help in this regard.It will be really helpful for many.Thanks in advance.......
7 years ago
Step 1 says this:
The only two devices which work with this project are Belkin's WEMO Light Switch and Belkin's WEMO Plug.
The devices I have are WemoSwitch, i.e. Model Number F7C027.
Will that work?