Rule with Multiple Channel Triggers - Which one?

Is the a method to determine which trigger fire a rule if the riggers are channels?

rule "Nest Binding LogReader"
        Channel "logreader:reader:someBindingLogReader:newErrorEvent" triggered or
        Channel "logreader:reader:someBindingLogReader:newWarningEvent" triggered
        //Pseudo Code



Unfortunately not in Rules DSL. In JSR223 and PaperUI Rules this is possible.

There is a receivedEvent implicit variable that holds the dates part of the event, if there is any. Perhaps if the two events have different data you can use that.

Yes there is: // Full 'channel' that triggered the event // Thing ID portion of channel (everything before the last ':') // ID portion of channel (everything after the last ':')

receivedEvent.Event provides access to the ‘payload’ of the event


Excuse the dummy-question, but I didn’t get this working with the java-script-rules in OH3, I assume the answer in this threat was OH2-only (I´m currently running openHAB 3.2.0.M1)

I did:
if (receivedEvent.Event.toString == “rein”) {“Markise einfahren”);

and I got:

2021-09-02 06:29:17.687 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘bc70be9ce9’ failed: ReferenceError: “receivedEvent” is not defined in at line number 3

What did I do wrong?? Or is there any better way of getting the item, which triggers the rule (or, more detailed, the state of it)?


receivedEvent is still there in OH3, but it’s nature has changed. It’s just a string now, with no .Event method.

Thanks for response @rossko57 !

if(receivedEvent == “rein”) {
//events.sendCommand(‘AlexaBuro_Sprich’, “Markise einfahren”);“Markise einfahren”);
should work??

tried also with receivedCommand instead of receivedEvent, but still got the reference-error from above.

do i have to do something else??

I dunno from this fragment. This isn’t DSL, don’t you have to use the event object?

You are correct, this isn’t DSL, this is JavaScript (ECMA). Is this my misunderstanding?
Does ‘receivedEvent’ and ‘receivedCommand’ only work in DSL??
If so, how can this be done then in JavaScript?

that’s what I´ve done:
The rule is triggered by one of the phones of my family-members (via MQTT, but I assume, this is not of interest). The items are string-items and contain a command. In this case “rein” or “raus”, but there are several more possibilities like “ein”, “aus”, “auf”, “ab” etc… Independent of which phone the rule has triggered, the action I want to do is the same.

  - id: "1"
      itemName: iPhonevonAndreasiPhoneSE_Siri
    type: core.ItemCommandTrigger
  - id: "2"
      itemName: iPhonevonDavidiPhoneXR_Siri_iPhoneV
    type: core.ItemCommandTrigger
  - id: "4"
      itemName: iPhonevonDanieliPhoneXR_Siri_iPhoneN
    type: core.ItemCommandTrigger
  - id: "5"
      itemName: iPhonevonMartinaiPhoneXR_Siri_iPhoneM
    type: core.ItemCommandTrigger
conditions: []
  - inputs: {}
    id: "3"
      type: application/javascript
      script: >+
        // logging einschalten

        var logger = Java.type("org.slf4j.LoggerFactory").getLogger("org.openhab.model.script.Rules.Siri");
  "Siri Kommando");

        if(receivedEvent == "rein") { 
            events.sendCommand('AlexaBuro_Sprich', "Markise einfahren");
  "Markise einfahren");
        if(receivedEvent == "raus") { 
            events.sendCommand('AlexaBuro_Sprich', "Markise ausfahren");
  "Markise ausfahren");

    type: script.ScriptAction

Well, sendCommand() only works in DSL. When you choose another language, you have to find out the equivalent way to get the same methods.
In this case, you use events.sendCommand() as equivalent.

Your task is to find out the similar way to use ‘receivedEvent’ and ‘receivedCommand’

Then there’s the logic problem. The rule you have shown us is triggered by command. There should be a receivedCommand implicit variable available to you, but not a receivedEvent because that is about channel-based rule triggers, and you don’t have any channel triggers here.

1 Like

LOL, you let me learn it the hard way… :slight_smile:

BUT: Got it now. Understood you explanation, did some research and found … “event.itemCommand” which is exactly doing what I was looking for.

Thanks a lot for your patience with me :+1:

1 Like