Applescripting iCal And Indigo
[Update 08/27/2004] My earlier attempts at scripting Indigo and iCal were good but I have greatly simplified the process. There are two functions as before:
- LogDevice(DeviceName) - Will automatically create the iCal event based on device parameters. Be sure to call this after you have changed the devices state.
- logmessages(MessageGroup, message, EventKind) - General message logging. For logging messages not related to devices.
[Update 06/19/04:] See this article on getting data from iCal.
[Updated 05/30/04] Here's the latest incarnation of my iCal logging script. I've changed it quite a bit. There's two ways to use it.
- Use LogDevice(DeviceName) for devices.
- Use logmessages(MessageGroup, message, EventKind) for non devices.
You set EventKind to true for the start of an event and EventKind to false for the end of a event. Or if you want to just do a single logging use false for EventKind. This version makes use of the built in iCal properties and filters out Motion Detectors.
Note: I use the description field pretty heavily and this script may require that you have the proper info there.
[Updated 4/19/2004] I had given up on my iCal logging script, but decided to give it another try with some serious updates. Here's what's new:
- It can track when a device is turned on and when one is turned off. If I turn on my living room lights at 5pm and turn them off 8pm it will show an event that starts at 5pm and ends at 8pm. It's a lot easier to to read this information in an iCal type interface then a log file.
- It does some cleaning up so if a device is turned on and Indigo never sees that it was turned off it will remove the event all together. This needs some work.
- It logs motion detectors different from "on/off devices".
- It uses the description field to determine what kind of device it is and what calendar to put it in. I'm pretty consistent with my descriptions which look like this: Switchlinc controlling a lamp in the living room.
There's still some things to fix so expect an update to this in the next few weeks as I have time to work on it.
One of the limitation of Indigo is its ability to control scheduled events. When ever you have an event that needs to occur at a specified time you get a Time/Date trigger. Say for example you want to have a motion detector turn on a light, you would set the motion detector to turn on the light when motion was detected then turn off the light after a specified amount of time. I'm doing this in my living room. But when I want the light to stay on I use a Palm Pad to keep the light on, at the same time I need to cancel any scheduled auto off triggers for that light. Indigo does give me the ability to disable any auto off triggers that are created by Indigo. But I would rather delete them. If I create my own auto off triggers there's no way for me to look through the triggers and delete them my what units they effect.
I started looking at iCal for my scheduling needs. iCal 1.5.1 has much better Applesciptablity specifily the ability to have files run as an alarm. Since I am no expert at Applescript I looked at what Applescript were already out there for iCal. I found the iCal Script Pack by Blank Rebel Productions. With this I was able to make a motion logging script. Basically every time a motion detector is tripped it creates a event under a calendar named for the motion detector. I can then go at look at iCal and see if/when there was motion during the day while I was gone.
This has worked out pretty well. Except I seem to be tasking iCal to its limits on my Lombard. I must have thousands of entries per calendar and right now I have 6 motion detector that log data to iCal. But it does work. I plan to do some other stuff with this data like predict how long lights need to stay on and output the data to a web page.
Next step was to use iCal to actually control the scheduled events. The idea was to have a script that created the file to be attached to the alarm. The Auto off script would be basic telling Indigo to turn off the specified unit. There would be a script to delete any existing scheduled events and finally a script to schedule the event.
The script was made after some help from the MacScripter.net BBS. But at this point it doesn't seem to work. First problem is the "File Alarm" doesn't seem to fire. It shows scheduled but I never see the applescript popup and run. Second problem is the file for the alarm is suppose to have a variable assigned in it that is the unit to be turned off. But for whatever reason the variable doesn't get assigned to it. This is probably due to some lack of understanding of Applescript on my part.
For now I'm giving up on this project. I've got my system mostly working like I want and I know the developer of Indigo is working to improve the indigo.


