Author |
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: April 20 2002 at 12:42 | IP Logged
|
|
|
I have macros that are triggered by motion detectors. It seems that the motion detectors transmit an On command every 10 seconds. I assume that PowerHome is queing up all these as triggers and that is why I am getting the light going on and off?
My macro checks a flag to see if the light was turned on manually before, then, if not, it turns it on, does a WAIT for 300, then, turns it off.
Any suggestions?
Thanks,
Tony
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: April 20 2002 at 21:33 | IP Logged
|
|
|
Well, I added a flag that does not let it hit my macro while it is already timing, but, is there a way to do this and re-trigger a timer (cancel the currect timed operation and start another one)?
Tony
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: April 21 2002 at 13:07 | IP Logged
|
|
|
Tony,
Im not sure exactly what you are talking about...its true that a motion sensor will continue to send on "on" command whenever it see's motion...approximately every 10 seconds. When it no longer sees motion, and the motion sensor timer times out, it will send an "off" command. Now with X-10, there is nothing wrong with sending multiple "on" or multiple "off" commands. If a light is on and an "on" command is issued, no effect...same with the "off" command. Im not sure exactly what effect you are trying to achieve. Im my setup, whenever the motion sensor sends an "on" command, a trigger fires and issues an appropriate "on" command for a light. If the motion sensor continuously sends an "on" command, my trigger continues to fire and send an "on" command. When the motion sensor sends an "off" command, a trigger fires and sends the appropriate "off" command to the light.
Now in reference to your second message about cancelling a timer...you can kill a timed event by using Direct SQL, but its messy. I think what you are trying to do is similar to what Ive done in the sample database which is detailed in the macros: PP K ALL, PALM PAD CONTROL, PALM PAD TIMER, and PP TIME EXPIRE. Basically what Ive done is when I need to start a timer, I check a global variable to see if a timer is already going. If this variable is 0, then I create a timed event (my timed event expires in 30 seconds) and set the global variable that I just checked to the time that the timed event should fire. Now if I get another trigger firing before the timer has completed, instead of creating a new timed event, I just set the global variable to when my timer should now expire (30 seconds). When the original timed event expires, it checks the global variable to see if its been updated with a new time. If it has, then a new timed event is created to expire when the global variable says it should. When the timed event expires and the global hasnt been changed, then the global is set to 0 so it knows that no timed events are pending. I know its not easy to explain but hopefully you'll get an idea of how to accomplish what you want.
If this hasnt answered your question, just let me know and I'll try again
Dave.
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: April 21 2002 at 16:44 | IP Logged
|
|
|
Thanks, Dave.
The first part has to do with my macro; I think I need to rethink it.
The second one (cancelling a timer) is just what I need; thanks for that.
Did you ever consider writing up a description of the sample DB you supply with PH? I bet all the answers are in there!
Tony
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: April 27 2002 at 09:49 | IP Logged
|
|
|
Reviewing the explanation on your timer code, it doesn't seem that you are actually cancelling the timer. Can you explain how to change the timer value, or, point me to a place I could look into it?
Thanks,
Tony
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: April 28 2002 at 23:39 | IP Logged
|
|
|
Tony,
You're correct...I dont cancel the timer. What happens is that the macro that is executed by the timer compares the current time with a time stored within a global variable. If the time in the GV is older than the current time then the GV is set to 0 and no new timer is created. If the time in the GV is not in the past, then the macro creates a new timed event to itself with the timed event set to fire at the time stored within the GV. The GV is updated by whatever event you're wanting to time. I'll try to break it down further...
The key to remember is that only one timed event is ever existing at a time. A global variable is used to control the timed event. Here goes...
1. A trigger fires based upon an incoming event. That trigger calls macro 1.
2. Macro 1 checks global variable 1's value. If its 0, then the time that the timed event should fire is stored within GV 1. Lets say its 30 seconds in the future. If the current time is 14:12:09 then the time stored in GV 1 is 14:12:39. A timed event is created to be executed at the current date with time 14:12:39. This timed event will fire Macro 2. If the value in GV 1 is not 0, then the time 30 seconds from now is stored within GV 1. A timed event is not created because one should already exist.
3. The timed event fires. It calls Macro 2. Macro 2 checks GV 1 and compares it to the current time. If the current time is greater than GV 1, then the macro sets GV 1 to 0 and performs its normal operation. If GV 1 is greater than the current time, then a new timed event is created for the time in GV 1. Macro 2 then terminates.
That should do it. If the trigger is refired before the timer times out, then GV 1 is just updated with the new time that the action should occur. Macro 2 compares this time and creates timed events one at a time until no more incoming triggers changes GV 1.
Let me know if its still not clear.
Dave.
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: April 29 2002 at 20:38 | IP Logged
|
|
|
Very interesting! That just makes me more confused about the effect that I get with lights going on and off! Based on your description, it should not happen!
Tony
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: April 30 2002 at 09:45 | IP Logged
|
|
|
Tony,
Export the triggers and macros associated with your problem and email them to me. I'll take a look at them and let you know what I find.
Dave.
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: April 30 2002 at 16:13 | IP Logged
|
|
|
Thanks, Dave!
|
Back to Top |
|
|