This is an Instructable to make a Twitter controlled Home Automation system for your house in less than 7$ (Rs.450). This tutorial includes setting up Python, Arduino as well as Twitter to build your very own Twitter controlled personal assistant.
The main reason I built this is to turn on the AC and mosquito coils in my room before I get home, so that when i come home, the room is already cooled and free from mosquitoes. But this implementation works for about anything.
Reason for the use of Twitter is because of an already existing twitter Android Wear app. This helps me to tweet by speaking into my watch. That basically means, I control my house talking to my watch!
Usually a home automation system of this sort would cost hundreds of dollars and still be not as good. In this project you will be able to control the appliances in your house right from your watch(if you have an android wear watch like I do).
Be sure to check out the video for an insight.
What goes in?
1) A micro-controller (arduino or arduino clone will do)
2) A laptop (Windows preferably)
3) A relay Shield (optional)
4) Android Wear Watch* (optional)
Step 1: Python Installation
Firstly you will have to download the TwitterHouse.zip file.
NOTE: The zip contains files ONLY FOR WINDOWS and no other operating system. Sorry. Based on your operating system you will have to download the equivalent individual files independently.
Check if you have python already installed on your computer by following the command prompt instruction below. If not continue this step.
Once you have downloaded and extracted the zip file, install python-2.7.9.msi
Open Command Prompt from search and type in "python" and click on enter. You should see that.
Step 2: Twitter Application
This and the next step are important steps where you link twitter to python.
To do so, you'll have to first create a Twitter account(if you don't have one).
Once you're done with that, head over to https://apps.twitter.com/ and hit on "Create New App". Type in a name(any name will do), description(doesn't have to be detailed) and website(any will do) and Create your Twitter application.
Now you go to Application setting and under Access level click on modify app permissions and change that to Read and Write, Update settings. Then click on the Keys and Access tokens tab and note down your Consumer Key and Secret. and scroll down to "Create my access token". Note down your Access token and access token secret as well.
Now you're all set with Twitter's Application Program Interface.
Step 3: Python Twitter Integration
Go back to the folder you had unzipped the downloaded file. And unzip the file tweepy-master.zip
Once you're done with that, open CMD(command prompt) again and navigate to the location of tweepy.
To enter a file, type "cd" and then the file name. and to go to root directory type "cd \".
Once you are in the folder tweepy-master where the file setup.py is located, type in "python setup.py install ". Once its done installing. Close cmd and reopen it. Type
once python is opened, type in
If you get ">>>" then you have successfully installed tweepy on your computer. Congratulations.
I suggest you install pyserial-2.7.win32.exe now as well. This you can just install like any other normal executable installation.
Step 4: Arduino Software Setup
In the same downloaded and unzipped folder(TwitterHome), run the installation of arduino. (arduino-1.6.0-windows (1).exe).
Once you're done installing the Arduino IDE, connect your Arduino using the USB serial cable and start the IDE. Select the board you are using and port it is connected on.
NOTE: I am using an Arduino clone and hence my drivers had to be installed separately. If you are also using a clone, download and install the respective drivers too in case it doesn't detect.
Take a note of this port as well.
Now open the file TwitterHome\python-tweet\python-tweet.ino in the IDE. Compile and upload the code to your Arduino.
Now you are done with the coding part of the Arduino.
You may reward yourself with a cookie.
Step 5: Python Coding
This is the part where you may go wrong the most number of times. But don't worry. I did too, because I had to write that code you will use.
Back to the TwitterHome folder, there are 2 files, homeautomationon.py and homeautomationoff.py
This tutorial will show you what to do in one of them and you will have to repeat the same steps for the other file.
So first right click on the file homautomationon.py and click on "edit with IDLE".
Once the editor opens, first thing you'll notice are the comments throughout the code. These comments(## change or ## change optional) are the lines of code you will have to edit based on your preferences and your configuration. The changes are pretty straight forward but in case you have any problems, feel free to comment below.
All the things I asked you to Note down earlier will come in handy now.
Step 6: Hardware
This is the step where you can tailor the hardware to suit your needs.
This step becomes very simple if you have an arduino Relay shield, if not you can make one like I did and use it. The trigger of the relay shield is to be connected to the pin programmed in the arduino program you uploaded to your microcontroller.
Attach the appliance to your relay shield like you would do if you were to put a switch in its circuit. The arduino doesnt drive the appliance but simply acts as an ON/OFF switch. After you're done wiring up the shield and the arduino connect it back to your computer.
Step 7: Watch Integration
This is the most fun and simplest step. Download Bunting on your phone and it should appear on your watch.
You are all set. :)
Step 8: Magic
Go to the python IDLE editor window that the program you have edited is in, and click on F5. You should see a new window pop up and it will display the contents of any tweet containing the keywords you have specified. When that keyword is detected, python will send a message via serial to your arduino to turn ON/OFF the appliance.
And now you can brag about your personal assistant on twitter. *drumroll* You can try it out by either tweeting on your watch (or any other device). When you tweet with the keyword, your PA will also tweet back to you based on the process undertaken.