Code to Interface Your Home to Twitter

Home Connected to Twitter

Last week we interviewed Andy Stanford-Clark on his smart home integration with Twitter and now we have a document 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 via 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. Right 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 relies on the search engine, which parses and indexes every public message sent to Twitter. I could not poll 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:

#Copyright 2008 Justin Wickett
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the 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
#GNU General Public License for more details.
#You should 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 appropriate 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

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

1 Comment on "Code to Interface Your Home to Twitter"

  1. amazing.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.