Xiomi (MI) Switch rule - nothing happens

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

Log is ok - but nothing happens …

Please use the code fences
What do you see in the logs when you press the button?

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

with one rule for each triggered event

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.

Absolutely nothing in the log…

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.

Just did the xx to hide it.

log:
11:12:54.737 [INFO ] [del.core.internal.ModelRepositoryImpl] - Refreshing model ‘xiomi.rules’
11:12:59.767 [INFO ] [org.quartz.core.QuartzScheduler ] - Scheduler openHAB-job-scheduler_$_NON_CLUSTERED started.

It’s added as thing. It was detected when I scanned the mi binding.

And i have even added it as an item (even though it is not needed)

Is there anything else in the rules file?

No. Nothing else in the rule file.

Log when I press it in the PaperUI…

11:19:26.112 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘sluk_alt_knap1’ received command ON
11:19:26.112 [ERROR] [rnal.common.AbstractInvocationHandler] - An error occurred while calling method ‘EventSubscriber.receive()’ on ‘org.eclipse.smarthome.core.thing.internal.CommunicationManager@3be02bd1’: null
java.lang.NullPointerException: null
11:19:26.114 [INFO ] [smarthome.event.ItemStateChangedEvent] - sluk_alt_knap1 changed from NULL to ON
11:19:26.116 [ERROR] [ome.core.internal.events.EventHandler] - Dispatching/filtering event for subscriber ‘org.eclipse.smarthome.core.events.EventSubscriber’ failed: null
java.lang.NullPointerException: null
11:19:26.117 [ERROR] [rnal.common.AbstractInvocationHandler] - An error occurred while calling method ‘EventSubscriber.receive()’ on ‘org.eclipse.smarthome.core.thing.internal.CommunicationManager@3be02bd1’: null
java.lang.NullPointerException: null
11:19:26.117 [ERROR] [ome.core.internal.events.EventHandler] - Dispatching/filtering event for subscriber ‘org.eclipse.smarthome.core.events.EventSubscriber’ failed: null
java.lang.NullPointerException: null
11:19:26.920 [ERROR] [rnal.common.AbstractInvocationHandler] - An error occurred while calling method ‘EventSubscriber.receive()’ on ‘org.eclipse.smarthome.core.thing.internal.CommunicationManager@3be02bd1’: null
java.lang.NullPointerException: null
11:19:26.920 [ERROR] [ome.core.internal.events.EventHandler] - Dispatching/filtering event for subscriber ‘org.eclipse.smarthome.core.events.EventSubscriber’ failed: null
java.lang.NullPointerException: null
11:19:26.920 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘sluk_alt_knap1’ received command OFF
11:19:26.921 [ERROR] [rnal.common.AbstractInvocationHandler] - An error occurred while calling method ‘EventSubscriber.receive()’ on ‘org.eclipse.smarthome.core.thing.internal.CommunicationManager@3be02bd1’: null
java.lang.NullPointerException: null
11:19:26.921 [INFO ] [smarthome.event.ItemStateChangedEvent] - sluk_alt_knap1 changed from ON to OFF
11:19:26.922 [ERROR] [ome.core.internal.events.EventHandler] - Dispatching/filtering event for subscriber ‘org.eclipse.smarthome.core.events.EventSubscriber’ failed: null
java.lang.NullPointerException: null

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 should have also asked but do you see the correct responses in the Xiaomi MiHome app?

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.

Just tried to manually retype the entire rule… Same result

Appriciate the help. what else can I export to debug?

Have you tried a rule in the format I sent in my earlier post where you specify the trigger value there?

Tried that

rule "Xiomi Master Switch SHORT_PRESSED"
when
	Channel "mihome:sensor_switch:158d00020eb3f0:button" triggered SHORT_PRESSED
then
		VernerPanton.sendCommand(OFF)
end

Still nothing… Something is broken…

Have you checked the devices log on the MiHome App like I suggested?
Do you see the click and double-click messages?

Yes. If I goto the gateway. I see the button. And if I click on it I see the activity on the button… Fully updated…

Did you put the gateway into developer mode and enter the key on the Things for the gateway?

Yes. My temp sensors and door/window sensors have been working for ages… But this is my first rule…