Twittering Your Home

by Gordon Meyer

Interest in the messaging service Twitter is clearly on the rise (see this Wall Street Journal article if you're not already familiar with it), and while most people are figuring out how to use Twitter for its intended purpose--social networking--I'd like to share a few notes on my more prosaic experiment of using it as part of my home automation system.

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. )

Why Twitter?

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.

Getting Started

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.

Implementation Details

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:

  1. Retrieves the message text from the Description field.
  2. Formats the message and Twitter login information.

  3. 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 & ""

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!


2007-03-16 14:21:29
You write:

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.

I think that in general this is the wrong approach. Instead of calling for people to stop using a potentially useful feature that seems flaky, get more eyeballs on that feature and soon enough the problems will be reproducible and shortly thereafter, fixed.

Interesting post otherwise, thanks!

Gordon Meyer
2007-03-16 14:30:30
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.
Gordon Meyer
2007-03-16 14:42:11
A nice overview of Twitter, by the way, can be found here:

Newbie's Guide to Twitter.

2007-03-16 15:48:19
This is a nice idea. I'm going to set it up so some servers that need occasional baby-sitting notify me by Twitter.
Jamie Thingelstad
2007-03-16 22:38:48
I've been doing this now for a while. See the my write-up for my robot at
Gordon Meyer
2007-03-17 07:17:15
Very nice, Jamie, some fun ideas there. Well worth checking out. Thanks for posting your URL.
Martin Stanhope
2007-03-18 02:28:40
A neat way to use this script would be with the excellent Proxi from Griffin.

With Proxi you could trigger the script by monitoring for example a Folder, Skype, Digg, an RSS feed, iTunes, speech, various remote controls, networks, wake up from sleep or even another Applescript etc.

Martin Stanhope
2007-03-19 03:32:48
Apologies for the broken link in the previous post. I should have been Proxi
2007-03-21 07:07:28
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.
Fun Florida
2007-03-30 09:52:54
Is there a way to add html tags into the twitter messages? To send links to friends.
Twitter Forum
2007-04-01 16:12:01
Funky stuff! We have linked to your article from the unofficial twitter forums.
2007-04-22 14:33:16
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.

Not sure what the problem is, but for some reason, cUrl does not resolve any host (even from my vista machine. anyone know if curl works with Vista? the curl site doesn't mention it anywhere and I'm wondering if I'm running into some strange command line / vista / UAC thing... any thoughts? is there an alternative to curl?