Please login or register.

Login with username, password and session length

Author Topic: Macro calling a macro  (Read 5614 times)

spam4us

  • Hero Member
  • *****
  • Helpful Post Rating: 3
  • Posts: 152
Macro calling a macro
« on: September 09, 2007, 01:52:53 PM »

Is there a way to have Macro1 perform Macro2 and for Macro1 to wait for Macro2 to finish before the rest of Macro1 completes without using a delay (which I found to be hit or miss).
Here's what I'd like to do.

Macro1
   trigger c1 on
     set c2 on (this will trigger macro 2)
     *At this point, I want macro2 to finish before the next 2 statements execute.
     turn light a3 on
     turn light a4 on
End of Macro1

Macro2
  Trigger C2 on
   turn on light e2
   turn on light e3
End of Macro2

Thanks
Logged

KDR

  • Hero Member
  • *****
  • Helpful Post Rating: 53
  • Posts: 758
    • Home Automation Chat
Re: Macro calling a macro
« Reply #1 on: September 09, 2007, 02:56:32 PM »

spam4us unfortunately once a Macro starts there is no way to stop it until it runs to the end. I will have to give this some thought to see if there is any way to work around this. I'm sure there will be some others post here that may have some ideas.

----------------KDR
Logged
Note: "Guests" may read the X10 forum , but you must register to post!

When I'm online you can find me in the Home Automation Chat Room!

HA Dave

  • Hero Member
  • *****
  • Helpful Post Rating: 175
  • Posts: 7127
Re: Macro calling a macro
« Reply #2 on: September 09, 2007, 03:20:21 PM »

Is there a way to have Macro1 perform Macro2 and for Macro1 to wait for Macro2 to finish before the rest of Macro1 completes without using a delay (which I found to be hit or miss).
Here's what I'd like to do.

Macro1
   trigger c1 on
     set c2 on (this will trigger macro 2)
     *At this point, I want macro2 to finish before the next 2 statements execute.
     turn light a3 on
     turn light a4 on
End of Macro1

Macro2
  Trigger C2 on
   turn on light e2
   turn on light e3
End of Macro2

Thanks


Maybe if you used three macros?

Macro1
   trigger c1 on
     set c2 on (this will trigger macro 2)
     
End of Macro1

Macro2
  Trigger C2 on
   turn on light e2
   turn on light e3
trigger MACRO 3
End of Macro2

MACRO 3
     turn light a3 on
     turn light a4 on
End of Macro3
Logged
Home Automation is an always changing technology

spam4us

  • Hero Member
  • *****
  • Helpful Post Rating: 3
  • Posts: 152
Re: Macro calling a macro
« Reply #3 on: September 10, 2007, 01:27:47 AM »

KDR & Dave_x10_L,
     Thanks for the replies.

KDR, I would like to do this without using a delay since I found that using them is trial and error as far a guessing how much time is needed for the other macros to complete.

Dave_x10_L, the problem using your example is that Macro2 will always trigger Macro3 which may not always be wanted.

I was thinking of having some snippets of code that I could execute as a subroutine so I don't wind up having alot of long routines.  An example would be a Front Door macro triggered when someone comes to the front door to run Macro2 to turn on a porch light, run macro3 to ring a chime, and run macro4 to turn on an appliance module.


(Front Door Macro)
Trigger c1 on
    run macro2
    run macro3
    run macro4

Macro2
    turn on porch light
    turn on front foyer light
Macro3
    ring the chime
    turn on light next to the chime
Macro4
    turn on appliance module
   
There may be other times where I would only need to run macro3 and macro4.
Example
Someone comes to the back door.  I don't want macro2 to run but I do want Macro3 & 4 as well as another macro5.  It would look something like this.
(Back Door Macro)
    run Macro3
    run Macro4
    run Macro5

Macro5
    turn on back porch light

In this example I can "re-use" macro3 & 4.

     Now I know the above is possible, BUT I would like to have macro 4 not execute until Macro3 is finished and not have Macro5 execute until Macro4 is finished without any coding put into Macro3, 4 or 5.  Is there a way to say

Run Macro3
Wait for Macro3 to finish
Run Macro4
Wait for Macro4 to finish
Run Macro5
again without using the "Delay" statement.

  I have tried the above, but it seems that the macros start to run before the previous one has finished.
Hope this makes sense. It's sure ginving me a headache.

thanks

Logged

steven r

  • Advanced Member
  • Hero Member
  • ******
  • Helpful Post Rating: 74
  • Posts: 2189
  • Halloween with X10
Re: Macro calling a macro
« Reply #4 on: September 10, 2007, 02:17:07 AM »

I think Dave_x10_L's "work around" is about the best you'll be able to do. If you're afraid of macro 2 accidentally triggering macro 3, you can use flags. If you give your macro 2 a unique house / unit code it shouldn't be a problem however.

I did, however, want to remind you that for a macro to be executed by another macro you'll need to create a dummy variable with the same house and unit code as the the macro you want to call. e.g. If you want a macro M1 to call macro M2 you'll need a dummy module also labeled M2. (While there is another way to call a macro, the dummy variable approach is the most reliable.)

What you need to realize is the AHP was not designed to have macros call macros. The work around to have a macro execute a macro by using a dummy variable was discovered by the X10 community. There is no way, however, for a macro to call another macro as a true subroutine.
« Last Edit: September 10, 2007, 02:37:55 AM by steven r »
Logged
BVC let's me tell my camera where to go!
:) Murphy is my beta testing pal. He helps me find problems whether I like it or not. :)

Tuicemen

  • Administrator
  • Hero Member
  • ****
  • Helpful Post Rating: 282
  • Posts: 10497
  • I don't work for X10, I use it successfuly!
Re: Macro calling a macro
« Reply #5 on: September 10, 2007, 09:50:46 AM »

spam4us :
What you are trying to do is totally possible ,how ever as steven r pointed out you'll need to create phantom modules, use flags and conditions and most likely Else's in your macros!
Understanding how each of these works can be found by doing an advanced search or from links in my Topic: Having ActiveHome Pro Problems? Please Read This First!  (Read 21285 times)

eg:
front door:
c1 on
set flag 2
turn on dummy module D1

macro for dummy
D1 0n,if flag 2 set
turn on chime and lamp macro address
turn on porch light
turn off dummy (D1)
clear flag 2

Macro for back door
set flag 3
turn on dummy macro D1

else for dummy D1
if flag 3 set
Turn on kitchen light
turn on chime and lamp macro address
turn on radio
clear flag 3
turn off D1


With out the Smart Macros plug-in this isn't possible!
You can let this get very complicated or be very simple, but You don't need a macro to simply turn on an applance module!
every macro can contain it's own conditions and several Else's
eg: lamp chime macro could contain the condition  if it is between 7 and 9 am don't turn on chime just the light  the  else could be turn on lamp and chime
One Note on conditions: The first set of conditions that is met will trigger the macro so you couldn't have a macro with if it is after 6 then the next else to have the condition it is after 6 and flag 2 is set! the second would never fire! ;)
Best of luck
Cheers
« Last Edit: September 10, 2007, 09:52:22 AM by Tuicemen »
Logged
Please Read Topic:
General Forum Etiquette
Before you post!
 

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