I have this rule:
rule “Xiaomi_Switch”
when
Channel “mihome:sensor_switch:158d00020exxx:button” triggered
then
var actionName = receivedEvent.getEvent()
switch(actionName)
{
case “SHORT_PRESSED”:
{
VernerPanton.sendCommand(OFF)
}
case “DOUBLE_PRESSED”:
{
SpisebordLampe.sendCommand(OFF)
}
case “LONG_PRESSED”:
{
VernerPanton.sendCommand(ON)
}
case “LONG_RELEASED”:
{
SpisebordLampe.sendCommand(ON)
}
}
end
I know it is not an answer as to why your rule doesn’t work but I use the following:
rule "Xiaomi Master Switch LONG_PRESSED"
when
Channel "mihome:sensor_switch:158d00018b4015:button" triggered LONG_PRESSED
then
MasterEnsuiteFanLightSwitch.sendCommand(ON)
end
rule "Xiaomi_Switch"
when
Channel "mihome:sensor_switch:158d00020exxx:button" triggered
then
var actionName = receivedEvent.getEvent()
logInfo("xiaomi","action is {}",actionName) //<---
switch(actionName) {
case "SHORT_PRESSED":
VernerPanton.sendCommand(OFF)
case "DOUBLE_PRESSED":
SpisebordLampe.sendCommand(OFF)
case "LONG_PRESSED":
VernerPanton.sendCommand(ON)
case "LONG_RELEASED":
SpisebordLampe.sendCommand(ON)
default: //<---
logInfo("xiaomi","No match found for {}",actionName) //<---
}
end
Please add some logging to ensure the rule is triggered at all.
Are you using the xxx in the device id in your rule or have you just put that in to hide the id?
If it is in your rule you need to replace it with your actual id which can be read from the PaperUI -> Configuration -> Thing for your switch.
Yeah, The errors make sense because the thing is not actually a switch as OH sees things so ON and OFF don’t mean anything to it. That is why it is necessary to capture the events.
The interesting thing is that your logInfo statements aren’t generating log entries, which would suggest the rule is not being triggered at all.
To me that would suggest you have something wrong in the Channel “mihome…” definition, but there really isn’t much information to help us help you.
I can only suggest that maybe you should delete re-type that line in case there is something wrong or a strange character in the line. I have had problems occasionally with code I have cut and pasted which were fixed by simply typing what appears to be the same thing.
I can connect to all my 23 devices/sensors in MI. And all of them react in OpenHAB - except the button.
I have the problem that OpenHAB loses the connection to the sensors. If I change the IP to hostname it is online again on the gateway and updated in openhab.
Can see in the log on the MI gateway that I have clicked on the button.
rule "Xiomi Master Switch SHORT_PRESSED"
when
Channel "mihome:sensor_switch:158d00020eb3f0:button" triggered SHORT_PRESSED
then
VernerPanton.sendCommand(OFF)
end