Has somebody already found out how to use “receivedCommand” inside a JSS rule in the UI? From old ECMA tutorials it should be “command” but the UI does not know how to proceed. Additionally would be nice how achieve the same behavior: “instanceof Number” in JSS.
Thanks for your help!
Thats the old DSL rule:
rule "Rollershutter"
when
Item Sonoff15_rollershutter received command
then
if(!(receivedCommand instanceof Number)){
switch receivedCommand
{
case DOWN : Sonoff15_Number.sendCommand(0)
case UP : Sonoff15_Number.sendCommand(100)
default : {}
}
}else{
val Number rollershutter = Sonoff15_rollershutter as DecimalType).intValue
Sonoff15_Number.sendCommand(rollershutter)
}
end
EDIT:
New JS-Rule:
switch (String(event.itemCommand)){
case "DOWN" : items.getItem("Sonoff15_Number").sendCommand("0")
break;
case "UP" : items.getItem("Sonoff15_Number").sendCommand("100")
break;
case "STOP" : items.getItem("Sonoff15_ShutterStop").sendCommand("STOP")
break;
default:
items.getItem("Sonoff15_Number").sendCommand(items.getItem("Sonoff15_rollershutter").state)
break;
}
I was dealing with a similar issue wanting to access the receivedCommand for an ItemCommandTrigger and stumbled upon this thread. Unfortunately my very simple rule fails to execute. Here’s the code:
var {event, items, log, rules, triggers} = require("openhab")
let logger = log("tests");
rules.JSRule({
name: "[TESTING] Test Switch Received Command",
description: "Log the item name, state and received command",
triggers: [
triggers.ItemCommandTrigger("testSwitch")
],
execute: data => {
let itemName = event.itemName;
}
});
I’m running openhab 3.2.0.M2 in a Docker container on a Raspberry Pi 3 running raspbian lite. I have configured the JSScriping Extension through Main UI to not use built-in variables. Any idea why this doesn’t work?
It produced an error with only that statement. I have elaborated further in this post. I was accessing an undefined variable, that problem is fixed now. Unfortunately, that the property of that variable I’m trying to access is somehow undefined and I have no idea why.
The problem was much deeper than expected but I found a solution which I have described in detail as a reply to my other post. I’ll just leave the link here in case anyone stumbles upon this post while dealing with a similar issue.