[SOLVED] Syntax for start/stop a rule from another rule

In order to simplify some of my code, I’m looking to start or stop a rule (or more) from another rule.
What is the sintax, pls?

Updated: I added bellow some clarification of what I’m looking for.

Since the rules are event driven you just need the set a proxy item and have the other rule trigger on that item. However that only solved the start g part, I see no way of stopping a running rule.

What do you mean by “Stop a rule”? In general, a rule , if triggered, should not last longer than some Milliseconds.

I mean when situation X then I want to trigger rule X wich command stop triggering (running) rule 1, rule 2, rule 3.

But why would the rule 1 2 and 3 run? Rules should run very short!

Maybe you mean something like

rule "enable gatekeeper"
     when (situation X event)
then
     someItem.postUpdate(ON)
end

rule "rule 1"
   when  whatever event
then
   if (someItem.state != ON) {       // works if OFF or undefined yet.
        do stuff
   }
end

You’d probably want a way to turn your gatekeeper off again.

1 Like

For example, I powered my house from 2 different sources (A, B). If I powered from A, I want to let “free” to run the rules 1,2,3 and block from running the rules 7,8.9. But if I powered from source B, then I would need to block from running the rules 1,2,3 and let “free” to run the rules 7,8,9.

I have many rules. And I want to add 2 “main” rules wich govern the others. In fact, I’m looking for an ideea to avoid editing each already created rules (which can be updated with a simple “while” loop, eventually).

Ok, so it’s not to stop running rules, but to prevent rules to run.
Just make an Item to store “Power A/B”.
Use an if(power == "A") in your rules.

rule "myrule"
when
    //some trigger
then
    if(power.state.toString == "A") return;
    // This Code is only executed if Power is not A
end
1 Like

Ok, Udo, but how could this rule say:
“hey, while powerSource == A,
so rule 1,2,3 are ON (available to start if are triggered) … && rule 7,8,9 are OFF (prevented to be triggered)”.

Then change the if statement:

rule "myrule"
when
    //some trigger
then
    if (power.state.toString == "A") {
        // rule code
    }
end

The rule code will only execute when power source is “A”

Thanks… but I think I’m not able to make myself clear. :frowning:

So, my OH are running:
rule 1, rule 2, rule 3,
rule 7, rule 8, rule 9.

I’m trying to find if I can control these already built rules from above from two another rules:
rule A (when the house is powered by sourceA)
rule B (when the house is powered by sourceB).

And “control” means: let it be triggered or not, available to be triggered or not.

Yes, that’s what we are saying.

In rule A set the power source flag to “A”

String PowerSourceFlag
rule "A"
when
    // trigger
then
    powerSourceFlag.postUpdate("A")
    // code of "A" rule
end

rule "rule 1"
when
    // trigger
then
    if (PowerSourceFlag.state.toString == "A") {
        // rule 1 code
    }
end

Aha… but in this case I have to update manually each rule. So there is not any other possibility.

Yep
If you want to add complicated behaviour to OH you will HAVE to modify your rules…

Thanks!

Cool, please mark the thread as solved, thanks