View unanswered posts | View active topics It is currently Tue May 21, 2013 3:20 pm



Reply to topic  [ 10 posts ] 
 Help with script - Log devices in iCal Smart Home Hack #91 
Author Message
User avatar

Joined: Jun 14, 2006
Posts: 500
Post Help with script - Log devices in iCal Smart Home Hack #91
I use the following script taken from Smart Home Hacks #91 and put it in my Attachments folder. Then I set up a trigger to run anytime there is a X10 Command Received. I have the Trigger Action to run an applescript as embedded as "LogDevice(device_name_from_my_device_list" When I try to run the script I get "The variable device_name_from_my_device_list is not defined. Can anyone help me? Thanks in advance!

using terms from application "Indigo 2"
on LogDevice(DeviceName)
tell application "IndigoServer"
log "Log Device: " & DeviceName
if (name of device DeviceName exists) and (description of device DeviceName does not contain "future") then
set eventdate to current date
set UnitDisc to description of device DeviceName
set UnitType to description of device DeviceName
set unitState to on state of device DeviceName
set theNote to "" --optionally put a note here based on other variables
set theLocation to UnitType & " " & UnitDisc

LogInCal(UnitType, DeviceName, theNote, theLocation, eventdate, unitState)
end if
end tell
end LogDevice
--end using terms from

on logmessages(MessageGroup, message, EventKind)
set MinSummaryLength to 5
set theLocation to "Message"
set eventdate to current date
if MessageGroupe contains "Messages" then set EventKind to false

set OldDelims to AppleScript's text item delimters
set AppleScript's text item delimiters to " "
set theList to the text items of message
set AppleScript's text item delimiters to OldDelims
set x to count of items in theList
if x is greater than MinSummaryLength then
set i to 0
repeat with n from 1 to x
set i to i + 1
if i is 1 then
set LogTemp to item i of theList
else
set LogTemp to LogTemp & " " & item i of theList
end if
if i is MinSummaryLength then exit repeat
end repeat
set LogTemp to LogTemp & "..."
else
set LogTemp to message
end if
LogIniCal(MessageGroup, LogTemp, message, theLocation, eventdate, EventKind)
end logmessages
end using terms from


on LogIniCal(theCalName, theSummary, theNote, theLocation, eventdate, EventKind)
tell application "iCal"
set CalList to (title of every calendar)
if theCalName is not in the CalList then create calendar with name theCalName
set TargetCal to (first calendar whose title is the CalName)

if EventKind is true then
--make new started event
make event at end of events of TargetCal with properties ¬
{start date:eventdate, summary:theSummary, description:theNote, location:theLocation, status:tentative}
else if EventKind is false then
try
set EventList to (every event whose summary is theSummary) of TargetCal
set TargetEvetn to (last item of EventList whose status is tentative)
if status of TargetEvent is tentative then
set (end date) to TargetEvent to eventdate
set status of TargetEvent to confirmed
end if
on error
make event at the end of events of TargetCal with properties ¬
{start date:eventdate, summary:theSummary, description:(theNote & " (no starting event found)"), location:theLocation, status:cancelled}
end try
end if
end tell
end LogIniCal


Fri Feb 23, 2007 4:12 pm
Profile

Joined: Apr 01, 2003
Posts: 823
Location: Rio Rancho, NM
Post 
Can you post the full log?

_________________
Greg In The Desert


Fri Feb 23, 2007 10:51 pm
Profile WWW
User avatar

Joined: Jun 14, 2006
Posts: 500
Post Help with script - Log devices in iCal Smart Home Hack #91
Hello - Thanks! I appreciate your assistance. There is not much in my log this morning so I reloaded the attachment scripts and select "run" in the trigger to run the LogDevice(espresso) to show you I get the script error: The variable espresso is not defined. Any info you need please let me know. I think this is a great hack and I'd like to get it working.

Regards,

Bob

I tried to run the script manually and I got;

Feb 24, 2007 9:24:35 AM
Trigger Action ical_events
Error script error: The variable espresso is not defined.

So I reloaded the attachment scripts and tried again;

Feb 24, 2007 9:25:40 AM
Loading attachments
"iCal.scpt" script loaded
"templinc attachment.scpt" script loaded
Error script error: The variable espresso is not defined.


Sat Feb 24, 2007 10:30 am
Profile

Joined: Apr 01, 2003
Posts: 823
Location: Rio Rancho, NM
Post 
What's in your trigger action? It should be set to execute a applescript that looks like:

Code: Select all
LogDevice("espresso")


espresso should be a device defined in your device list.

_________________
Greg In The Desert


Sat Feb 24, 2007 10:39 am
Profile WWW
User avatar

Joined: Jun 14, 2006
Posts: 500
Post Help with script - Log devices in iCal Smart Home Hack #91
Hello - Thanks again! I didn have the brackets around the device name so I changed it to LogDevice("espresso") as you showed in your last post but now I get the following error?

Feb 24, 2007 10:22:55 AM
Script Log Device: espresso
Error script error: IndigoServer got an error: Can't continue LogInCal.
Error error dispatching event to attachment script (-1753)
Error script error: Can't continue LogInCal.


Sat Feb 24, 2007 11:27 am
Profile

Joined: Apr 01, 2003
Posts: 823
Location: Rio Rancho, NM
Post 
I'm not sure that the heck that means. Make sure you have downloaded the latest version here.

_________________
Greg In The Desert


Sat Feb 24, 2007 1:15 pm
Profile WWW
User avatar

Joined: Jun 14, 2006
Posts: 500
Post Help with script - Log devices in iCal Smart Home Hack #91
Hello - Thanks so much!! I downloaded the latest version as per your link and now I am making progress. To start the logging I set a trigger;

TYPE: X10/RF command received
RECEIVED: ON
DEVICE: espresso

ACTION: LogDevice("espresso")

How do I stop the logging when the device "espresso" shuts off?


Sat Feb 24, 2007 3:06 pm
Profile

Joined: Apr 01, 2003
Posts: 823
Location: Rio Rancho, NM
Post 
It should only log once when the trigger is activated. When the device is turned on, it will create the event in iCal. When the device is turned off (and you need a trigger for when it's turned off) it will modify the ical event to show the length of time time event was on.

_________________
Greg In The Desert


Sat Feb 24, 2007 3:10 pm
Profile WWW
User avatar

Joined: Jun 14, 2006
Posts: 500
Post Help with script - Log devices in iCal Smart Home Hack #91
I'm almost there. I have a trigger TYPE: DEVICE STATE CHANGE, CHANGED TO: ON and DEVICE: espresso to run the LogDevice("espresso"). For some reason a TYPE:X10/RF Command received won't activate the script.

Also it only creates one Calenders named Appliance Module (AM14..

How do I create a diffrent Canander for eat itme I want to log?

Thanks again!


Mon Feb 26, 2007 2:14 pm
Profile

Joined: Apr 01, 2003
Posts: 823
Location: Rio Rancho, NM
Post 
The script is configure to put stuff in iCal based on what model the device is. If it's a X10 device, it looks at what model of device you have set when you edit the device. If it's a Insteon device, its hard coded.

If you want a different kind of calendar scheme, you will need to change the script.

_________________
Greg In The Desert


Mon Feb 26, 2007 3:05 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 10 posts ] 

Who is online

Users browsing this forum: IanLJ and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.   Template designed by STSoftware.