Is the a method to determine which trigger fire a rule if the riggers are channels?
rule "Nest Binding LogReader"
when
Channel "logreader:reader:someBindingLogReader:newErrorEvent" triggered or
Channel "logreader:reader:someBindingLogReader:newWarningEvent" triggered
then
//Pseudo Code
logInfo("myLog", ruleTrigger.name)
end
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.
receivedEvent.channel.toString // Full 'channel' that triggered the event
receivedEvent.channel.thingUID.toString // Thing ID portion of channel (everything before the last ':')
receivedEvent.channel.id.toString // ID portion of channel (everything after the last ':')
Also, 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”) {
logger.info(“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)?
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.
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.