X10 Community Forum

🖥️ActiveHome Pro => Plug-ins => Smart Macros => Topic started by: X10 Ken on February 14, 2009, 03:02:03 PM

Title: Macro screwed by second RF motion signal
Post by: X10 Ken on February 14, 2009, 03:02:03 PM
I have built a simple alarm system using macros, motion sensors, lights, and horns.  It works fine (as intended) if there is only one motion detected signal received.  However, if a second motion RF is received while the system is flashing the lights, the lights stop flashing.  I have a flag to stop the macro from running two copies at the same time but it still doesn't work.

I would greatly appreciate it if someone could tell me what is going on here.  Below are the three macros involved (with comments on what they are doing).

Macro #1 - Alarm Indoor-1 Motion
  Conditions
       O2 On and        // Motion sensor signal
       Flag Status On exactly 4 and  // Alarm in Armed Status
       Flag Status Off exactly 5     // Not currently alarming
  Set Flags [5] Flag Command    // Set Currently alarming
  (P11) Start O2 ON             // Phantom to just log start of macro
  (L2) Mini Alarm ON            // Turn on sounds
  (L3) Power Horns ON
  (L2) Mini Alarm ON
  (L3) Power Horns ON
  (L2) Mini Alarm ON
  (L3) Power Horns ON
  (P5) Flash Loop Phan 1 ON      // Trigger Macro #2
  Delay for 22 Seconds              // Time to leave alarms on
  (P5) Flash Loop Phan 1 OFF     // Stop flash phantom
  Clear Flags [5] Flag Command   // Stop flash loop flag
  (P6) Flash Loop Phan 2 OFF     // Cleanup on exit
  House Code L All Units Off      // Turn off sounds
  House Code K All Units Off      // Turn off lights

Macro #2 - Flash Loop 1
  Conditions
     P5 On and                         // Trigger from Macro #1
     Flag Status On exactly 5      // Used to tell when loop is to exit
  (P13) Start Mid Loop ON       // Phantom just to log macro starting
  (P6) Flash Loop Phan 2 ON    // Trigger Macro #3

Macro #3 - Flash Loop 2          // Does actual light flashing
  Conditions
     P6 On and                        // Trigger from Macro #2
     Flag Status On exactly 5     // Know when to quit
  House Code K All Lights On   // Lights On
  Delay for 2 Seconds             // Length of on cycle
  House Code K All Units Off     // Lights off
  (P6) Flash Loop Phan 2 OFF     // Reset for next loop
  (P5) Flash Loop Phan 1 ON      // Trigger for next loop

It has taken me about 8 hours to write this and isolate the cause of the problem.  Any help would be greatly appreciated.

Ken
===

Title: Re: Macro screwed by second RF motion signal
Post by: BVD on February 14, 2009, 10:41:47 PM
I have built a simple alarm system using macros, motion sensors, lights, and horns.  It works fine (as intended) if there is only one motion detected signal received.  However, if a second motion RF is received while the system is flashing the lights, the lights stop flashing.  I have a flag to stop the macro from running two copies at the same time but it still doesn't work.

Ken,
What is the address of the second RF motion signal that messes up your macro or does it matter? Also exactly what do you mean when you say you have a flag to stop the macro from running two copies at the same time?
One thing you might want to consider is including is a macro to initialize the status of the flags you are using. 1st it would clear all flags, next it would SET Flag 4. By proxie 1st step CLEARS Flag 5. Now you are assured the when the conditions check the flag status will always be TRUE and when O2 becomes true due to motion the macros will run.
I have more ideas but think about this and please answer the questions above.
Last thought make sure the motion sensors are triggering your macros and not you running the macros by clicking on them with a mouse. The flag conditions only act correctly when triggered by an RF command.

Hope this helps!
Till Later,
Bob
Title: Re: Macro screwed by second RF motion signal
Post by: X10 Ken on February 14, 2009, 11:18:03 PM
What is the address of the second RF motion signal that messes up your macro or does it matter? Also exactly what do you mean when you say you have a flag to stop the macro from running two copies at the same time?
One thing you might want to consider is including is a macro to initialize the status of the flags you are using. 1st it would clear all flags, next it would SET Flag 4. By proxie 1st step CLEARS Flag 5. Now you are assured the when the conditions check the flag status will always be TRUE and when O2 becomes true due to motion the macros will run.
I have more ideas but think about this and please answer the questions above.
Last thought make sure the motion sensors are triggering your macros and not you running the macros by clicking on them with a mouse. The flag conditions only act correctly when triggered by an RF command.

Bob, Thanks for taking the time to look at what I have posted.  I understand your concerns about the flags not being correct at the start of the sequence, but if that were the case, things would not run correctly with only a single motion trigger.  I have also verified the flag status with the Status Report.

The purpose of Flag #5 being set is to prevent a second motion signal from this (or any other motion detector) from running the macro while it is already in the process of running from a previous trigger.  In theory, a second trigger should have zero effect because of the Flag #5 setting.

To isolate the problem, I took the other motion detector out of the picture.  There is only one (Set to O2).  If there is only one trigger from O2 the system works fine.  If there is a second O2 in the middle of the sequence, the lights (which were in flash mode) immoderately stop flashing.

I am a programmer by trade.  In the world I am used to, the second O2 should be ignored and have no effect because at the time the second O2 is issued Flag 5 is on and the entire trigger macro should be ignored.

I also understand the difference between running a macro from the computer and running it from the motion trigger.  I learned this the hard way a few days ago.  I always trip it by walking in front of it.

Ken
===

Title: Re: Macro screwed by second RF motion signal
Post by: BVD on February 15, 2009, 11:31:42 AM
Ken,
I am not a programmer by trade but I have worked with control systems PLC (Programmable Logic Controllers) not (Power Line Commands) for about 25 years. I am familiar with ladder logic, some visual basic, and some C programming. I've helped programmers find problems with their software because I am stupid much like the piece of equipment they are trying to control. A lot of times programmers overlook things mainly because they wrote the program and in their minds it should work. I look at it step by step or rung by rung and pretend I am the PLC and what would I do with the commands you have given me.

This AHP softwares half way stab at being a programming language leaves a lot to be desired. In a real programming language you could break or halt execution of the program and check the current status of different things. You could also use a JSR [NAME] to stop the execution Jump to Sub Routine [NAME], execute the commands in that sub routine, and RTS Return from Sub Routine and continue main program execution.

Check your history of commands issued as you run these macros. Something tells me you will find that Flag 5 isn't always in the state you think it is in. Another thought is that possibly O2 times out and turns off. The other thing that bothers my pea brain is in the first macro you have a delay of 22 seconds. I think you are using it to pause macro1 long enough for macro 2 & 3 to execute. Am I correct? And I am wondering what really happens after the 22 second delay times out. It seems to me that it would then execute the remaining commands which would set things up for a halt macro situation.

I in no way mean to insult your intelligence. I am just trying to help you get this working as it should.

Till Later,
Bob
Title: Re: Macro screwed by second RF motion signal
Post by: X10 Ken on February 15, 2009, 12:39:02 PM
Check your history of commands issued as you run these macros. Something tells me you will find that Flag 5 isn't always in the state you think it is in. Another thought is that possibly O2 times out and turns off. The other thing that bothers my pea brain is in the first macro you have a delay of 22 seconds. I think you are using it to pause macro1 long enough for macro 2 & 3 to execute. Am I correct? And I am wondering what really happens after the 22 second delay times out. It seems to me that it would then execute the remaining commands which would set things up for a halt macro situation.
Bob,

Thanks again for your interest in my problem.

The 22 seconds is the amount of time that horns and lights are supposed to be in alarm state before resetting back to normal.  In a production system, this would be a longer time interval, but 22 seconds seems to be enough for test purposes.  After the 22 seconds, all of the macros should halt execution (and they do).

The motion detectors are set to a very large time interval (over an hour) before sending an off signal, so that is not a factor.

I have looked at the logs between runs that work and runs that don't work.  I can see the extra RF Receive in the non-working log, but can't tell what it is doing.  The extra RF signal may be turning off flag #5, but the logs do not ever show flag state changes.  If you think it would help, I can try to post the logs.

Ken
===
Title: Re: Macro screwed by second RF motion signal
Post by: BVD on February 15, 2009, 01:27:14 PM
Ken,
Please do if it is possible. If not copy, and paste them into an Email to me.
w8rvd@columbus.rr.com

Till Later,
Bob
Title: Re: Macro screwed by second RF motion signal
Post by: Boiler on February 15, 2009, 02:05:25 PM
X10Ken,

Sorry to take things in a different direction but... What version of ActiveHomePro are you using?  Be advised that the latest (V3.236) has a number of bugs (I'm not up to date on these).  I honestly don't see a problem with the Macros that you've posted.  You may want to try reverting to V3.204.
Title: Re: Macro screwed by second RF motion signal
Post by: X10 Ken on February 15, 2009, 02:18:48 PM
Sorry to take things in a different direction but... What version of ActiveHomePro are you using?  Be advised that the latest (V3.236) has a number of bugs (I'm not up to date on these).  I honestly don't see a problem with the Macros that you've posted.  You may want to try reverting to V3.204.

I purchased my AHP after 2.236 came out so I have no older version to revert to.

Where can I get the older version?
Where there things fixed in this version that reverting might mess me up?
Are the control files compatible?

Thanks,
Ken
===
Title: Re: Macro screwed by second RF motion signal
Post by: Boiler on February 15, 2009, 03:31:05 PM
Ken,

You can download various previous releases from here: AHP Updates (http://software.x10.com/pub/applications/activehome/).

The control files should be backward compatible.  As far as fixes are concerned, I believe they were trying to fix some issues with the Security and camera modules.  In doing so, the "Fixed" (i.e. broke) other things.

Have a look around the forum for problems related to 3.236 - as I said, I'm not up to date on this.
Title: Re: Macro screwed by second RF motion signal
Post by: X10 Ken on February 15, 2009, 04:19:35 PM
Please do if it is possible.

Bob,

New Information!!!!!

If the second RF signal from the motion detector is received directly by the AHM interface, there is no problem.  If the RF signal is received by both the AHP interface AND a TM751 transceiver, there is still no problem.  However, if the motion signal ONLY comes from a transceiver (TM751 or RR501) then the problem happens.  Unfortunately, one of my motion sensors needs to be in a place that can not communicate directly with the AHM interface (even with my initial antenna mod).

Here are the two files.  AHP outputs the files in HTML, but this forum does not allow posting of an HTM file, so I converted them to MS Word (.DOC) files for posting.

Things of note:

The first file (Works.doc) is a complete run where everything worked exactly as expected.

The second file (No_Work.doc) shows what happens if a second time pass by the detector happens when the first set of macros are still processing.  Everything stops when the second RF comes in.

Items of note:
I have no transceivied house codes.
The second set of motion signals is duplicated.
I have used two different model motion sensors with same results.
I have used two different model transceivers with same results.

That's what I know as of now.

Ken
===
Title: Re: Macro screwed by second RF motion signal
Post by: BVD on February 16, 2009, 12:45:15 PM
Ken,
I looked over and traced through both of the macros you sent. I noticed that in the WORKS listing from the DELAY 22 seconds till the line that would execute after the delay and stop the macro was 36 seconds. This tells me that the delays are additive. Your initial 22 seconds plus 14 seconds worth of 2 second delays in the third macro. I noticed that in the NO WORKS several things.
1. Your 22 second DELAY starts at 2:07:51 macros 2 & 3 execute once adding 2 seconds.
2. You receive 2 triggers from your motion sensor O2 ON at 2:07:57. 6 seconds in to the 22 second delay and macros 2&3 terminate and return to macro 1 at the 22 second delay line, wait 18 seconds for the remainder of the timer to time out, then start execution of the line under the 22 second delay at 2:08:15 and runs thru the rest of macro 1 and stops.

I definitely see the chance of data collision happening. The RR501 has collision avoidance built in and listens before sending PLC data, but once it thinks it's clear to send and starts sending it's data the macro issues a command and OOOPPP's. Phantom modules can change states and no longer be true.

There is no way that I know of to turn off the motion sensor once the macro is triggered an back on after the macros have completed. Last night I tried a little experiment with a little different approach. I had an Initialization Macro
Conditions for Macro1
If P1 On (Motion Sensor) and Flag Status 5 Clear and P9 Off
Clear All Fags for monitored house code (P)
All Units OFF for monitored house code (P)
SET Flag 5
P9 ON
P10 ON
P3 ON (Trigger Macro 2)Ring Chime wait 1 minute Ring Chime Again wait 1 minute
Conditions for Macro 2
If P3 Module Status ON and Flag Status 5 SET and Module Status P10 ON
P10 Off
P2 ON (Chime)
Delay 1 minute
P2 On (Chime)
Delay 1 minute
P11 ON (Triggers Macro 3) Reset for next trigger
Conditions for Macro 3
If P11 ON and Flag Status 5 SET and Module Status P10 OFF
Clear All Fags for monitored house code (P)
All Units OFF for monitored house code (P)

See what you think of this setup. Second trigger does not Stop the macro.

Till Later,
Bob
Title: Re: Macro screwed by second RF motion signal
Post by: BVD on February 16, 2009, 05:26:27 PM
Ken,
Here are a couple of files for you

Till Later,
Bob
Title: Re: Macro screwed by second RF motion signal
Post by: X10 Ken on February 16, 2009, 05:41:51 PM
Here are my latest log files.  It proves the problem is timing related.

If these files post ok, I'll post the macros that created them.

Ken
===
Title: Re: Macro screwed by second RF motion signal
Post by: X10 Ken on February 16, 2009, 05:58:32 PM
Hi All,

If you look at the log files I just posted, you can see that the transceived signal from the motion detector causes the loop to stop, but ONLY if it comes just before the step where Macro #2 tries to restart itself.

Here are the macros:

Macro #1 - Alarm ID-1 Motion
  Trigger:  O2 On and        // Transceived Motion Signal
  Conditions:
     Flag Status Off exactly 5 and
     Flag Status On exactly 4
  Actions:
     Set Flags [5] Flag Command    // Used to exit loop and prevent duplicate macros running
     Delay for 1 Second
     (L2) Mini Alarm ON
     (L3) Power Horns ON
     (L2) Mini Alarm ON
     (L3) Power Horns ON
     (L2) Mini Alarm ON
     (L3) Power Horns ON
     Delay for 2 Seconds
     (P6) Flash Loop Phan 2 ON   // Start looping
     Delay for 02:30                   // Amount of time alarm should be on
     Clear Flags [5] Flag Command  // Stop the repeating loop
     (P5) Flash Loop Phan 1 OFF    // Clean up and turn off everything
     (P6) Flash Loop Phan 2 OFF
     House Code L All Units Off
     House Code K All Units Off

Macro #2 - Flash Inner Loop, Repeats until Flag 5 turns off
  Trigger: P6 On and
  Condition:
      Flag Status On exactly 5
  Actions:
      (F13) Inner Loop ON      // Phantom to show macro start in log file
     House Code K All Lights On
     (L1) Chime ON
     Delay for 5 Seconds
     House Code K All Units Off
     (F12) End Inner Loop OFF   // Phantom to show macro end in log file
     Delay for 5 Seconds
     (P6) Flash Loop Phan 2 ON  // Make this macro run itself again
---------- If motion signal appears here before the macro restarts, the looping fails to restart.

As you can see from the macros and the log files, there is a short window of time when the motion signal will cause things to stop running properly.

There must be an explanation for this behavior.

Ken
===

Title: Re: Macro screwed by second RF motion signal
Post by: X10 Ken on February 17, 2009, 12:10:49 PM
Here are a couple of files for you

Bob,

I looked at your files.  In that they are conditional on module status (which I can't because of only one monitored house code), and that my problem has been isolated to a looping problem, they don't really apply to my problem.

HOWEVER!!!!!  In thinking about how to respond to your post and explaining that there is only a one second window where things can get messed up, I got a sudden realization.

In my original testing the macro restarted about every 4 seconds.  With each restart there was a one second window where an incoming signal could mess things up.  This means that a random signal had a 25% chance of screwing my macro.

I have now changed my inner macro to do a bunch of repeated cycles before exiting.  In this way, the execution of the inner macro takes 30 seconds and there is only a 3% chance that a random signal will screw the process and never in the first few cycles which are the most important.

This is not the best solution, but it is a good enough solution until I get a hard wired alarm system installed.

Thanks for helping my thought process.

If anyone else has a total solution, I would love to hear from you.

Ken
===