Grouping conditions into functions

Iā€™m wondering if this is possible or maybe something that can be considered on an update for RM.

I have several scenarios and comparisons which require to jump back and fort between several conditions. Right now, RM is linear in processing the instructions.

Is there a way to build a condition set, under a name that can be called out from the ā€œmasterā€ rule?

My rules are extremely complex and long and itā€™s difficult to follow a chain of conditions when the same thing repeats itself under a different step.

Iā€™m thinking something like this

If a is true
FUNCTION1
If b is true
FUNCTION2
If c is true and var is 0
FUNCTION1
End if

and then somewhere within, one defines said functions

Iā€™m currently McGyver-ing it with another rule per ā€œfunctionā€ but that adds clutter.

Is there a more elegant way to achieve that?

1 Like

Not that I can think of, but you would not be alone if you just ran one rule's action from another rule.

Alternatively, if you are getting this complex, it's possible you have some coding experience. In that case, keep in mind that you can write custom apps in Groovy for Hubitat (Rule Machine just exists so you don't have to and is quite powerful on its own, though was ultimately written using this same environment). The developer docs, particularly the app primers under "App Structure," would be a good starting point if you aren't sure how: Developer Documentation | Hubitat Documentation. Just another idea -- because there, of course, you can literally use methods (as Groovy calls what some other languages call functions).

2 Likes

I would aver that WebCoRE strikes a very good balance between the elegant modularity of coding (e.g. Groovy) at one extreme and the point-and-click ease and linearity of Rule Machine at the other.

WC's learning curve is modest, reliability and system integration very high, sporting a feature set that's fairly rich for having begun as a community app. That includes powerful conditionals like SWITCH and CASE. It has a wide install base of users.

WC gets my vote for operations of above-average complexity. For everything else, there's still RM.

2 Likes

I mean, "Run Rule Actions" basically is a function call. Create a rule with no triggers, name it something like "[Function] BlahBlah" and call it from other rules.

Alternatively, consider collapsing the other direction -- have your complex set of criteria turn on/off a virtual switch, and have other rules that react to the switch turning on/off.

2 Likes

Thatā€™s how I am currently doing it with run rule actions :blush:

If youā€™d see my Rule Machine, youā€™d probably understand the clutter pain I have.

It does what i need as is. I was hoping that maybe there is a way of which iā€™m not aware of, on nesting the trigger-less functions under the main one.

No way of making child rules, no. I think you could install a second Rule Machine instance to hold subordinate rules, though I don't see a way to rename the instances.

Iā€™ll use number sequence in the rule name and group them accordingly.

001 NAME
001 Function1
Etc

That should make it easier to follow ā€¦

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.