View unanswered posts | View active topics It is currently Sat May 25, 2013 12:07 pm



Reply to topic  [ 12 posts ] 
 Trouble with Delay 
Author Message

Joined: Mar 22, 2009
Posts: 61
Location: Kingwood, Texas
Post Trouble with Delay
Not sure why the Applescript is not picking up the logic to test the state of a device. Seems to always trigger a false for the "on" state. I am assuming the last two insteon commands are from cleanup. The index on the device was 8. Any suggestions ?

Here is the applescript:

tell application "IndigoServer"
send insteon group instnTurnOn using name DeviceName
log "Send Insteon Command On"
delay 5.0
if (time date action ("_delayed_action_" & DeviceName) exists) then
delete time date action ("_delayed_action_" & DeviceName)
end if
if (on state of device DeviceName) = true then
set the value of variable DeviceName to "true"
--GrowlDevice(DeviceName)
else
log "Attempt Restart"
send insteon group instnTurnOn using name DeviceName
delay 5.0
-- test to see if it is running for the second time
if (on state of device DeviceName) = true then
set the value of variable DeviceName to "true"
log "GrowlDevice Command next"
--GrowlDevice(DeviceName)
log "GrowlDevice Command should have sent"
else
log "Pump did not start on 2nd attempt"
set theMessage to (DeviceName & " did not start")
Growl(DeviceName, theMessage)
end if
end if
set theDelayName to ("_delayed_action_" & DeviceName)
set DelayAction to ("FeaturesOff(\"" & DeviceName & "\")")
--display dialog theDelayAction
CreateDelay(theDelayName, DelayTime, DelayAction, "Script")
end tell
end FeaturesOn

Here is the Log

2010-10-11 18:00:00 Time/Date Action Pond Pump Timer
2010-10-11 18:00:00 Script Send Insteon Command On
2010-10-11 18:00:05 Script Attempt Restart
2010-10-11 18:00:10 Script Pump did not start on 2nd attempt
2010-10-11 18:00:10 Time/Date Action Check Weather Conditions
2010-10-11 18:00:10 Sent INSTEON "PowerLinc Interface" on (group/scene 8)
2010-10-11 18:00:10 Sent INSTEON "PowerLinc Interface" on (group/scene 8)


Mon Oct 11, 2010 8:54 pm
Profile

Joined: Mar 31, 2008
Posts: 739
Post Re: Trouble with Delay
See if adding "delay 2" at the beginning is helpful. I just completed a script to query and sum the brightness of some lights to set a control page variable. Didn't work until the delay was put in at the beginning of the script. Seems the script executes faster than Insteon returns the answer.


Mon Oct 11, 2010 9:03 pm
Profile
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 6667
Location: Austin, Texas
Post Re: Trouble with Delay
You know that the "with name" option of "send insteon group" isn't a device name but rather an INSTEON group name, right? Are you sure the light is actually coming on?

I think you may be confusing INSTEON groups and devices. Can you explain more what you're trying to do rather than just a code snippet?

_________________
Jay (Indigo Support)
Image


Tue Oct 12, 2010 6:51 am
Profile WWW

Joined: Mar 22, 2009
Posts: 61
Location: Kingwood, Texas
Post Re: Trouble with Delay
Jay,

Sorry the post was hasty and a bit incomplete. The DeviceName is the same as the group name. I am using the group command since I have multiple KPL's to sync with the device.

The first line of the script is missing On FeaturesOn(DeviceName,DelayTime). The intent of the script is to insure that the my multiple water features turn on during the day and turn off. I have a reliability issue with the backyard signals as the runs are fairly long. I set up a Time/Date Action for the group, use an embedded applescript..... FeaturesOn("Pond_Pump",30).

The log shows the script out ran the insteon commands ? which was why I put delay 5 after each send insteon group command.

This script was pushing my knowledge on applescript for sure.

Going to give hamw's idea a try. Thanks for the responses!


Tue Oct 12, 2010 7:38 am
Profile

Joined: Mar 22, 2009
Posts: 61
Location: Kingwood, Texas
Post Re: Trouble with Delay
Forgot to mention I tested the applescript if command to test for the on state and it worked fine as written which led me to the delay question ?

Jay, forgot to ask... What is the best way to reset the attachment scripts ? compile, save, run in applescript ? or do I also need to restart the server to load the new version also ?

Thanks


Tue Oct 12, 2010 7:48 am
Profile
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 6667
Location: Austin, Texas
Post Re: Trouble with Delay
Once you've saved the attachment script, select "Reload Attachments" from the Script menu and the server will reload them all - that should pick up the change.

However, this explains what you're seeing - if you're implementing this as an attachment, then the script is running completely before anything else is processing because embedded and attached scripts are run in the main event loop of the server (a requirement of AppleScript) - so nothing else is getting processed while the script is running including the actual sending of the group commands.

What you need to do is implement this as an external script - that will run it in a separate process and the group command will process immediately. The script will most likely run correctly that way.

_________________
Jay (Indigo Support)
Image


Tue Oct 12, 2010 7:58 am
Profile WWW

Joined: Mar 22, 2009
Posts: 61
Location: Kingwood, Texas
Post Re: Trouble with Delay
Explains why the send insteon group commands are processed after the script. Thanks for the tips on the attachment scripts.

Thanks

Will


Tue Oct 12, 2010 1:29 pm
Profile

Joined: Mar 31, 2008
Posts: 739
Post Re: Trouble with Delay
Jay, sorry for the dumb question, but to make an external script one just saves it in a folder and chooses that script name from the action window? This is in distinction to typing the script directly in the window?


Tue Oct 12, 2010 6:14 pm
Profile
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 6667
Location: Austin, Texas
Post Re: Trouble with Delay
Yep - in Script Editor just save it as a compiled script.

_________________
Jay (Indigo Support)
Image


Tue Oct 12, 2010 7:56 pm
Profile WWW

Joined: Mar 22, 2009
Posts: 61
Location: Kingwood, Texas
Post Re: Trouble with Delay
Last question on this I hope.... I am creating a delayed action with your CreateDelay script and need to use a linked applescript in the command instead of the embedded applescript in the code for the reasons above. Can this be done ? Can't tell for sure in the IndigoServer Dictionary in Applescript.

Thanks


Wed Oct 13, 2010 8:01 pm
Profile
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 6667
Location: Austin, Texas
Post Re: Trouble with Delay
Sorry, I don't know what CreateDelay is.

You can't create an action step of type Execute AppleScript file via AppleScript. You can, however, tell IndigoServer to execute a script file from an embedded AppleScript:

Code: Select all
execute script POSIX file "/path/to/script.scpt"


This will spawn an "osascript" process with the specified script file (which means it processes outside of the IndigoServer process) so it's safe to call from an embedded Execute AppleScript. Not sure if that helps or not though... ;)

_________________
Jay (Indigo Support)
Image


Wed Oct 13, 2010 9:06 pm
Profile WWW

Joined: Mar 22, 2009
Posts: 61
Location: Kingwood, Texas
Post Re: Trouble with Delay
Thanks Jay I can use the info.

Last night I decided to split the create delay from the "turn on, verify and notify" script and add another linked file to "turn off, verify and notify" and use the built in delay for the action item instead of trying to create delay within the first script. Little more convoluted but works great. For others info a brief summary of what I did to put closure to this.

I have a pond pump, pool waterfall, pool slide that need to run a timer schedule for maintenance.... Backyard long power lines, reliability questionable.

Created generic scripts for FeaturesOn and Features Off for any device.... FeaturesOn("Pond_Pump") to not maintain three identical scripts as I make improvements.

Pond Pump Example:
Created Time Date actions - Pond Pump Timer (run every six hours for 30 minutes for chlorination)
linked script - turn on Pump, verify on, if not resend command, growl if on or off to Ipad & Iphone (Pond Pump On script which simplify calls FeaturesOn)
linked script (delay by 30 minutes) - turn off Pump, verify off, if not resend command, growl if on or off to Ipad & Iphone (Pond Pump Off script which calls FeaturesOff)

Works great


Thu Oct 14, 2010 8:13 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 12 posts ] 

Who is online

Users browsing this forum: No registered users 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.