Author |
|
logbuilder Newbie
Joined: February 03 2009 Location: United States
Online Status: Offline Posts: 22
|
Posted: February 21 2009 at 01:50 | IP Logged
|
|
|
Ok. Now I'm working on the macro that turns on lights when motion detected on cameras.
I've got the lights turning on when motion is detected.
What I want to do is turn off the lights after 10 minutes of no motion. As long as motion is being detected, it is going to keep firing my macro. Eventually, all motion will stop and there will be one last execution of the macro.
Here is what I'm thinking.
In the macro,
issue a turn on lights command.
Increment a global variable by 1
wait 10 minutes
decrement global var by 1
if global var < 1
turn off lights
exit
else
exit
By testing this var, if multiple macros have fired due to motion continuing for some period of time, none will turn off the lights till the last one ends.
So given the above, I am unclear on a few things.
First, how to create and initialize the global var.
Second, how to increment/decrement
Third, how to test.
Fourth, what syntax for these commands.
I know I'm asking questions that have been asked many times before but I can't seen to find any good doc. I've searched the forum for these types of answers but haven't found them.
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: February 21 2009 at 09:01 | IP Logged
|
|
|
Answering your questions...
1. GV's are created in Setup, Global Variables. Right-click, insert, type the name, tab over, then enter an initial value.
2. increment/decrement
set global | ID | "{ID}" + 1
set global | ID | "{ID}" - 1
or
formula | ph_addtoglobal( "ID", value )
where value = +/- 1
After lots of fiddling, all my motion-based macros now look like this...
if light is on, then extend wait, exit
if off, then turn on, initiate wait
if wait done, turn off light
key commands: ph_ismacrowaiting, ph_extendmacrowait,
|
Back to Top |
|
|
logbuilder Newbie
Joined: February 03 2009 Location: United States
Online Status: Offline Posts: 22
|
Posted: February 21 2009 at 17:56 | IP Logged
|
|
|
Tony,
I think I agree that your logic is the best. I have coded it but am having problems with ph_getinsteonstat as you will see in another note I posted. Other than that, I think I am pretty close.
My understanding is that ph_extendmacrowait will add to the wait of the oldest macro of that name that is running. Right?
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: February 21 2009 at 22:54 | IP Logged
|
|
|
You got it, but there is only one waiting macro of a given name.
|
Back to Top |
|
|
|
|