Multiselection rules

Hi There,

i want to control my shutter with the exec binding and run my script with the arguments from switch.
When i press it the log shows an error:

[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Shuttercontrol’: An error occurred during the script execution: index=1, size=1

shuttercontrol.items

String shuttercontrol_shutter   "Jalousieren"   <shutter>

Switch shuttercontrol_gateway_run    { channel="exec:command:shuttercontrol_gateway:run" }
String shuttercontrol_gateway_args   { channel="exec:command:shuttercontrol_gateway:input" } 
String shuttercontrol_gateway_out    { channel="exec:command:shuttercontrol_gateway:output" }

shuttercontrol.things

Thing exec:command:shuttercontrol_gateway "CMD - Shutter Gateway" [
        command="/etc/openhab2/scripts/shuttercontrol %2$s",
        interval=0,
        autorun=true]

shuttercontrol.rules

rule "Shuttercontrol"
 when
   Item shuttercontrol_shutter received command
 then
   logInfo(receivedCommand)
   logInfo("1")
   shuttercontrol_gateway_args.sendCommand(receivedCommand)
   logInfo("2")
end

shuttercontrol.sitemap

sitemap shutter label="Jalousien"
{
        Frame label="Stuff"
        {
                Switch item=shuttercontrol_shutter mappings=["up"="Hoch", "center"="Mitte", "down"="Unten"]
        }
}

So, how i get fixed this? I tried to changed the item-type of shuttercontrol_shutter to Switch but than i got this “error”:

[WARN ] [rest.core.internal.item.ItemResource] - Received HTTP POST request at ‘items/shuttercontrol_shutter’ with an invalid status value ‘up’.

I’ve read that switches only can store ON and OFF but in reason of possibility to define mappings in the sitemap i’m not sure if its true. And maybe item-type String has no received command event?

Lukas

Not sure if it’s the cause of your error, but your logInfo statements is wrong. logInfo needs two strings as arguments, the name of the logger and the logmessage.

Example:

rule "Shuttercontrol"
 when
   Item shuttercontrol_shutter received command
 then
   logInfo("Shuttercontrol", receivedCommand.toString)
   logInfo("Shuttercontrol", "1")
   shuttercontrol_gateway_args.sendCommand(receivedCommand)
   logInfo("Shuttercontrol", "2")
end
1 Like

Thats it! Thanks a lot!

By the way:
The sendCommand-function also need a string.

Hopefully i will learn to code rules in the future :wink: