Please login or register.

Login with username, password and session length

Author Topic: Need help with conditional macro  (Read 7919 times)

paul warshawsky

  • Sr. Member
  • ****
  • Helpful Post Rating: 5
  • Posts: 102
Need help with conditional macro
« on: July 03, 2008, 01:02:22 AM »

Background first:  My 5 year old is too small to reach light switches - she's upset because her 3 year old sister can...  She wants to be able to turn on the light in the bathroom - so far pretty simple, right?

Here's the catch - I don't want her turning the lights on/off on the Sabbath and screwing up our timers.  I also want her to be able to turn the light off with the same switch.  Also at night, when her eyes are dark adapted I want the light to be dim so it doesn't bother her eyes.

The solution I tried:

I got a big red button (KR15A) set this to C9
Flag 1 turned on over Sabbath to prevent macro from running (see below)
I don't know if it matters but C is my monitored housecode
Wrote the following macro

C9 On:
    Condition: Flag 1 and 2 OFF AND Daytime        (Flag 1 OFF - not sabbath, Flag 2 Off macro has not turned light on)
                C3 Bright 100%
                Wait 30 sec                                   (prevent multiple trigger from turning light off right away)
                Set Flag 2 On
                Wait 30 min
                Set Flag 2 Off                                 (if she forgets to turn the light off and we do it from the
                                                                    main switch need to reset flag so it will work again)
    Else Condition: Flag 1 and 2 OFF
                C3 On 50%
                Wait 30 sec
                Set Flag 2 On
                Wait 30 min
                Set Flag 2 Off
    Else Condition: Flag 1 Off
                C3 Off
                Wait 30 sec                                   (deal with multiple trigger)
                Set Flag 2 Off                                (ready to turn of again)

I think this should work - but it doesn't.  I have only tested it at night but when I press the button nothing happens and I get this activity in the Monitor:

1049 2008-07-03 12:50:16 AM Receive C9 (Bathroom Button Day On)
1050 2008-07-03 12:50:17 AM Receive C On (Bathroom Button Day On)
1051 2008-07-03 12:50:23 AM Macro C3 (Family Bathroom)
1052 2008-07-03 12:50:23 AM Macro C Bright 100(Family Bathroom)
1053 2008-07-03 12:50:23 AM Macro C Dim 50(Family Bathroom)
1054 2008-07-03 12:50:24 AM Macro C3 (Family Bathroom)
1055 2008-07-03 12:50:24 AM Macro C Off (Family Bathroom)

Any suggestions of where I went wrong?

Paul


Here is the Macro:

Bathroom Button Day On C9 On and Flag Status Off exactly 1, 2 and Daytime
 Delay for 1 Second
 (C3) Family Bathroom ON
 Delay for 30 Seconds
 Set Flags [2] Flag Command 
 Delay for 30:00
 Clear Flags [2] Flag Command 
Bathroom Button Night On C9 On and Flag Status Off exactly 1, 2
 Delay for 1 Second
 (C3) Family Bathroom Brighten then dim to 50%
 Delay for 30 Seconds
 Set Flags [2] Flag Command 
 Delay for 30:00
 Clear Flags [2] Flag Command 
Bathroom Button Off C9 On and Flag Status Off exactly 1
 Delay for 1 Second
 (C3) Family Bathroom OFF
 Delay for 30 Seconds
 Clear Flags [2] Flag Command 

Logged

Walt2

  • Advanced Member
  • Hero Member
  • ******
  • Helpful Post Rating: 28
  • Posts: 787
Re: Need help with conditional macro
« Reply #1 on: July 03, 2008, 02:59:39 PM »

Unfortunately, AHP is not a perfect programming language, and doesn't always do what "typical programming logic" would lead one to expect.  This is particularly true for If...Then...Else constructs.

Also, AHP is not recursive.  While you are in any of your 30 minute "waits", you can't start executing another thread of C9 'on' even if it might travel down a different If...Then...Else branch.

From my experience, I would change it to this...

C9 On:
    Condition: Flag 1 and 2 OFF AND Daytime     
      ... 
      Else Condition: Flag 1 and 2 OFF AND Nightime
      ....
      Else Condition: Flag 1 Off and 2 ON and Nightime(?)
      ....

« Last Edit: July 03, 2008, 03:04:37 PM by Walt2 »
Logged
* Sears Home Control System, Radio Shack Plug 'n Power, NuTone, Stanley LightMaker, BSR, HomeLink.
* Tecmar Device Master, CP290 (LightHouse), CM11A (AH), CM14A (AH2), CM15A (AHPro).

paul warshawsky

  • Sr. Member
  • ****
  • Helpful Post Rating: 5
  • Posts: 102
Re: Need help with conditional macro
« Reply #2 on: July 03, 2008, 06:48:21 PM »

Walt,

I've read previously that a macro can be triggered multiple times while still running - this is why there is so much talk of using flags to prevent multiple triggers.  Is this not true of conditional macros?  (I suppose I could test this once the macro works...)

So I simplified the macros (deleted all the delays) and made the conditions explicit as you suggested.  Now the activity monitor shows that everything is working great, but the light does not turn on!!

This is the output from the activity monitor:

Event   Date/Time   Action   Data
0   03/07/2008 6:33:29 PM   Receive   C9 (Bathroom Button Day On)
1   03/07/2008 6:33:30 PM   Macro   C3 (Family Bathroom)
2   03/07/2008 6:33:30 PM   Macro   C Off (Family Bathroom)
3   03/07/2008 6:33:59 PM   Receive   C9 (Bathroom Button Day On)
4   03/07/2008 6:34:04 PM   Macro   C3 (Family Bathroom)
5   03/07/2008 6:34:04 PM   Macro   C Bright 100(Family Bathroom)
6   03/07/2008 6:34:18 PM   Receive   C9 (Bathroom Button Day On)
7   03/07/2008 6:34:19 PM   Macro   C3 (Family Bathroom)
8   03/07/2008 6:34:19 PM   Macro   C Off (Family Bathroom)


This seems like a toggle  (off - on - off) but the bright 100% is simply not happening.  Before everyone suggests it, I have changed to "issue on instead of bright 100%" - no difference.

Strange... Currently the macro reads as follows:

Bathroom Button Day On   C9 On and
Flag Status Off exactly 1, 2 and
Daytime   (C3) Family Bathroom   ON
      Set Flags [2]   Flag Command
Bathroom Button Night On   C9 On and
Flag Status Off exactly 1, 2 and
Nighttime   (C3) Family Bathroom   Brighten then dim to 50%
      Set Flags [2]   Flag Command
Bathroom Button Off   C9 On and
Flag Status Off exactly 1 and
Flag Status On exactly 2   (C3) Family Bathroom   OFF
      Clear Flags [2]   Flag Command

Any suggestions.

Paul
Logged

Walt2

  • Advanced Member
  • Hero Member
  • ******
  • Helpful Post Rating: 28
  • Posts: 787
Re: Need help with conditional macro
« Reply #3 on: July 03, 2008, 07:32:10 PM »

Now the activity monitor shows that everything is working great, but the light does not turn on!!

The operation was a success, but the patient died.   :'
Logged
* Sears Home Control System, Radio Shack Plug 'n Power, NuTone, Stanley LightMaker, BSR, HomeLink.
* Tecmar Device Master, CP290 (LightHouse), CM11A (AH), CM14A (AH2), CM15A (AHPro).

PajamaGuy

  • Hero Member
  • *****
  • Helpful Post Rating: 32
  • Posts: 522
Re: Need help with conditional macro
« Reply #4 on: July 04, 2008, 06:57:14 AM »

What lamp/switch module are you using for the light?  Are you using "absolute", "Dim", or "Brighten" (the command in the macro, not the preferences setting).

If you remove all the conditions, and simply have the Red Button turn the light just "ON" does it work?
If so, add just the on/off FLAG and see if the light turns on AND off.
Add the next condition, like daytime vs. nighttime - and if that doesn't work, try the time span, NOT the daytime/nighttime parameter.
.etc.
Start working that and tell us where it fails.
Logged
PajamaGuy
Win-7 - Dell XPS -Automation
VA12a on a dedicated desktop - Video
XTB-IIR & V572RF32

Remote via LogMeIn (FREE) and Ignition

paul warshawsky

  • Sr. Member
  • ****
  • Helpful Post Rating: 5
  • Posts: 102
Re: Need help with conditional macro
« Reply #5 on: July 04, 2008, 08:07:32 AM »

The switch is a WS12A.

So far I have tried:

Programming Red Button to same code as switch - can turn on light.

Programming Red Button to house code that triggers a macro which turns on light - this works too.

I have not tried the one condition only macro (light on? --> turn off, light off? ---> turn on).  It will take a few days before I get to this.

Clearly the problem is not an obvious error on my part but rather a failure of the system to behave as it should.  Does anyone feel like trying a similar macro on their setup to see if this is a problem with my software/CM15a???

Paul
Logged

paul warshawsky

  • Sr. Member
  • ****
  • Helpful Post Rating: 5
  • Posts: 102
Re: Need help with conditional macro
« Reply #6 on: July 04, 2008, 06:46:18 PM »

OK - so here's where I stand right now.  I can toggle the light using a flag (If Flag OFF --> Turn ON light and set flag ON; If Flag ON --> Turn OFF light and set Flag OFF).  This only works if I put a slight delay before the Light On - my usual trick of 1 sec seems to be inadequate so now I've set 1 sec delay --> Light On --> 1 sec delay --> Light On (again) - this seems to work reliably.  (This means there is a reasonable chance the light will turn on quickly, but if it doesn't it gets another chance.)

I suspect my need for delays has something to do with having a XPCR installed which is causing some collisions.

I will try to build the rest of the macro back in the next few days.

Paul
Logged

paul warshawsky

  • Sr. Member
  • ****
  • Helpful Post Rating: 5
  • Posts: 102
Re: Need help with conditional macro
« Reply #7 on: July 07, 2008, 11:50:33 PM »

So judicious adding of short delays and some repeats for reliability have resulted in a reliable functional macro.  Retriggering does not seem to cause much trouble.  Interestingly, AHP adds a hidden 1 sec delay before the flag change.  Here is the final macro (from ahpeeprom_w.txt):

   C9 on
      if on or later than dawn                                              ; AHP way of programming "Its Daytime"
      and on or earlier than dusk
      and flags 1, 2 off
            delay 00:02 min:sec                                            ; this was the key - without this 2 sec delay macro fails
            C3 brighten by 100%
            delay 00:01 min:sec
            C3 brighten by 100%                                          ; not sure repeat needed but didn't see the harm
            delay 00:01 min:sec                                            ; I don't add this delay AHP does!!!
            set flag 2 on
   C9 on
      if flags 1, 2 off
      and on or later than dusk                                          ; these conditions added by AHP for "Its nighttime"
      or on or earlier than dawn                                         
            delay 00:01 min:sec
            C3 brighten first, then dim by 50%
            delay 00:01 min:sec
            set flag 2 on
   C9 on
      if flag 1 off
      and flag 2 on
            delay 00:02 min:sec
            C3 off
            delay 00:01 min:sec
            C3 off
            delay 00:01 min:sec
            set flag 2 off

Thanks for the help guys.

Paul
« Last Edit: July 08, 2008, 01:46:59 AM by paul warshawsky »
Logged

paul warshawsky

  • Sr. Member
  • ****
  • Helpful Post Rating: 5
  • Posts: 102
Re: Need help with conditional macro
« Reply #8 on: July 08, 2008, 01:19:41 AM »

ARGHHHHHH!!

Macro works, but only before midnight!!!!

After midnight it seems to trigger more than one limb of the conditional macro!  What I think is happening is that limb 2 of the macro is being triggered simultaneously with limb 3 when only limb 3 is supposed to trigger.

In this snippet from the activity monitor the macro has been triggered with flag 2 on (i.e. this should make it run limb 3 which turns the light off and clears flag 2).  The Bright 100% and Dim 50% must be coming from limb 2 which should not be running since flag 2 is on!

196   08/07/2008 12:46:38 AM   Receive   C9 (Bathroom Button Day On)
197   08/07/2008 12:46:44 AM   Macro   C3 (Family Bathroom)
198   08/07/2008 12:46:44 AM   Macro   C Bright 100(Family Bathroom)
199   08/07/2008 12:46:45 AM   Macro   C3 (Family Bathroom)
200   08/07/2008 12:46:45 AM   Macro   C Off (Family Bathroom)
201   08/07/2008 12:46:51 AM   Macro   C3 (Family Bathroom)
202   08/07/2008 12:46:51 AM   Macro   C Bright 100(Family Bathroom)
203   08/07/2008 12:46:51 AM   Macro   C Dim 50(Family Bathroom)
204   08/07/2008 12:46:53 AM   Macro   C3 (Family Bathroom)
205   08/07/2008 12:46:53 AM   Macro   C Off (Family Bathroom)


Why this happens only after midnight is a mystery to me - but I think I have a clue.  I find the EEPROM program difficult to decipher, but is seems to me that the condition for the second limb of the macro has "OR time before dawn" as a condition! This could explain why limb 2 fires in addition to limb 3 - while the flags tell it to run limb three, an or condition of "OR before dawn" would make this limb run too.  This would also explain why it works at night but before midnight (i.e. after dusk, not before dawn).  This would be a bug in AHP's programming of the CM15a.

0x027c:   0x7c   01111100   ------------- macro initiator START ----------- This corresponds with limb 1 - turn on during daytime
0x027d:   0x27   00100111   Trigger: C9
0x027e:   0xe3   11100011   b7: function 'on'; b6..5: '3' condition(s); b4..0: macro pointer msb
0x027f:   0x06   00000110   macro pointer: 0x0306
0x0280:   0x08   00001000   -- condition: b7..5: 'time'; b3..2: 'on or later than'; b0: 'and'
0x0281:   0x40   01000000   b7: dusk 'off'; b6: dawn 'on'
0x0282:   0x80   10000000   time: dawn;
0x0283:   0x0c   00001100   -- condition: b7..5: 'time'; b3..2: 'on or earlier than'; b0: 'and'
0x0284:   0x80   10000000   b7: dusk 'on'; b6: dawn 'off'
0x0285:   0x80   10000000   time: dusk;
0x0286:   0xc0   11000000   -- condition: b7..5: 'off status of flag'; b3..2: 'equal to'; b0: 'and'
0x0287:   0x00   00000000   flags:' 1', ' 2'
0x0288:   0x03   00000011          |
0x0289:   0x89   10001001   ------------- macro initiator START -----------  This would be limb 2 - on at night
0x028a:   0x27   00100111   Trigger: C9
0x028b:   0xe3   11100011   b7: function 'on'; b6..5: '3' condition(s); b4..0: macro pointer msb
0x028c:   0x25   00100101   macro pointer: 0x0325
0x028d:   0xc0   11000000   -- condition: b7..5: 'off status of flag'; b3..2: 'equal to'; b0: 'and'
0x028e:   0x00   00000000   flags:' 1', ' 2'
0x028f:   0x03   00000011          |
0x0290:   0x08   00001000   -- condition: b7..5: 'time'; b3..2: 'on or later than'; b0: 'and'
0x0291:   0x80   10000000   b7: dusk 'on'; b6: dawn 'off'
0x0292:   0x80   10000000   time: dusk;
0x0293:   0x0d   00001101   -- condition: b7..5: 'time'; b3..2: 'on or earlier than'; b0: 'or'     I think the bug is here with the 'or'
0x0294:   0x40   01000000   b7: dusk 'off'; b6: dawn 'on'
0x0295:   0x80   10000000   time: dawn;
0x0296:   0x96   10010110   ------------- macro initiator START -----------   This would be limb 3 - off
0x0297:   0x27   00100111   Trigger: C9
0x0298:   0xc3   11000011   b7: function 'on'; b6..5: '2' condition(s); b4..0: macro pointer msb
0x0299:   0x44   01000100   macro pointer: 0x0344
0x029a:   0xc0   11000000   -- condition: b7..5: 'off status of flag'; b3..2: 'equal to'; b0: 'and'
0x029b:   0x00   00000000   flag:' 1'
0x029c:   0x01   00000001          |
0x029d:   0xa0   10100000   -- condition: b7..5: 'on status of flag'; b3..2: 'equal to'; b0: 'and'
0x029e:   0x00   00000000   flag:' 2'
0x029f:   0x02   00000010          |

Anybody have any thoughts?  Do you agree this is a bug??

Paul
Logged

paul warshawsky

  • Sr. Member
  • ****
  • Helpful Post Rating: 5
  • Posts: 102
Re: Need help with conditional macro
« Reply #9 on: July 08, 2008, 01:33:35 AM »

OK, here is my workaround, which seems to work before and after midnight (I'm pretty convinced that my explanation above is correct).  The problem was related to a flaw in the "Its nightime" condition which uses "Its after dusk, OR its before dawn".  The problem is the OR is combined with the flag check (which is supposed to be AND).  There is no way to do this combination in one limb, so I have split the nighttime into two limbs (flags off and after dusk ELSE flags off and before dawn).

   C9 on
      if on or later than dawn                     These two conditions added by using the "Its daytime" condition
      and on or earlier than dusk
      and flags 1, 2 off
            delay 00:02 min:sec
            C3 brighten by 100%
            delay 00:02 min:sec
            C3 brighten by 100%
            delay 00:01 min:sec
            set flag 2 on
   C9 on
      if flags 1, 2 off
      and on or later than dusk
            delay 00:01 min:sec
            C3 brighten by 100%
            delay 00:01 min:sec
            C3 brighten first, then dim by 50%
            delay 00:01 min:sec
            set flag 2 on
   C9 on
      if flags 1, 2 off
      and on or earlier than dawn
            delay 00:01 min:sec
            C3 brighten by 100%
            delay 00:01 min:sec
            C3 brighten first, then dim by 49%
            delay 00:01 min:sec
            set flag 2 on
   C9 on
      if flag 1 off
      and flag 2 on
            delay 00:02 min:sec
            C3 off
            delay 00:02 min:sec
            C3 off
            delay 00:01 min:sec
            set flag 2 off

Yay!  My simple macro works after many hours of troubleshooting!

Any comments?

Paul
Logged
 

X10.com | About X10 | X10 Security Systems | Cameras| Package Deals
© Copyright 2014-2016 X10.com All rights reserved.