Twittering Your Home
by Gordon Meyer
Home automation enthusiasts, particularly those of the hobbyist bent, have come up with several clever methods of having their systems send them notifications of household events when they're away from home . For example, the home automation system might send a message to their cell phone when the kids arrive home after school, or when the UPS delivery person has left a package at the front door. (For more about the usual methods for doing this, and other examples, see my MacDevCenter article: Macintosh Home Monitoring. )
I've been experimenting with using Twitter for automated notifications, and so far I really like the advantages it provides over other techniques.
First, Twitter supports several methods of delivering messages (which are called "tweets" in Twitter-speak). A tweet can be received via SMS to your cell phone, via several instant messaging services, by visiting a web page, or by using specialized apps such as the terrific Twitteriffic.
The best thing about this flexibility is that the recipient chooses how they want to receive their tweets, and changing this setting is easily done "on the fly." The sender of the message doesn't need to know which delivery mechanism is currently active, it's all handled by Twitter. This simplicity is a boon for home notifications which typically either take a shotgun approach and send notifications to several places at once (home, office, and cell phone email), or try to guess (based on time of day or other data) what the best destination might be. Letting the recipient determine where they want to receive messages, at any given moment, makes delivery much simpler and more reliable.
Finally, Twitter has a simple HTTP-based interface for sending messages. Instead of having to script an email program, or an SMS utility, sending a tweet is as easy as having your home automation system open a URL.
My First Implementation
This is an example of a notification sent to me, from my XTension-based home automation system, indicating that someone has been on my front porch.
Here's how the same message appears on my personal Twitter web page:
When I'm away from a computer, I change my Twitter preferences to send tweets to my phone, instead. Twitter can also relay messages using iChat (AIM), GoogleTalk, LiveJournal, and Jabber but I've had mixed success with the reliability of delivery over IM systems, so I don't use those options.
You'll need two Twitter accounts. A personal account, for yourself, which you'll use to receive the messages sent by your home. If you want to receive messages via SMS and IM, you'll have to configure, and confirm, those details in your Twitter account settings.
The second Twitter account is for your home automation to use when sending the notifications. When you create this account, you will probably want to select the "protect my updates" option so that your notifications aren't available to the public at large. Then, add your personal account as a "friend" of the home's account so that you can receive the messages.
Here's how I currently have this working. Some of these details are specific to XTension, one of the home automation applications I use, but the concept is adaptable to other systems. (See Hacking the Hack, below.)
When a visitor comes to my front door, XTension receives a signal from a motion detector. (Readers of Smart Home Hacks will find the full details about how the visitor is detected beginning on page 271.)
The motion detector activity causes XTension to run a script that constructs a message telling me what happened, and copies the message to the Description field of a unit called "Notify Twitter." (This is one method of passing variables in XTension.)
In the example below, which shows XTension's Master List window, the Description of the Notify Twitter unit has been set by this script to "Somebody is at the front door!"
Next, the motion detector's script sets the value of Notify Twitter to "On," which causes the script attached to the Notify Twitter unit to execute. This script does the following:
- Retrieves the message text from the Description field.
- Formats the message and Twitter login information.
- Sends the message and login info to Twitter's status API.
Here's the script, which borrows some code from Tilman for using curl to send a Twitter status message:
set theMessage to description of me
set TwitterID to "yourID"
set TwitterPassword to "yourPassword"
set TwitterLogin to TwitterID & ":" & TwitterPassword
set TwitterStatus to quoted form of ("status=" & theMessage)
set results to do shell script "curl --user " & TwitterLogin & " --data-binary " & TwitterStatus & " http://twitter.com/statuses/update.json"
You'll need to enter the login and password for your home's Twitter account, as noted in the script.
Shortly after running this script, the message is delivered via Twitter, as illustrated earlier. It's a simple as that.
Hacking the Hack
There are several ways in which this script can be used and adapted. For example, I'm using a variant of it with PhoneValet, to send CallerID information when someone calls my office phone. (See Growling PhoneValet for a starting point if this interests you.)
If I had a security camera on my front porch, it's easy to imagine including a URL, in the tweet, that would lead to a snapshot taken at the time the motion was detected. Although, depending on the length of your URLs, you might need to utilize something like TinyURL to shorten it before sending. Twitter limits the size of tweets to 140 characters.
If you use Indigo, another Mac-based home automation application, the above script will work just a few modifications. Instead of passing the message text using the Description field, use an Indigo global variable.
If you use MisterHouse, an open source home automation application for Mac, Linux, and Windows, you'll need to adapt this technique only slightly, replacing the AppleScript portions with Perl.
I'm continuing to tweak and adapt the basic idea here to new applications, if you have a suggestion or enhancement, please let me know what you come up with. Thanks, and have fun tweeting!
Twitter can also relay messages using iChat (AIM), GoogleTalk, LiveJournal, and Jabber but I've had mixed success with the reliability of delivery over IM systems, so I don't use those options.
|Fair enough, William. I only meant that I can't comment on its usefulness, but I'd sure like to utilize it. I'm hoping your sentiment is correct. Thanks for posting.|
|A nice overview of Twitter, by the way, can be found here:|
This is a nice idea. I'm going to set it up so some servers that need occasional baby-sitting notify me by Twitter.
|I've been doing this now for a while. See the my write-up for my robot at http://www.thingelstad.com/2007/03/introducing-my-robot/.|
|Very nice, Jamie, some fun ideas there. Well worth checking out. Thanks for posting your URL.|
A neat way to use this script would be with the excellent Proxi from Griffin.
|Apologies for the broken link in the previous post. I should have been Proxi|
|Thanks for this Gordon. Based on the information here, I've been able to rig up Twitter as an alert relay for my Nagios Network monitoring application. It's easy to set up Nagios to use CURL to post its alerts into Twitter, and my colleagues and I can now enroll in Twitter and use Twitter functions to decide how we want to receive alerts (IM during the work day -when the IM interface gets mended-, and SMS out of office hours). Beats me having to edit Nagios config files to manage my support team's alert settings.|
|Is there a way to add html tags into the twitter messages? To send links to friends.|
|Funky stuff! We have linked to your article from the unofficial twitter forums. http://www.twitterforum.com|
LOVE the concept and am trying to get this working with mControl, my home automation software. Right now, I send email alerts, but would love to be sending tweets.