Code to interface Your home to Twitter
last week we interviewed Andy Stanford-Clark on his smart home integration with Twitter and now we have a file published by computer science student Justin Wickett giving his open source script to do the same. read on for the code that gets your home communicating with you through SMS text message to your mobile plus all the other advantages Twitter offers.
“I only had to write a few lines of code to pull all of these technologies together so that they would work with each other. The following code is a very rough implementation that I originally used to test the feasibility of this idea. I plan on incorporating Bluetooth support as well as confirmation notifications once I get back to duke University. best now, I am using my cell phone to send Twitter public updates that are broadcasted out to all of my friends. This method is not secure, and spams your followers with updates about your electrical network’s condition. I recommend creating a private account for testing purposes, or better yet using Twitter’s direct messaging functionality.
Finally, this code depends on the Summize.com search engine, which parses and indexes every public message sent to Twitter. I could not poll Twitter.com because of rate limiting issues. My code polls Summize’s rest API (which is simply a web URL) every second checking to see if there has been an update. This polling method is not efficient and taxes Summize’s servers. I recommend subscribing to and parsing Twitter’s Pub Sub Jabber feed (see ). below is my quick and dirty Python code that can be easily ported over to other languages:
#/usr/bin/python
#Copyright 2008 Justin Wickett
#This program is totally free software: you can redistribute it and/or modify
#it under the terms of the GNU general Public license as published by
#the totally free software Foundation, either version 3 of the License, or
#(at your option) any later version.
#This program is distributed in the hope that it will be useful,
#but WITHOUT any WARRANTY; without even the implied warranty of
#MERCHANTABILITY or fitness FOR A particular PURPOSE. See the
#GNU general Public license for much more details.
#You ought to have received a copy of the GNU general Public License
#along with this program. If not, see <>.
import feedparser, os, time #The ‘feedparser’ library can be installed from
#TODO: replace the username as well as the INSTEON address with the suitable values
#TODO: also make sure that the path is correctly set in the system command to icmd’s path on your local machine
lastTweet = 0 #Used to keep track of the last Tweet received to make Summize queries less expensive
username = “xxxxxxxx” #Twitter username who is sending the commands to control the electrical network
insteonAddress = “xx.xx.xx” #INSTEON address of the device you want to turn on and off
while(1):
feedUrl = “”+username+”&since_id=”+str(lastTweet) #Polling Summize
feed = feedparser.parse(feedUrl)
if len(feed[‘entries’]) > 0 and feed[‘entries’][0].link.split(‘/’)[-1] > lastTweet:
if cmp(feed[‘entries’][0][‘title’], “Bedroom lights on”) == 0: #Check for the “ON” command
os.system(“icmd “+insteonAddress+” ON 255”) #Turn the lights controlled by my switch on
if cmp(feed[‘entries’][0][‘title’], “Bedroom lights off”) == 0: #Check for the “OFF” command
os.system(“icmd “+insteonAddress+” OFF 255”) #Turn the lights controlled by my switch off
lastTweet = feed[‘entries’][0].link.split(‘/’)[-1] #Save the last Tweet so we aren’t stepping over ourselves
time.sleep(1) #Sleep one second, and execute code again
Justin Wickett’s Site : follow Automated home on Twitter
Share this:
Facebook
Twitter
Reddit
LinkedIn
Pinterest
Email
More
WhatsApp
Print
Skype
Tumblr
Telegram
Pocket