I just uncovered a bug in one of my rules that I migrated from DSL to JavaScript some time ago.
The setup is something like this:
Item:
Switch TestTimer_Switch { expire="15m,command=OFF" }
The DSL rule:
rule "Test Timer DSL"
when
Item TestTimer_Switch received command OFF
then
logInfo("Test Timer", "Received command OFF")
end
And the part of a rule restarting the timer:
items.TestTimer_Switch.postUpdate("OFF");
items.TestTimer_Switch.sendCommand("ON");
Now, the rule having the bug which was driving me crazy:
rules.when()
.item("TestTimer_Switch").receivedCommand("OFF")
.then(event => {
console.log("Received command OFF");
})
.build("Test Timer JS");
And the bugfixed version:
rules.when()
.item("TestTimer_Switch").receivedCommand()
.then(event => {
if (event.receivedCommand == "OFF") {
console.log("Received command OFF");
}
})
.build("Test Timer Cmd JS");
The real rule has multiple triggers, so actually had to check the item as well:
if (event.itemName == "OfficeTvSocketIdle" && event.receivedCommand != "OFF") {
return;
}
After reading the documentation, the mistake in my migration from DSL to JavaScript became obvious, but nevertheless, I'm wondering if it would make sense - and is feasible - to support providing the command in the Rule Builder Trigger? I.e. so that it would be possible to use .receivedCommand("OFF") (as an example).
Your Environment
- openHAB version used: 4.2.2
- openhab-js version used: 5.3.1