Author |
|
npavkov Groupie
Joined: February 29 2004 Location: United States
Online Status: Offline Posts: 91
|
Posted: October 12 2005 at 19:27 | IP Logged
|
|
|
Dave, I think I saw this in the forum before, but I can not find it now.......
How would I cancel a particular timed event????
I have a one shot event that under some conditions I would like to not execute it AFTER it has already been scheduled......How could I do this???
Thanks again for all your help.........Nick
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: October 13 2005 at 16:18 | IP Logged
|
|
|
You could do it a couple of ways...
First, you could just let the timed event occur and then check a global (or some similar flag) and if set, then just ignore the action.
Second, you can use the ph_directsql function to delete the timed event. You just have to be careful that you supply enough unique information so that you cancel just the timed event you're interested in.
The syntax would be something like:
ph_directsql("delete from timedevents where frequency = 0 and action = 'YOUR MACRO ID'")
Since you said it was a one shot, it will have a frequency of 0. This helps narrow down the events to only "one shot" events. I then included in the where clause where the ACTION was equal to the macro id that you created the event for (this of course is assuming that the timed event was for a macro type).
You could narrow it down even further by using the starttime if you knew what time it was going to fire.
Another way to make it even more reliable is to make sure that the action contains text that you can later reference. If we are going to assume you are calling a macro, then you probably used syntax similiar to the below to create the timed event:
ph_createtimedevent(0,"YOUR MACRO ID",180)
You could also achieve the exact same result with the following:
ph_createtimedevent(2,"/*DELETE ME*/ ph_macro('YOUR MACRO ID')",180)
The "DELETE ME" is within a comment so will not affect the formula which calls the same macro. You now however have created a unique signature for your timed event that you can use to get rid of it with direct SQL:
ph_directsql("delete from timedevents where action like '/*DELETE ME*/'")
HTH,
Dave.
|
Back to Top |
|
|
npavkov Groupie
Joined: February 29 2004 Location: United States
Online Status: Offline Posts: 91
|
Posted: October 13 2005 at 21:22 | IP Logged
|
|
|
thanks for your help again Dave.... Is it possible to cancel the FIRST occurrance of a macro named "test" in scheduled time order??
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: October 14 2005 at 14:36 | IP Logged
|
|
|
Nick,
No problem. The SQL code to delete the FIRST (earliest) occurrance of a timed event whose action is 'TEST' is:
delete from timedevents where action = 'TEST' and starttime = (select min(starttime) from timedevents where action = 'TEST')
Another possibility you may want to explore instead of Timed Events (Im not sure what you're trying to accomplish) would be waiting macros. There are a full set of functions available for controlling waiting macros and you can essentially achieve the same functionality of timed events.
For example, you can have a macro that is triggered based upon some action. This macro would use the ph_ismacrowaiting function to see if the macro is currently waiting. If not, then the macro waits a specified amount of time (say 3 hours). If the macro is again triggered within this 3 hour period, the ph_ismacrowaiting function would return true at which point you can extend the wait period of the currently waiting macro. Once the wait period is up, the macro can then perform the required actions. This way you don't get into the messy timed event deletes and creates.
HTH,
Dave.
|
Back to Top |
|
|
npavkov Groupie
Joined: February 29 2004 Location: United States
Online Status: Offline Posts: 91
|
Posted: October 14 2005 at 20:39 | IP Logged
|
|
|
Dave, that sounds pretty easy..... what I want to do is powerhome controls my outside lights. when the lights come on there is a timed event created to turn off the lights at say 11 PM and my son sometimes works late so when my son does not work late I want to turn the lights out at a 'normal' time (like 11 PM) but when my son works late I want to trigger PH to leave the lights on until a daily event that runs at say 2:30 am to turn off the lights.
does macrowait function allow other macros and triggers to run normally and is there some way to tell in a PH display which macros are waiting????? if I create a timed event then all I need to do is look at the timed event list to see the current scheduled times, so that would easily show me the 'one shot' timed event is scheduled to turn off the lights.....
your input and recommendations are greatly appreciated.....
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: October 22 2005 at 21:57 | IP Logged
|
|
|
Nick,
Sorry to take so long getting back to you .
Yes, macro wait allows all other events, triggers, etc. to run normally. It does not in halt processing like a delay statement.
You can see a list of waiting macros in the PowerHome Status screen.
Let me know if you have any questions and I'll help you out.
Dave.
|
Back to Top |
|
|