please read this
Oh, for some reason I missed the part what rlkoshak mentionedâŠ
So after reading it, I tried this:
case receivedCommand >= 0 && receivedCommand <= 100 :
mqttActions.publishMQTT("cmnd/Shelly25RollerShutter_Back/ShutterPosition1", "50")
This doesnât throw any error, but also the case donât get triggered. As soon as I change receivedCommand to receivedCommand as Number, it keeps complaining this: âno viable alternative at inputâ
So since rossko57 mention that the receivedCommand isnât a numeric variable, I tried this:
rule "Rollershutter back"
when
Item shutterBack received command
then
val mqttActions = getActions("mqtt","mqtt:broker:mosquitto")
var Number shutterPosistion = receivedCommand as Number
logInfo("Rollershutter rule", "First part, value of shutterPosistion is = " + shutterPosistion.toString)
switch (receivedCommand) {
case UP :
mqttActions.publishMQTT("cmnd/Shelly25RollerShutter_Back/Backlog", "shutteropen")
case STOP :
mqttActions.publishMQTT("cmnd/Shelly25RollerShutter_Back/Backlog", "shutterstop")
case DOWN :
mqttActions.publishMQTT("cmnd/Shelly25RollerShutter_Back/Backlog", "shutterclose")
case shutterPosistion >= 0 && shutterPosistion <= 100 :
mqttActions.publishMQTT("cmnd/Shelly25RollerShutter_Back/ShutterPosition1", "50")
}
logInfo("Rollershutter rule", "Second part, value of shutterPosistion is = " + shutterPosistion.toString)
end
But again, the case donât to seemed triggered by the value, also tried including the loginfo inside the switch{} part but that seem te be possible either, who can help me out?
Iâm not an expert in Rules DSL and I havenât used it in a while, but try this:
rule "Rollershutter back"
when
Item shutterBack received command
then
val mqttActions = getActions("mqtt","mqtt:broker:mosquitto")
logInfo("Rollershutter rule", "First part, value of shutterPosistion is = " + shutterPosistion.toString)
switch (receivedCommand) {
case UP :
mqttActions.publishMQTT("cmnd/Shelly25RollerShutter_Back/Backlog", "shutteropen")
case STOP :
mqttActions.publishMQTT("cmnd/Shelly25RollerShutter_Back/Backlog", "shutterstop")
case DOWN :
mqttActions.publishMQTT("cmnd/Shelly25RollerShutter_Back/Backlog", "shutterclose")
default : {
var shutterPosistion = (receivedCommand as Number)
if (shutterPosistion >= 0 && shutterPosistion <= 100) {
mqttActions.publishMQTT("cmnd/Shelly25RollerShutter_Back/ShutterPosition1", "50")
}
}
}
logInfo("Rollershutter rule", "Second part, value of shutterPosistion is = " + shutterPosistion.toString)
end
This isnât going to work if receivedCommand is for example STOP.
See JimT suggestion to only attempt number if you already know it is not UP/DOWN/STOP
You might like to think about the logic a bit more though ⊠if it is a command that is not UP/DOWN/STOP, what else could it be apart from a number 0-100?
Thanks, that did the trick, I now ended up with this rule and it works like I wanted. If controlled by the rollershutter buttons from OH, it does what it suppose to de, when controlled by Apple HomeKit, it also does what you command it to do:
rule "Rollershutter back"
when
Item shutterBack received command
then
val mqttActions = getActions("mqtt","mqtt:broker:mosquitto")
switch (receivedCommand) {
case UP :
mqttActions.publishMQTT("cmnd/Shelly25RollerShutter_Back/Backlog", "shutteropen")
case STOP :
mqttActions.publishMQTT("cmnd/Shelly25RollerShutter_Back/Backlog", "shutterstop")
case DOWN :
mqttActions.publishMQTT("cmnd/Shelly25RollerShutter_Back/Backlog", "shutterclose")
default : {
var shutterPosistion = (receivedCommand as Number)
if (shutterPosistion >= 0 && shutterPosistion <= 100) {
mqttActions.publishMQTT("cmnd/Shelly25RollerShutter_Back/ShutterPosition1", shutterPosistion.toString)
}
}
}
end
Maybe if somebody is looking for something similar, this will help.
Yea I checked the openHAB Log Viewer when I used the Apple HomeKit item to see what command it will send when you do different things with it. It will always send a number between 0-100, so for now, this rule will work like it suppose to do
Yes, my point was that the following code is therefore redundant
Itâs always true, you donât ever get to this test if it were UP/DOWN/STOP