Question about Rules in OH3

  • Platform information:
    • Hardware: RPi 4 / 4GB
    • OS: Debian Bullseye
    • Java Runtime Environment: Zulu 11
    • openHAB version: 3.4.3
  • Issue of the topic: I have a question about rules created via the UI vs. rules I create textually.

I have created several rules via the UI to automatically control lights.
This creates dozens of rules and now I was wondering if it is possible to simply build a rule via the UI that then processes what arrives.

In my previous attempts, I guess I was thinking too simply, because if I use multiple triggers as “when”, all “then” events are processed one after the other.
I just thought if I trigger “AA”, event “AA” is triggered, if trigger “AB”, then event “AB” and so on.

I know that I can create such sequences in a text-based rule according to the scheme:
Filename like “Auto_Lights_Rule”

rule: “Test”

when: “Trigger Item”

then: “Event Item”

if: “…”

rule: “Test1”

when: “Trigger Item”

…and so on.

Now the question, is a collection rule only text-based possible or also via the UI?

Thanks a lot and excuse my bad English.

That rule is exactly what you’ve described doing in the UI. One rule per Item.

If I understand correctly, you want to process events from multiple Items in one rule, perhaps doing something slightly different based on the Item that triggered the rule.

Of course this is possible but not with pure UI rules. You will have to use a Script Action and code the actions same as you would in a .rules file. In the Script Action you only put the stuff that goes between the when and end.

So if the rule is triggered by ItemA, ItemB, and ItemC you could create a Rules DSL Script Action under then:

if(triggeringItemName == "ItemA") {
else if(triggeringItemName == "ItemB") {
else if(triggeringItemName == "ItemC") {

Of course, if everything truly is different for each Item it’s probably best to put each into a separate rule just triggered by that one Item.

Be sure to review the rules pages of the Getting Started Tutorial which covers all the different ways to create rules in MainUI.

Also, I recommend Blockly over Rules DSL.