Author |
|
syonker Senior Member
Joined: March 06 2009 Location: United States
Online Status: Offline Posts: 212
|
Posted: December 08 2013 at 09:11 | IP Logged
|
|
|
Hi Dave and Clan,
I want to ask about what might be considered a *specific* "best practice" procedure (which I will below) but it occurs to me that having a "Moderated, Sticky, Best Practices" section where entries are screened and approved by staff and honed down to their simplest form (as in not 88 replies to get to the meat) might be valuable. Anything from "labeling techniques", to "best way to manage timed events", etc. Just a thought.
Alright, as for *my* question:
CURRENT: I don't really like having a "once every minute" timed event that runs a macro checking all of my "countdown timers" (such as sprinkler zones, garage egress lighting, motion sensor light zones, etc.). It just seems wasteful and prone to error.
QUESTION: Is there a better way or a "best practice" to use an event to set a timer, decrement it by minute, and fire a specific event related to the chain of that counter's having reached zero and then just top using cycles on PowerHome until the next time something "countdown timer" related occurs?
Thanks in advance for any advice,
-S
__________________ "I will consider myself having succeeded when my house becomes sentient and attempts to kill me."
><(((º>`·.¸¸.·´¯`·.¸><(((º>¸.
·´¯`·.¸. , . ><(((º>`·.¸¸.·´¯`·.¸><(((º>
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: December 08 2013 at 12:33 | IP Logged
|
|
|
Steve,
Great idea on having a "Best Practices" type section where replies are restricted. There is a lot of info on the forum but trying to find it is at best difficult. I'll do some thinking (or take suggestions) on the best way to implement.
Concerning your question...It sounds as if you've got a timed event that fires every minute. It runs a macro that decrements various counters and when a counter gets to 0, you perform some action.
If that is correct, a couple of ways come to mind that may work better. One would be when a countdown timer is initiated, you use the ph_createtimedevent or ph_createtimedevent1 functions to create a one time timed event for the countdown timer value. This way, each countdown would have its own specific timed event that only fires after the countdown has expired rather than every minute. If the countdown (timed event) needs to be modified after its been started, you can use the ph_modifytimedevent function to change the expiration datetime.
You needn't worry about having a lot of these onetime timed events as they don't consume any CPU since they're not actual timers.
Another option would be to use macro waits. When a "timer" needs to be started, a macro can be launched that performs a "wait" for a specified number of seconds. Waiting macros also don't consume CPU as internally they are treated similar to timed events. You could create a single countdown timer macro that will handle all your timer needs like below. The limitation with this type of macro is that you cant "extend" or modify the countdown.
Macro ID is TIMER
10 Wait ph_getvar_n(1,2) * 60
20 Formula Post ph_macro(ph_getvar_s(1,1))
Very simple. You would always call this macro with a ph_macroparm function. If you wanted a countdown timer for 5 minutes to run a macro called COUNTEXPIRE, you would initiate the timer with this formula:
ph_macroparm("TIMER","COUNTEXPIRE",5,0,0,0)
If you need to be able to modify the countdown after its been started, then you'll need a macro per type of countdown. Since I don't know your specific situation, I'll just an example with a macro ID of TIMER1.
10 Goto Label if(ph_ismacrowaiting("TIMER1") > 0,"EXTEND","NEW")
20 Label EXTEND
30 Formula Immediate ph_extendmacrowait("TIMER1",ph_getvar_n(1,1) * 60,0)
40 End Macro
50 Label NEW
60 Wait ph_getvar_n(1,1) * 60
70 Macro TIMER1EXPIRE Post
Still pretty simple. You initiate (or extend) the countdown timer with this formula:
ph_macroparm("TIMER1",5,0,0,0,0)
Read the help file for info on the ph_extendmacrowait function to determine the best method of time extension.
Let me know what you think.
Dave.
|
Back to Top |
|
|
syonker Senior Member
Joined: March 06 2009 Location: United States
Online Status: Offline Posts: 212
|
Posted: December 10 2013 at 05:04 | IP Logged
|
|
|
I will look in detail at the options above as soon as I can break away
from work long enough. Gimme a week or two.
I am leaning toward kicking off dynamic timed events via function calls.
Seems like a more clean approach
-Spencer
__________________ "I will consider myself having succeeded when my house becomes sentient and attempts to kill me."
><(((º>`·.¸¸.·´¯`·.¸><(((º>¸.
·´¯`·.¸. , . ><(((º>`·.¸¸.·´¯`·.¸><(((º>
|
Back to Top |
|
|
|
|