macdevcenter.com
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Macintosh Home Monitoring
Pages: 1, 2, 3

Baby Steps

Let's get back to our example. Next you're going to tell XTension to run an AppleScript when it receives an On command from unit C14, which is your motion detector. To enter this script, select the motion detector in the Master List window, then choose Edit -> Edit Unit. In the Edit Unit dialog that appears, click the Edit button next to the On Script label.



XTension uses AppleScript for its programming language, so you can pretty much trigger any automated task that tickles your fancy. I use the Create New Message script from Apple to send an email to my cell phone's email address. You just need to change the script to customize the message and specify the details of your email account.

If you're less handy with scripting, fire up Automator and create an application that sends an email, then use the On Script to "tell application Finder" to open the application you created.

Regardless of where you get your script, paste it into the XTension editor window, then click Check Syntax to make sure it compiles successfully. To test your script you can simulate an On command from the sensor by double-clicking the unit in the Master Unit List window. If all goes well, you'll get the message on your cell phone. Bask in your success!

Getting Smarter

Eventually you'll discover that this simplified setup has some drawbacks. As mentioned earlier, the motion detector sends an On signal every few seconds while motion is still being detected. This means you'll soon overflow your mailbox if the detector is in a busy area. Additionally, the way it's set up now, an email gets sent at all hours of the day, not just during the periods that you're really interested in monitoring.

Luckily, there are ways to address this. The simplest is to only run XTension when you want to receive the notifications. If XTension isn't running, the signals from your detector will be ignored. That works fine if you're confident that you'll remember to start XTension before you leave home. Sometimes, the simple approach really is the best.

However, if you want something smarter you can create a scheduled event so that signals are acted upon only during certain hours of the day. Scheduling is one of XTension's most powerful features, so this won't be tough at all.

Choose File -> New Event, and create an "Ignore Front Door" event as shown in Figure 3. This event executes every weekday at 6:30 p.m., the time you're normally home from work. Its action is set to "block" the unit Front Door Motion. Blocking means that while XTension will still receive the signal from the motion detector (there's no way to stop the sensor from sending the signal), the signal will be ignored and the email script will not run.

figure 3
Figure 3: An event that ignores the motion detector

Similarly, create a second event called "Watch Front Door" whose action unblocks the unit in the early afternoon, or whatever times you want to watch for motion. With these two events, you've created a window in time during which you'll be notified of the motion at your front door.

If you find that a time window is too inflexible, here's another option. Create a pseudo-unit (it's like a variable) whose value determines if the email will be sent. For example, create a pseudo-unit called "Out Of The House" and turn it On, with a mouse click, when you leave the home. In your mail script, check to see if the value of Out Of The House is On, and if it is, send the email.(See the XTension user's guide for more about pseudo-units and checking the state of other units in a script.)

Doing More

If you're not using XTension, this approach is easy to adapt to other home automation software. The concepts of scheduled events and triggering scripts in response to sensors are core to all of the packages discussed. Just start simple, celebrate your early successes, and carefully build a more complex system as time and needs arise.

Now that you're familiar with home automation scheduling, you might find some other uses for it, too. For example, I use XTension as my alarm clock, with different alarm times set for weekends and holidays, all handled automatically. Once you've got the concept, you might just keep doing more. I'm looking forward to hearing about where you end up.

Gordon Meyer writes and speaks about personal technology and instructional design from his automated home in Chicago.


Return to the Mac DevCenter