X10 Community Forum

🖥️ActiveHome Pro => Smart Macros => Plug-ins => User-Designed Working Macros => Topic started by: steven r on March 27, 2008, 10:35:40 AM

Title: Looping Macros
Post by: steven r on March 27, 2008, 10:35:40 AM
It's both easy and dangerous to build and start a loop. e.g. I use one as a panic that flashes the lights.
The most basic endless loop can be created as follows.

Create a Dummy module with the same address as your macro.

Macro M1 ON - Trigger on an M1 signal
<execute commands>
delay 10 min
M1 On

The above will continue to execute indefinitely and if triggered again each additional loop will continue till purged. I strongly recommend using flags, elses, and/or time conditions to give one an exit point.

Without a way to exit, the macro will go into an endless loop causing multiple possible problems including possibly having the CM15A lock up!

This is a the looping macro I use to test check my X10 signal as well as switches and modules on my test jig before installing. It gives an example of how to program an exit for a macro.

AHP 3.204 (should work on 3.206 as well)

This is an example on a looping macro using a flag to exit it. I use a similar one to flash the lights.
It requires a dummy lamp module set to HC/UC P1. Macros can't directly call themselves! A macro can trigger a dummy module with the same HC/UC, however. This will result in a macro effectively calling itself.
I test my X10 components on P1 and leave them on that code till I need them. This way if I need to reach in the X10 box of stuff for something in a hurry, I know the component has been already tested.

The actual looping macro is "P1 On". Macros "P2 On" and "P2 Off" start and stop the loop respectively.

P1 ON LOOP TEST   - Triggers with P1 On and Flag Status On exactly 1   
Delay for 2 Seconds
(P1) Dummy - Loop test   OFF                                         ;X10 test commands
Delay for 2 Seconds                                                       ;   "     "        "
(P1) Dummy - Loop test   Brighten then dim to 25%          ;   "     "        "
Delay for 4 Seconds                                                       ;   "     "        "
(P1) Dummy - Loop test   Brighten then dim to 75%          ;   "     "        "
Delay for 4 Seconds                                                       ;   "     "        "
(P1) Dummy - Loop test   OFF                                         ;   "     "        "
Delay for 2 Seconds                                                       ;   "     "        "
(P1) Dummy - Loop test   ON                                          ;Recalls itself via dummy module

P2 ON - START SIGNAL TEST - Triggers with P2 On   
Set Flags [1]   
(P1) Dummy - Loop test   ON                                         ;Starts P1 loop via dummy module

P2 OFF -STOP SIGNAL TEST - Triggers with P2 Off   
Clear Flags [1]                                                             ;With flag 1 clear P1 loop will stop at the end of its current loop
Delay for 2 Seconds
Clear Flags [1]                                                             ;Redundant command. Most likely not needed. Added just for the "Murphy factor"
Delay for 30 Seconds
(P1) Dummy - Loop test   OFF                                       ;Just to make sure whatever I was testing is left off.

Another exit approach would be to place a timed condition in the looping macro.
Title: Re: Looping Macros
Post by: steven r on March 27, 2008, 12:16:51 PM
Exit via a time.

Requires dummy appliance module M1

M1 Off - Triggers on M1 off and time is before 6:00 am
<turn off kids lights>
delay 15 min
M1 Off

Once started it will turn off the light every 15 minutes till it's time to wake up for school.
This works flawlessly for wired lights and also for plug in lights till your kid figures out how to plug his lamp in directly.  ;)

Hey... It's just an example. Your mileage will vary.

I've built a similar one for Earth Hour (http://www.earthhourus.org) this coming Sat, March 29 at 8:00 pm.
Title: Re: Looping Macros
Post by: Don N on December 05, 2009, 10:49:05 AM
steven r --  I built your looping marco and found that after 5-6 cycles a "firestorm" causes the AHP to lock up.  By your narrative, it sounds as if you use this routine a lot.  How have you overcome the "firestorm?"