Mi(Xiaomi) Smart home bindings?

Hi Everybody,

First of all, thank you for this binding.

Anybody try this, when have 2 vlan?
I have the server in 192.18.0.0/24 [A vlan] but the Chines stuff(like this) in 192.168.10.0/24 [B vlan]
When the server and the gateway in the same vlan,work as expected. But when I move it to secure vlan, its stop working.
The Openhab say its “Online”, but when I change for example the lamp, I get this error:

20:47:17.584 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘Gateway_Brightness’ received command 53
20:47:17.587 [INFO ] [marthome.event.ItemStateChangedEvent] - Gateway_Brightness changed from 16 to 53
java.lang.NullPointerException
at org.openhab.binding.mihome.internal.EncryptionHelper.encrypt(EncryptionHelper.java:35)
at org.openhab.binding.mihome.internal.EncryptionHelper.encrypt(EncryptionHelper.java:25)
at org.openhab.binding.mihome.handler.XiaomiBridgeHandler.getEncryptedKey(XiaomiBridgeHandler.java:282)
at org.openhab.binding.mihome.handler.XiaomiBridgeHandler.createDataJsonString(XiaomiBridgeHandler.java:267)
at org.openhab.binding.mihome.handler.XiaomiBridgeHandler.writeToBridge(XiaomiBridgeHandler.java:263)
at org.openhab.binding.mihome.handler.XiaomiActorGatewayHandler.writeBridgeLightColor(XiaomiActorGatewayHandler.java:191)
at org.openhab.binding.mihome.handler.XiaomiActorGatewayHandler.writeBridgeLightColor(XiaomiActorGatewayHandler.java:187)
at org.openhab.binding.mihome.handler.XiaomiActorGatewayHandler.execute(XiaomiActorGatewayHandler.java:53)
at org.openhab.binding.mihome.handler.XiaomiDeviceBaseHandler.handleCommand(XiaomiDeviceBaseHandler.java:100)
at org.eclipse.smarthome.core.thing.internal.ThingManager$4.call(ThingManager.java:374)
at org.eclipse.smarthome.core.thing.internal.ThingManager$4.call(ThingManager.java:1)
at org.eclipse.smarthome.core.common.SafeMethodCaller.executeDirectly(SafeMethodCaller.java:218)
at org.eclipse.smarthome.core.common.SafeMethodCaller.callAsynchronous(SafeMethodCaller.java:189)
at org.eclipse.smarthome.core.common.SafeMethodCaller.call(SafeMethodCaller.java:83)
at org.eclipse.smarthome.core.common.SafeMethodCaller.call(SafeMethodCaller.java:67)
at org.eclipse.smarthome.core.thing.internal.ThingManager.receiveCommand(ThingManager.java:371)
at org.eclipse.smarthome.core.items.events.AbstractItemEventSubscriber.receive(AbstractItemEventSubscriber.java:46)
at org.eclipse.smarthome.core.internal.events.OSGiEventManager$1.call(OSGiEventManager.java:192)
at org.eclipse.smarthome.core.internal.events.OSGiEventManager$1.call(OSGiEventManager.java:1)
at org.eclipse.smarthome.core.common.SafeMethodCaller$CallableWrapper.call(SafeMethodCaller.java:181)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

Any idea?
THX

BR,
O.

Your welcome :slight_smile:

Seems like the binding is either missing the developer key or the gateway token.

please check, if your server in A VLAN receives heartbeat messages from the gateway.
enable DEBUG logging for the binding in the console of karaf and check if you get messages which look like this:

2017-04-22 21:53:45.078 [DEBUG] [me.handler.XiaomiActorGatewayHandler] - Item got update: {"cmd":"heartbeat","model":"gateway","sid":"xxxx","short_id":"0","token":"70TmuQW5QTln1BX4","data":"{\"ip\":\"192.168.0.xxx\"}"}

to be able to write values to the gateway you need to have the token (which is in this heartbeat message and gets updated every 10sec), and the developer key you get from the xiaomi app as described in the readme for the binding.

Are you receiving value updates from sensors etc. when in different VLANs? Then at least multicast traffic should be routed.
Multicast address is 224.0.0.50, port is 9898

Thank your quick answer!
From Service vlan, cant create any connection to server vlan or to internet. Everything disabled. :confused:
Enough the multicast ip?

at least multicast traffic and the port, I’d say…

1 Like

Still I have no luck. On mikrotik not so easy to setup this :slight_smile:
now I have a little bit different error log, but I think, this is the same issue…

09:35:06.805 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘Gateway_LightSwitch’ received command ON
09:35:06.806 [DEBUG] [me.handler.XiaomiActorGatewayHandler] - Device 286c07888601 on channel mihome:gateway:286c07888601:brightness received command ON
java.lang.NullPointerException
at org.openhab.binding.mihome.internal.EncryptionHelper.encrypt(EncryptionHelper.java:35)
at org.openhab.binding.mihome.internal.EncryptionHelper.encrypt(EncryptionHelper.java:25)
at org.openhab.binding.mihome.handler.XiaomiBridgeHandler.getEncryptedKey(XiaomiBridgeHandler.java:282)
at org.openhab.binding.mihome.handler.XiaomiBridgeHandler.createDataJsonString(XiaomiBridgeHandler.java:267)09:35:06.808 [INFO ] [marthome.event.ItemStateChangedEvent] - Gateway_LightSw
itch changed from OFF to ON

    at org.openhab.binding.mihome.handler.XiaomiBridgeHandler.writeToBridge(XiaomiBridgeHandler.java:263)
    at org.openhab.binding.mihome.handler.XiaomiActorGatewayHandler.writeBridgeLightColor(XiaomiActorGatewayHandler.java:191)
    at org.openhab.binding.mihome.handler.XiaomiActorGatewayHandler.writeBridgeLightColor(XiaomiActorGatewayHandler.java:187)
    at org.openhab.binding.mihome.handler.XiaomiActorGatewayHandler.execute(XiaomiActorGatewayHandler.java:75)
    at org.openhab.binding.mihome.handler.XiaomiDeviceBaseHandler.handleCommand(XiaomiDeviceBaseHandler.java:100)
    at org.eclipse.smarthome.core.thing.internal.ThingManager$4.call(ThingManager.java:374)
    at org.eclipse.smarthome.core.thing.internal.ThingManager$4.call(ThingManager.java:1)
    at org.eclipse.smarthome.core.common.SafeMethodCaller.executeDirectly(SafeMethodCaller.java:218)
    at org.eclipse.smarthome.core.common.SafeMethodCaller.callAsynchronous(SafeMethodCaller.java:189)
    at org.eclipse.smarthome.core.common.SafeMethodCaller.call(SafeMethodCaller.java:83)
    at org.eclipse.smarthome.core.common.SafeMethodCaller.call(SafeMethodCaller.java:67)
    at org.eclipse.smarthome.core.thing.internal.ThingManager.receiveCommand(ThingManager.java:371)
    at org.eclipse.smarthome.core.items.events.AbstractItemEventSubscriber.receive(AbstractItemEventSubscriber.java:46)
    at org.eclipse.smarthome.core.internal.events.OSGiEventManager$1.call(OSGiEventManager.java:192)
    at org.eclipse.smarthome.core.internal.events.OSGiEventManager$1.call(OSGiEventManager.java:1)
    at org.eclipse.smarthome.core.common.SafeMethodCaller$CallableWrapper.call(SafeMethodCaller.java:181)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

09:35:06.812 [DEBUG] [g.mihome.handler.XiaomiBridgeHandler] - Send to bridge: {“cmd”: “write”,“model”: “gateway”,“sid”: “286c07888601”,“short_id”: “0”,“data”: “{“rgb”: 603979776, “key”: “”
}”}
09:35:06.813 [DEBUG] [.mihome.internal.socket.XiaomiSocket] - Sending message: {“cmd”: “write”,“model”: “gateway”,“sid”: “286c07888601”,“short_id”: “0”,“data”: “{“rgb”: 603979776, “key”: “
”}”} to /10.6.2.47
09:35:06.853 [DEBUG] [g.mihome.handler.XiaomiBridgeHandler] - Received message {“cmd”:“write_ack”,“sid”:“286c07888601”,“data”:"{“error”:“Invalid key len”}"}
09:35:06.853 [DEBUG] [g.mihome.handler.XiaomiBridgeHandler] - Updated “last time seen” for device 286c07888601
09:35:06.853 [DEBUG] [g.mihome.handler.XiaomiBridgeHandler] - Device 286c07888601 honored write request
09:35:06.854 [DEBUG] [me.handler.XiaomiActorGatewayHandler] - Item got update: {“cmd”:“write_ack”,“sid”:“286c07888601”,“data”:"{“error”:“Invalid key len”}"}
09:35:06.854 [DEBUG] [.mihome.internal.socket.XiaomiSocket] - Data received and notified 1 listeners
09:35:06.854 [DEBUG] [.mihome.internal.socket.XiaomiSocket] - Thread waiting for data on port 9898

BR,
O.

seems that you got unicast traffic working as you receive answers to your requests.
just to be sure: you entered the developer key into the thing config of the bridge right?

are you receiving any reports or heartbeats?

Yes of curse, until it in the same vlan, its working

Regarding the heartbeats, you mean this?:

BR,
O.

Is it a problem, If at the first time it was in the same wlan, so the autodiscovery find it. Than I move it to other vlan, and simple edit the ip here:


BR,
O.

Config seems ok. You can see in your logs that it sends to the configured ip and gets answers.
With reports and heartbeats I mean in the debug log.
If nothing happens the gateway is sending a heartbeat every 10sec.
If for example a motion sensor triggers it should send a message with cmd : report in it

Please can anybody tell me how i can pair a aqara switch with the xiaomi gateway? I don´t speak chinese and i can´t read the manual.

Also there are two blue small led under the switches, what are they for?

I have the 2 channel aqara wireless switch (battery powered).

To pair a xiaomi gadget i have to press the button on the gateway three times, but what do i have to press on the switch?

EDIT:
Strange, now i can see the aqara switch in my mi home, but i can´t add it with openhab paper ui. Any tips how i can do that? I made a search for new things, but there was none, then i added manually an aqara 2 channel switch and then i had to enter the device id, but i don´t have that. Where can i get this? All my tmep sensors and xiaomi switches were filled in automatically with this id.

you have to press the gateway button three times, then one of the pushbuttons of the switch for a few seconds, five or so.
if you already see it perhaps it’s worth it pressing the button for the binding to get aware of the new device…
Good luck!

Good news
finally and thanks to @Kai the IOT marketplace now provides the latest version of the binding!!!

Please regard this a still under development and help the community to get the bugs out of it…

cheers!

1 Like

Finally i got it working.

I wanted to change to mihome-binding from 26.04.2017 but then all xiaomi things stopped working, so back to the old jar-file from 12.04.2017 i think and immediately it started to work again, and also there was the new aqara switch visible.

But on iot Marketplace still no new addon:

Date Created: 
Mon, 2017-04-17 17:48
Development Status: 
Beta
License: 
EPL
Date Updated: 
Tue, 2017-04-18 09:05
Submitted by: 
Dieter Schmidt

I found the not working (for me) jar-file from today on the github_
https://openhab.jfrog.io/openhab/libs-pullrequest-local/org/openhab/binding/org.openhab.binding.mihome/2.1.0-SNAPSHOT/

glad its working for you!
can anybody confirm that the marketplace JAR is no functional? there were some issues with jenkins the last time, perhaps this relates to that…

Is the direct link from my last post to jfrog.io the right jar?


Look at my screenshot, there is no update:

I could not download the marketplace version, would you please provide the link for ot? I can test it.

Look at my Screenshot, there is a link in it in top oft the picture. It is the github pullrequest. there you can find a link to a jar file from 24.04.2017. this is working for me.

I can confirm its NOT WORKING
had to move the existing jar away from the addons folder, then the one installed through the marketplace was registered and started in karaf.

what it outputs is:
207 | Active | 80 | 2.1.0.201704261053 | Energenie Mi|Home Binding

seems our binding shares the same name with the energenie bundle :frowning:
So the building system actually builds it, but its not the xiaomi mihome binding but energenie instead :dizzy_face:

With Aqara switch there is only single click available.

Is there a way to get double click or even tripple click? Maybe with some rules in Openhab?

Single click and voltage is working.

Hi guys, it’s a bit too much to read from the beginning, but just wondering if the Mi Smart Home Kit binding is working with openHAB 2 now, and if all products including the power strip were able to be controlled from openHAB 2?

Thanks in advance.

I´m using Openhab2 and i have the gateway/bridge -> Color is working, sound not tested yet. Temp/Humidity Sensor, magnetic Door Contact, Xiaomi Button Swicth and Aqara 2-channel battery powered switch also working.

I can use the functionality of the sensors and i also get voltage notifications - actual voltage and low battery warning.

I don´t own any power strip or other xiaomi mi home stuff which i haven´t listet here.

1 Like