Author |
|
wasdvd Groupie
Joined: February 13 2007 Location: United States
Online Status: Offline Posts: 42
|
Posted: March 16 2007 at 09:29 | IP Logged
|
|
|
I am new to PH, and so am not good at programming macros yet.
My goal is to be able to use MS10A detectors with a W800RF32 receiver to activate PH triggers to turn Insteon lights on, and keep them on for a certain length of time after motion ceases.
I am attempting to use MS10As because the MS14A type detectors have been less than reliable sensing motion in the first place, and then sometimes failing to send the OFF command.
Since the MS10A sends only a motion detected signal (if I am correct), I have to create PH macros to do the time delay shutoff. The trick I need to add, is to extend the time delay if additional motion is detected before the first delay sends the OFF command.
I feel like possibly I could store the time the motion is detected in a variable, then loop to test that time + the desired delay to now(). If I could alter the motion detected time variable for a new motion detected event, while the test loop is running, I could extend the final OFF event.
I have read here about certain commands not allowing PH to process other events, so I would need to avoid those. But being new and ignorant, I am not sure what to use and what to avoid.
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: March 16 2007 at 12:36 | IP Logged
|
|
|
Here is what I have been using.
The motion detector fires a trigger that calls this macro...
Macro: FOYER MOTION
Jump if( ph_getinsteonstat("FOYER LIGHT") = 2, 2, 1)
Macro FOYER LIGHT ON
Jump if(ph_ismacrowaiting("FOYER MOTION") > 0, 1, 3)
Wait ph_extendmacrowait("FOYER MOTION", 300, 0)
Jump 999
Wait 300
Macro FOYER LIGHT OFF
|
Back to Top |
|
|
wasdvd Groupie
Joined: February 13 2007 Location: United States
Online Status: Offline Posts: 42
|
Posted: March 16 2007 at 14:04 | IP Logged
|
|
|
This is exactly the type of info I needed.
I will look up the function definitions tonight in PH HELP to understand each statement.
I am completely new to macros. I try to figure this out from PH HELP, but have not had the light go on for macros.
Are these lines entered as a new macro? Are these lines the complete macro, or just an extract? I understand that I would use my device instead of "Foyer Light". I am guessing that you have other macros defined as "FOYER LIGHT ON" and "FOYER LIGHT OFF". Is the colon in "Macro: FOYER MOTION" specifying the start of the new macro, and defining its name?
These are lots of ignorant questions to someone who understands macros already. Is all this available in PH HELP? If so, I will continue to plow through there.
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: March 16 2007 at 18:09 | IP Logged
|
|
|
No problem.
This is what you would select and type in to a new macro that you create. This is the complete macro. Yes, I have ON and OFF macros. I do this so that architecture changes down the road are easy to fix.
You may want to look at my short tutorial here.
Feel free to ask more questions!
|
Back to Top |
|
|
wasdvd Groupie
Joined: February 13 2007 Location: United States
Online Status: Offline Posts: 42
|
Posted: March 16 2007 at 20:55 | IP Logged
|
|
|
Thanks for your help. I have been following your adventures on this forum.
PH .10 must have different macro detail screens from your tutorial. I am still lost in the macro definition.
I set up a macro name in ph Explorer>macro
Then, in marco detail, I tried to enter the macro you supplied, specifying the first line as command "MACRO", and choosing the macro I named.
Then I tried to insert another line as command "Jump" with the if() you listed as the formula. I could not get the formula builder to close and keep the command. The formula field remained blank.
I appreciate your help so far, and solicit any more that you can do.
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: March 16 2007 at 21:38 | IP Logged
|
|
|
Whoops! The first line was just supposed to show that it was a macro named FOYER MOTION.
Here is the macro from PH...
Edited by TonyNo - March 16 2007 at 21:38
|
Back to Top |
|
|
wasdvd Groupie
Joined: February 13 2007 Location: United States
Online Status: Offline Posts: 42
|
Posted: March 16 2007 at 22:53 | IP Logged
|
|
|
Thank You, TonyNo!!
The screen shot helped me define my first macro!! and get a grasp on the subject.
I have had enough trouble with W800 output being scrambled in PH that it took a bit to test, but it works, including the delay.
As you can see, I am just getting going with the macros, with your help.
|
Back to Top |
|
|
Deano Groupie
Joined: February 19 2003 Location: United States
Online Status: Offline Posts: 75
|
Posted: March 17 2007 at 10:43 | IP Logged
|
|
|
TonyNo,
I don't know when this extendmacrowait came along but it sure beats the old create timed event and the secondsafter using a stored value of now(). No database hits should be faster overall.
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: March 17 2007 at 11:42 | IP Logged
|
|
|
Deano: Oh, yeah. Way better!
|
Back to Top |
|
|
wasdvd Groupie
Joined: February 13 2007 Location: United States
Online Status: Offline Posts: 42
|
Posted: March 17 2007 at 17:44 | IP Logged
|
|
|
TonyNo, Thank for your help. I am now into several macros successfully.
I did try to change your example to add a time-of-day test, which did not work.
If you have time and the solution, please give me another clue.
Original, which does work:
Jump if( ph_getinsteonstat("FOYER LIGHT") = 2, 2, 1)
Macro FOYER LIGHT ON
Jump if(ph_ismacrowaiting("FOYER MOTION") > 0, 1, 3)
Wait ph_extendmacrowait("FOYER MOTION", 300, 0)
Jump 999
Wait 300
Macro FOYER LIGHT OFF
My addition, which does not:
Jump if((hour( now() ) > 16 or hour( now() ) < 8) ,2,999)
Jump if( ph_getinsteonstat("FOYER LIGHT") = 2, 3, 2)
Macro FOYER LIGHT ON
Jump if(ph_ismacrowaiting("FOYER MOTION") > 0, 2, 4)
Wait ph_extendmacrowait("FOYER MOTION", 300, 0)
Jump 999
Wait 300
Macro FOYER LIGHT OFF
My thought was to exit immediately if daylight, and proceed to the original marco if not daylight.
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: March 17 2007 at 18:39 | IP Logged
|
|
|
The time check looks correct, but it looks like you omitted some lines as your jump values "don't line up". Double-check those.
|
Back to Top |
|
|
wasdvd Groupie
Joined: February 13 2007 Location: United States
Online Status: Offline Posts: 42
|
Posted: March 17 2007 at 19:04 | IP Logged
|
|
|
The issue is I don't know how the "Jump" instruction works. It may be in PH help, but using SEARCH and just looking through the various instructions, I have not located it.
I assumed that the two numerics were the line to which to jump, the first numeric the line, counting from the top of the macro, if the expression is true, the last numeric the line to jump to, counting from the top, if the expression is false.
Are the values relative to the line of the jump instead? If so, how do you jump backwards? A minus numeric?
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: March 17 2007 at 19:09 | IP Logged
|
|
|
OK, no problem. That's in the manual, not Help.
The Jump value specifies how many lines to jump from the current line, so a jump 2 would go down 2 lines. A jump -5 would go up 5 lines.
|
Back to Top |
|
|
wasdvd Groupie
Joined: February 13 2007 Location: United States
Online Status: Offline Posts: 42
|
Posted: March 17 2007 at 21:01 | IP Logged
|
|
|
More thanks.
Yep, I found that paragraph based on your suggestion. I had printed and read the manual first thing after buying PH, but did not relate to "JUMP" then.
Using the correct JUMP values, the macros with the time check work great.
Now if I can get W800 inputs to be deciphered correctly by PH, I have almost everything solved. The technique described in posts here somewhere about understanding the X10 Security codes works too.
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: March 19 2007 at 16:24 | IP Logged
|
|
|
Also, another method for transferring control to other macro lines are the "Label" and "Goto Label" commands. Sometimes easier to setup if you're doing a lot of branching and don't want to do the counting necessary with a Jump. A Jump is slightly more efficient and I prefer to use it when it's a simple jump a couple of lines like in Tony's code.
Just wanted to throw out another method since you're just starting your foray into macros .
Dave.
|
Back to Top |
|
|
wasdvd Groupie
Joined: February 13 2007 Location: United States
Online Status: Offline Posts: 42
|
Posted: March 19 2007 at 22:24 | IP Logged
|
|
|
Thanks for your help, and thanks for PowerHome.
While I thought I had programming experience, I am slow to pick up PH, so thanks to all for the clues.
Any suggestions on why the W800RF32A X10 RF inputs are sometimes (often) scrambled? Wrong unit codes, wrong command #. This is from a variety of devices.
|
Back to Top |
|
|
cmhardwick Senior Member
Joined: July 08 2006 Location: United States
Online Status: Offline Posts: 290
|
Posted: March 20 2007 at 07:56 | IP Logged
|
|
|
One reason to use Label and Goto Label, even if less efficient, is that you don't have to change values if you insert lines. Keeps you from recounting and possibly missing one even if you are editing your macro. Coming from other languages, I find it cleaner to use labels even if it involves an extra line of code per label vs jump.
__________________ Cicero, Enjoying automation!
|
Back to Top |
|
|