Canceling a delayed action in an Action Group

Posted on
Tue Jul 13, 2010 6:28 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Canceling a delayed action in an Action Group

I know this must have been asked before, but I can't seem to find it in the forum. So, here goes...

I have a trigger that monitors the state of my espresso machine and executes an AppleScript on any state change [If state is on then... else if state is off then...]. I now want to add a feature that will automatically turn-off the machine 60 minutes after it is turned on, and issue a warning 10 minutes before the turn-off time.

To do this, I created an action group with two actions:
Action #1 after a 50 minute Delay by, runs a script announces that the espresso machine will turn off
Action #2 after a 60 minute Delay by, turns-off the machine
Both actions have Override previous delay selected

The Action Group is executed in the If state is on then... clause in the monitor script.

So, each time I start the machine, the action group executes, If I do nothing, I should get a warning in 50 minutes and the machine should turn-off in an hour. If i turn the machine off, and then on again, the timers should reset.
This seems like it should work, though I have not tested it yet. But, if anyone sees a problem with this approach, please comment.

Now the part I am unsure of how to do. If I turn the machine off before the 50 minute announcement, I want the pending announcement, and the delayed turn-off, canceled. How do I do this in AppleScript? I know about remove delayed actions for device, and that would let me remove the turn-off. But, how do I remove the delayed AppleScript action? [remove delayed actions for trigger does not seem appropriate.]

Posted on
Tue Jul 13, 2010 6:46 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Canceling a delayed action in an Action Group

berkinet wrote:
Now the part I am unsure of how to do. If I turn the machine off before the 50 minute announcement, I want the pending announcement, and the delayed turn-off, canceled. How do I do this in AppleScript? I know about remove delayed actions for device, and that would let me remove the turn-off. But, how do I remove the delayed AppleScript action? [remove delayed actions for trigger does not seem appropriate.]

Actually, do try using for trigger with the original Trigger Action name (the one that catches the device state change). That should work. It is a bit confusing though -- the for device argument removes delayed actions that target a device, whereas the for trigger argument bases the removal on the originating Trigger (or Time/Date) name.

Image

Posted on
Tue Jul 13, 2010 6:54 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Canceling a delayed action in an Action Group

support wrote:
...Actually, do try using for trigger with the original Trigger Action name (the one that catches the device state change). That should work. It is a bit confusing though -- ... whereas the for trigger argument bases the removal on the originating Trigger (or Time/Date) name.
Ok, so you are saying that even if trigger A runs an AS that executes Action Group B, doing "remove delayed actions for trigger A will clobber the delayed actions of Action Group B.

Doesn't cost much to try ;-)

Thanks.

Posted on
Tue Jul 13, 2010 7:03 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Canceling a delayed action in an Action Group

And the verdict is... It didn't work as hoped. The announcement still executed. One note, the trigger is named "•Espresso Monitor" Is it possible that the bullet (•) is causing a problem? (I use it to control the sort order of some triggers).

Posted on
Tue Jul 13, 2010 8:23 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Canceling a delayed action in an Action Group

Bummer. It should have passed the root originator all the way down to the delayed action, but it sounds like that didn't work. I'll look into it. The bullet character shouldn't matter.

Image

Posted on
Wed Jul 14, 2010 8:16 am
eme jota ce offline
Posts: 618
Joined: Jul 09, 2009
Location: SW Florida

Re: Canceling a delayed action in an Action Group

Berkinet,

I'm hesitant to jump into this thread because my lurking around in the shadows of this forum has made it clear that you are at a much higher HA level than I'll reach as a non-programmer / common consumer, but I have a similar setup with a different approach that has worked well. It's based upon the timer script and several triggers that: (1) send me a Textie IM whenever an exterior outlet connected to a Sonos amp is turned on, (2) automatically turn that outlet off after 90 minutes, (3) but sends a warning Textie message to a phone 10 minutes before shutdown so that (4) I can text back an extension of 30, 60, 90, or 240 minutes.

I use four trigger actions as described below:

1. Whenever the outlet is first turned ON notify me (in case it was an accident so I don't bother neighbors) and set timer.
Trigger: Device state changed, "Balcony Sonos Outlet" On/Off State becomes ON;
Condition: Always;
Actions: Send Email (to my Textie account); Modify variable "TimerSonosBalconyOutlet" to 5400.

2. Set Timer variable back to 0 if outlet is manually turned off (I don't remember why I added the condition. It might be superfluous)
Trigger:Device state changed, "Balcony Sonos Outlet" On/Off State becomes OFF;
Condition: If variable "TimerSonosBalconyOutlet" is greater than 0
Action: Modify variable "TimerSonosBalconyOutlet" Set to 0

3.Send 10 minute warning to Textie account before shutdown (This condition is necessary, though. When manually turned off, the first trigger is to set timer variable to 0, which would then trigger the less than 600 trigger below if manually turned off with more than 10 minutes left on timer)
Trigger: If variable "TimerSonosBalconyOutlet" becomes less than 600;
Condition: If variable "TimerSonosBalconyOutlet" is not equal to 0;
Action: Send warning email to Textie account

4.Turn Off Sonos outlet when timer variable reaches 0
Trigger:Variable changed, "TimerSonosBalconyOutlet" becomes equal to 0
Condition: Always
Action: Turn Off light / appliance "Balcony Sonos Outlet"

Steps 2 and 4 probably result in the outlet being turned off twice in those instances where I manually turn it off via Indigo Touch, but it hasn't caused problems. It serves the main purpose of avoiding the 10 minute warning message when the device has already been turned off.

There are also a few other triggers based upon receipt of an email from my Textie account that merely add time to the timer variable to avoid automatic shutoff, but it's really those 4 trigger that work together that provide the functionality I needed. I hope it works for you.

Posted on
Wed Jul 14, 2010 9:44 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Canceling a delayed action in an Action Group

eme jota ce wrote:
...I'm hesitant to jump into this thread...
I'm glad you did. If Matt can't resolve the problem in the short term, you have given me an idea of way to solve it.

I can change my setup so that:

Trigger A will also set a state variable for the coffee machine to ON or off depending on the changed state of the machine.

Then change the action (which is in AS), to check the state variable when it executes 50 minutes later. If the Coffee machine is still ON, announce, otherwise exit silently.

Thanks!

Posted on
Thu Jul 29, 2010 12:12 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Canceling a delayed action in an Action Group

support wrote:
Bummer. It should have passed the root originator all the way down to the delayed action, but it sounds like that didn't work. I'll look into it. ....
Matt: Did you ever get around to testing this?

Posted on
Thu Jul 29, 2010 12:21 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Canceling a delayed action in an Action Group

Not yet, but it is on my list. It'll be a while though before I have the time to dig into it.

Image

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests