Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: Best Practices Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
syonker
Senior Member
Senior Member
Avatar

Joined: March 06 2009
Location: United States
Online Status: Offline
Posts: 212
Posted: December 08 2013 at 09:11 | IP Logged Quote syonker

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 View syonker's Profile Search for other posts by syonker Visit syonker's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: December 08 2013 at 12:33 | IP Logged Quote dhoward

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 View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
syonker
Senior Member
Senior Member
Avatar

Joined: March 06 2009
Location: United States
Online Status: Offline
Posts: 212
Posted: December 10 2013 at 05:04 | IP Logged Quote syonker

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 View syonker's Profile Search for other posts by syonker Visit syonker's Homepage
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum