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.