Rule machine - Run another rule actions

I have two rules.

One with a trigger and actions and the other rule with no triggers. I left it blank and wrote my actions out for it.

In my first rule I’m calling up the second rule to run it’s actions.

My assumption is that it will run the actions of the rule with no triggers and it will actually work?

Yes, that will work fine.

Thanks.

I’m fine tuning all my rules and consolidating as much as possible. Figure less rule trigger lookups on all my motion sensor changes should cause less load on the hub..... Maybe I’m wrong ..

Well, there is a happy medium. You don't want rules to be too large either. The one big thing to avoid is having a rule with triggers that can happen at virtually the same time. RM will try to spin up a second copy of the rule before the first is finished and that's not good. You'll get a "pop" error in the logs. Something like "cannot pop() null list". (Can't remember the exact words) So, while yes, having multiple rules with the same trigger is bad, there are worse things. I use the "call the other rule" technique when It's something multiple other rules have to do but I don't want to have to do it in every rule. Like turn all the lights off in the house. I have a rule that has only conditional actions that handles all the lights turning off based on some criteria (usually mode). That way, whenever I need to do that, I just make sure that I adjust the mode a couple steps before I call the "lights off" rule. If I add or change or move a light, i only have to go to one place to fix it, not 4 or 5. My "leaving home" rule runs a lot faster now that they're separate too. So, the technique you inquired about is an underappreciated function of RM. :slight_smile:

2 Likes

I'm glad I found this thread! Running a rule WITHIN a rule is a nice feature, and you have to dig a bit to find it LOL.

Select Action Type to add
Set Private Boolean, Run/Cancel/Pause Rules
Select Which Action
Run Rule Actions

3 Likes

Glad I found this thread. Quick question on calling another rule. Is there a way to pass the device that was triggered, or even a device that is not triggered. For example say I want a specific light to brighten/flash based on where motion is detected, can I have a a Rule that handles the brighten/flash that is passed the info about which device to act on?

Mike

I don't think there is in the sense of passing arguments to a function or subroutine but you could do it less elegantly with hub variables. Exception on trigger device noted below in @jwjr's post.

I just tested this, having "Rule1" run the actions of "Rule2", and the "%device%" that triggered Rule1 was passed through to Rule2 unchanged.

1 Like

One other question about a Rule calling the actions in another Rule. Does the initial Rule wait for the rule it calls to return or does in continue on with its own actions thereby effectively running multiple sets of actions? For example if the rule being called conatains "wait for logic" will the initial rule wait as well?

No... the 2nd rule will spawn separately but the first rule will continue to execute. Unless you want to try something along the lines of what @672southmain suggests!

1 Like

It all depends on how you want it to work. You could synchronize the called rule with the calling rule by using a WAIT in the calling rule for a change in a semaphore Hub variable that could be set by the called rule.

I think I got it, so if I want to wait I can wait for a variable change, if I want to run without waiting do nothing (even if the action I called has a wait, correct?

Yep. You could even use the variable to pass back completion codes, etc. just initialize the variable before calling the called rule so you can see the change. You could even use the initialization of the variable to pass a parameter. Be creative.

1 Like