Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome General
 PowerHome Messageboard : PowerHome General
Subject Topic: Global var insight needed Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
logbuilder
Newbie
Newbie


Joined: February 03 2009
Location: United States
Online Status: Offline
Posts: 22
Posted: February 21 2009 at 01:50 | IP Logged Quote logbuilder

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 View logbuilder's Profile Search for other posts by logbuilder
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: February 21 2009 at 09:01 | IP Logged Quote TonyNo

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


Joined: February 03 2009
Location: United States
Online Status: Offline
Posts: 22
Posted: February 21 2009 at 17:56 | IP Logged Quote logbuilder

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 View logbuilder's Profile Search for other posts by logbuilder
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: February 21 2009 at 22:54 | IP Logged Quote TonyNo

You got it, but there is only one waiting macro of a given name.
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo'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