# Xiomi (MI) Switch rule - nothing happens

**URL:** <https://community.openhab.org/t/xiomi-mi-switch-rule-nothing-happens/52456>\
**Category:** Scripts & Rules\
**Created:** [September 27, 2018, 7:47pm UTC](https://community.openhab.org/t/xiomi-mi-switch-rule-nothing-happens/52456 "2018-09-27T19:47:28Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbagh](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jbagh](https://community.openhab.org/u/jbagh)\
**Post date:** [September 27, 2018, 7:47pm UTC](https://community.openhab.org/t/xiomi-mi-switch-rule-nothing-happens/52456/1 "2018-09-27T19:47:28Z")

</div>

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 …

---

<div class="post-metadata">

**Author:** ![vzorglub](https://community.openhab.org/user_avatar/community.openhab.org/vzorglub/32/17166_2.png) [@vzorglub](https://community.openhab.org/u/vzorglub)\
**Post date:** [September 27, 2018, 10:10pm UTC](https://community.openhab.org/t/xiomi-mi-switch-rule-nothing-happens/52456/2 "2018-09-27T22:10:24Z")

</div>

Please use the [code fences](https://community.openhab.org/t/how-to-use-code-fences/38383)  
What do you see in the logs when you press the button?

---

<div class="post-metadata">

**Author:** ![jrb5665](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/b38774/32.png) [@jrb5665](https://community.openhab.org/u/jrb5665)\
**Post date:** [September 28, 2018, 4:14am UTC](https://community.openhab.org/t/xiomi-mi-switch-rule-nothing-happens/52456/3 "2018-09-28T04:14:15Z")

</div>

I know it is not an answer as to why your rule doesn’t work but I use the following:

```php
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

---

<div class="post-metadata">

**Author:** ![Udo\_Hartmann](https://community.openhab.org/user_avatar/community.openhab.org/udo_hartmann/32/70871_2.png) [@Udo\_Hartmann](https://community.openhab.org/u/Udo_Hartmann)\
**Post date:** [September 28, 2018, 8:15am UTC](https://community.openhab.org/t/xiomi-mi-switch-rule-nothing-happens/52456/4 "2018-09-28T08:15:24Z")

</div>

```auto
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.

---

<div class="post-metadata">

**Author:** ![jbagh](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jbagh](https://community.openhab.org/u/jbagh)\
**Post date:** [September 29, 2018, 9:00am UTC](https://community.openhab.org/t/xiomi-mi-switch-rule-nothing-happens/52456/5 "2018-09-29T09:00:17Z")

</div>

Absolutely nothing in the log…

---

<div class="post-metadata">

**Author:** ![jrb5665](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/b38774/32.png) [@jrb5665](https://community.openhab.org/u/jrb5665)\
**Post date:** [September 29, 2018, 9:12am UTC](https://community.openhab.org/t/xiomi-mi-switch-rule-nothing-happens/52456/6 "2018-09-29T09:12:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jbagh](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jbagh](https://community.openhab.org/u/jbagh)\
**Post date:** [September 29, 2018, 9:15am UTC](https://community.openhab.org/t/xiomi-mi-switch-rule-nothing-happens/52456/7 "2018-09-29T09:15:26Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![jrb5665](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/b38774/32.png) [@jrb5665](https://community.openhab.org/u/jrb5665)\
**Post date:** [September 29, 2018, 9:19am UTC](https://community.openhab.org/t/xiomi-mi-switch-rule-nothing-happens/52456/8 "2018-09-29T09:19:19Z")

</div>

Is there anything else in the rules file?

---

<div class="post-metadata">

**Author:** ![jbagh](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jbagh](https://community.openhab.org/u/jbagh)\
**Post date:** [September 29, 2018, 9:20am UTC](https://community.openhab.org/t/xiomi-mi-switch-rule-nothing-happens/52456/9 "2018-09-29T09:20:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jrb5665](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/b38774/32.png) [@jrb5665](https://community.openhab.org/u/jrb5665)\
**Post date:** [September 29, 2018, 9:27am UTC](https://community.openhab.org/t/xiomi-mi-switch-rule-nothing-happens/52456/10 "2018-09-29T09:27:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jrb5665](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/b38774/32.png) [@jrb5665](https://community.openhab.org/u/jrb5665)\
**Post date:** [September 29, 2018, 9:30am UTC](https://community.openhab.org/t/xiomi-mi-switch-rule-nothing-happens/52456/11 "2018-09-29T09:30:11Z")

</div>

I should have also asked but do you see the correct responses in the Xiaomi MiHome app?

---

<div class="post-metadata">

**Author:** ![jbagh](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jbagh](https://community.openhab.org/u/jbagh)\
**Post date:** [September 29, 2018, 9:36am UTC](https://community.openhab.org/t/xiomi-mi-switch-rule-nothing-happens/52456/12 "2018-09-29T09:36:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jbagh](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jbagh](https://community.openhab.org/u/jbagh)\
**Post date:** [September 29, 2018, 9:36am UTC](https://community.openhab.org/t/xiomi-mi-switch-rule-nothing-happens/52456/13 "2018-09-29T09:36:50Z")

</div>

Just tried to manually retype the entire rule.. Same result

---

<div class="post-metadata">

**Author:** ![jbagh](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jbagh](https://community.openhab.org/u/jbagh)\
**Post date:** [September 29, 2018, 9:56am UTC](https://community.openhab.org/t/xiomi-mi-switch-rule-nothing-happens/52456/14 "2018-09-29T09:56:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jrb5665](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/b38774/32.png) [@jrb5665](https://community.openhab.org/u/jrb5665)\
**Post date:** [September 29, 2018, 10:01am UTC](https://community.openhab.org/t/xiomi-mi-switch-rule-nothing-happens/52456/15 "2018-09-29T10:01:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jbagh](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jbagh](https://community.openhab.org/u/jbagh)\
**Post date:** [September 29, 2018, 10:14am UTC](https://community.openhab.org/t/xiomi-mi-switch-rule-nothing-happens/52456/16 "2018-09-29T10:14:31Z")

</div>

Tried that

```php
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…

---

<div class="post-metadata">

**Author:** ![jrb5665](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/b38774/32.png) [@jrb5665](https://community.openhab.org/u/jrb5665)\
**Post date:** [September 29, 2018, 10:18am UTC](https://community.openhab.org/t/xiomi-mi-switch-rule-nothing-happens/52456/17 "2018-09-29T10:18:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jbagh](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jbagh](https://community.openhab.org/u/jbagh)\
**Post date:** [September 29, 2018, 10:20am UTC](https://community.openhab.org/t/xiomi-mi-switch-rule-nothing-happens/52456/18 "2018-09-29T10:20:27Z")

</div>

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..

---

<div class="post-metadata">

**Author:** ![jrb5665](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/b38774/32.png) [@jrb5665](https://community.openhab.org/u/jrb5665)\
**Post date:** [September 29, 2018, 10:35am UTC](https://community.openhab.org/t/xiomi-mi-switch-rule-nothing-happens/52456/19 "2018-09-29T10:35:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jbagh](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jbagh](https://community.openhab.org/u/jbagh)\
**Post date:** [September 29, 2018, 10:50am UTC](https://community.openhab.org/t/xiomi-mi-switch-rule-nothing-happens/52456/20 "2018-09-29T10:50:50Z")

</div>

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

[Next page](https://community.openhab.org/t/xiomi-mi-switch-rule-nothing-happens/52456.md?page=2)
