Sending PROWL iPhone Alerts from XTension

Prowl is an excellent iPhone app that acts as a receiver for remote notifications. It comes with a plugin for Growl, so if you're already using that you can plug directly into it. I've never had too much luck getting Growl to reliably alert me due to it's interesting networking model so the real value to me in Prowl is that it has a direct API that we can talk to in XTension without ever having to go through Growl, or even having to have it installed.

app store link to purchase Prowl You'll first need to purchase the prowl app. XTension is not affiliated directly with Prowl we just love the app. Once you have the app installed you need to setup an account on his server. iPhone popup alerts require that they go through a centralized server and you use of the prowl server is included in the price of the app. Next you'll need to create an “API Key” that XTension can use to directly contact your iPhone which you can do on the prowl site's settings page

SO now you have a program that can receive the alert, a server through whom you can sent the alert, now you just need something in XTension that can start the process off. There are a couple of extra steps involved here to make sure that XTension isn't held out or slowed down by an unresponsive server or a slow network or a cable modem that someone unplugged. In order to make sure that no matter what XTension keeps going we need to offload the actual request to the server to a separate applescript applet. This is just an applescript program that runs as a separate app and not inside of XTension like the rest of the scripts.

You can download the script I use here:

prowl_helper.zip

To see the source just drag and drop it onto the script editor. You will need to cut and paste your API code you received from the settings page into this script. Where to put it should be clearly marked at the top of the code. Then just re-save the app.

Make a global switch to turn it on and off

Now you need a global switch to turn prowl notifications on and off. Perhaps you'll create a schedule to turn this off at 11pm or whenever you run your going to bed script, except when you're on vacation or away from the house or something like that. In any case it is very helpful to be able to turn them off easily without having to edit a script. I created a new pseudo unit and called it “Send Prowl Alerts”. The global script we're going to create in the next step checks that status before doing anything.

Make the global script to call it

Next you need a global script or an attachment handler to call from XTension. I used a global script. Create a new global script and call it “prowl” and cut and past the following code into it:

--prowl helper script to send prowl notifications to iPhone
 
on SendProwlNotification(ThePriority, TheEvent, TheDescription)
 
 
    --check the global switch before we do anything
 
    if (status of "Send Prowl Alerts") is false then
 
      --you've turned off alerts, so nothing will be sent, but we'll log it anyway
 
      write log "Prowl alert not sent: " & TheEvent & ": " & TheDescription
      return
    end if
 
 
 
 
	write log "sending prowl notification " & TheEvent & ": " & TheDescription
 
	ignoring application responses
		tell application "Prowl Helper"
			SendIntProwlNotification(ThePriority, TheEvent, TheDescription)
		end tell
	end ignoring
 
end SendProwlNotification

the ignoring application responses tag is important in that the network request can take several seconds even if it's all working perfectly, and quite a bit longer if things are hosed up and you dont want XTension to try to wait for it. That is why we did all the extra work to move it out to a separate script application.

Now actually send the alert

The simplest way to actually generate an alert is to call that script from the ON script or any motion sensor or any door or window or other sensor logging an event you want to send an alert for. For example in the ON script of the front door sensor you might put

tell xGLobalScript "prowl" to SendProwlNotification( 2, "Front Door Open", (current date) as text)

and at some time later, either almost immediately or quite a bit later depending on how backed up Apples servers are you'll get the tone, buzz and a message on your iPhone! In the case of this test alert it took almost 4 minutes to appear, but it's often almost instant. I hope Apple or AT&T or whoever is responsible for the slowdowns to get their infrastructure fixed up. I have the same problem when experimenting with other apps that serve up alerts so it's not limited to just Prowl.

Improvements for easy scripting, use a Group

The best way to manage lists of units or devices that send various alerts is via a group. This way units can easily be added or removed without having to mess with the scripts themselves. A group's ON script receives an event you can use anytime any of the units in the group change their value.

You can even customize the script to look up the current label assigned to the unit, so if you've assigned “open” and “closed” to the window/door units and motion, safe for the motion units they can send the appropriate text to the alert.

Create a group called “Prowl Perimeter Alerts” or whatever makes sense to you. Then in the ON script add a handler like:

  on GroupMemberChanged(TheUnit, TheValue)
 
	--only report ON's
 
	if (TheValue is greater than 0) then
            tell xGlobalScript "Prowl" to SendProwlNotification( 2, TheUnit, "was opened at " & ((current date) as text)
       	end if
 
end GroupMemberChanged

More Information

If you're more attached to Twitter than Growl or want to be able to follow your house remotely via a twitter client please have a look at Gordon Meyer's excellent article Twittering Your Home where he talks about getting his XTension system talking directly to twitter.

tutorials/prowl.txt · Last modified: 2009/09/26 13:53 by Gordon Meyer
CC Attribution-No Derivative Works 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0