Xiaomi Smart Home binding

Hello everyone!
Trying to run bindings for Xiaomi Smart Home, but there are a few questions for help.

Raspberry Pi 3
openHABian
OH 2.3.0
Xiaomi gateway (lumi-gateway-v3_miio80959709)
Xiaomi door/window sensor

OK, configering Xiaomi using OH DOCS

In inbox for Xiaomi nothing.
If i try discover using Paper IU - result nothing

13:49:46.295 [DEBUG] [iscovery.XiaomiBridgeDiscoveryService] - Start scan for bridges
13:49:46.299 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-5923,5,main] waiting for data on port 60062
13:49:46.299 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Adding socket listener org.openhab.binding.mihome.internal.discovery.XiaomiBridgeDiscoveryService@15b0fb0
13:49:46.306 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Sending message: {“cmd”:“whois”} to /224.0.0.50:4321
13:49:56.272 [DEBUG] [iscovery.XiaomiBridgeDiscoveryService] - Stop scan
13:49:56.277 [DEBUG] [g.mihome.internal.socket.XiaomiSocket] - Interrupting Thread Thread[Thread-5923,5,main]
13:49:56.279 [DEBUG] [g.mihome.internal.socket.XiaomiSocket] - Closing socket java.net.DatagramSocket@16530fa
13:49:56.281 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Receiver thread was interrupted
13:49:56.283 [DEBUG] [g.mihome.internal.socket.XiaomiSocket] - Receiver thread ended

Ok, next try to add Xiaomi Home Bridge using Paper IU (IP + developer key)

14:01:29.947 [DEBUG] [ng.mihome.handler.XiaomiBridgeHandler] - Having 1 Item Discovery listeners
14:01:29.986 [DEBUG] [org.openhab.binding.mihome ] - ServiceEvent REGISTERED - {org.eclipse.smarthome.config.discovery.DiscoveryService}={service.id=388, service.bundleid=261, service.scope=singleton} - org.openhab.binding.mihome
14:01:30.050 [DEBUG] [org.openhab.binding.mihome ] - ServiceEvent REGISTERED - {org.eclipse.smarthome.config.core.status.ConfigStatusProvider}={service.id=389, service.bundleid=261, service.scope=singleton} - org.openhab.binding.mihome
14:01:30.104 [DEBUG] [ng.mihome.handler.XiaomiBridgeHandler] - Init socket on Port: 9898
14:01:30.105 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - ‘mihome:bridge:00a4ba56’ changed from UNINITIALIZED to INITIALIZING
14:01:30.118 [DEBUG] [me.internal.socket.XiaomiBridgeSocket] - Setup socket
14:01:30.140 [DEBUG] [me.internal.socket.XiaomiBridgeSocket] - Initialized socket to null:-1 on 0.0.0.0/0.0.0.0:9898
14:01:30.181 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Staring reveicer thread for socket on port 9898
14:01:30.181 [DEBUG] [g.mihome.internal.socket.XiaomiSocket] - There are 1 open sockets: {9898=java.net.MulticastSocket@469341}
14:01:30.203 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-5984,5,main] waiting for data on port 9898
14:01:30.225 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Adding socket listener org.openhab.binding.mihome.handler.XiaomiBridgeHandler@1abaee
14:01:31.278 [DEBUG] [ng.mihome.handler.XiaomiBridgeHandler] - Triggered discovery
14:01:31.299 [DEBUG] [ng.mihome.handler.XiaomiBridgeHandler] - Send to bridge mihome:bridge:00a4ba56: {“cmd”: “get_id_list”}
14:01:31.333 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Sending message: {“cmd”: “get_id_list”} to /192.168.100.10:9898
14:01:31.365 [DEBUG] [g.mihome.internal.socket.XiaomiSocket] - Received Datagram from 192.168.100.10:9898 on Port 9898
14:01:31.383 [TRACE] [ng.mihome.handler.XiaomiBridgeHandler] - Received message {“cmd”:“get_id_list_ack”,“sid”:“7811dce1ab5c”,“token”:“dm5RAoNOd4K3FsTf”,“data”:"[“158d000232ba94”,“158d00024acace”,“158d0001bf2806”,“158d0001b758d5”,“158d0001dccda5”,“158d0002469d7e”,“158d0001ad4666”,“158d0001c02fd6”,“158d0001b75731”]"}
14:01:31.409 [TRACE] [ng.mihome.handler.XiaomiBridgeHandler] - Updated “last time seen” for device 7811dce1ab5c
14:01:31.427 [DEBUG] [ng.mihome.handler.XiaomiBridgeHandler] - Send to bridge mihome:bridge:00a4ba56: {“cmd”: “read”, “sid”: “158d000232ba94”}
14:01:31.429 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - ‘mihome:bridge:00a4ba56’ changed from INITIALIZING to ONLINE
14:01:31.446 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Sending message: {“cmd”: “read”, “sid”: “158d000232ba94”} to /192.168.100.10:9898
14:01:31.474 [DEBUG] [ng.mihome.handler.XiaomiBridgeHandler] - Send to bridge mihome:bridge:00a4ba56: {“cmd”: “read”, “sid”: “158d00024acace”}
114:01:31.707 [DEBUG] [ng.mihome.handler.XiaomiBridgeHandler] - Send to bridge mihome:bridge:00a4ba56: {“cmd”: “read”}
14:01:31.719 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Sending message: {“cmd”: “read”} to /192.168.100.10:9898
14:01:31.731 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Data received and notified 1 listeners
14:01:31.741 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-5984,5,main] waiting for data on port 9898
14:01:31.752 [DEBUG] [g.mihome.internal.socket.XiaomiSocket] - Received Datagram from 192.168.100.10:9898 on Port 9898
14:01:31.764 [TRACE] [ng.mihome.handler.XiaomiBridgeHandler] - Received message {“cmd”:“read_ack”,“model”:“motion”,“sid”:“158d000232ba94”,“short_id”:33688,“data”:"{“voltage”:3045}"}

In inbox i see all my xioaomi sensors, but without Xiaomi Gateway.
If i link sensor

image

14:34:56.843 [DEBUG] [ng.mihome.handler.XiaomiBridgeHandler] - Adding item listener for device 158d0001c02fd6
14:34:56.850 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - ‘mihome:sensor_magnet:158d0001c02fd6’ changed from UNINITIALIZED to INITIALIZING
14:34:56.867 [DEBUG] [ng.mihome.handler.XiaomiBridgeHandler] - Having 1 Item listeners
14:34:56.908 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - ‘mihome:sensor_magnet:158d0001c02fd6’ changed from INITIALIZING to ONLINE
14:34:56.940 [DEBUG] [ihome.handler.XiaomiDeviceBaseHandler] - Device 158d0001c02fd6 on channel mihome:sensor_magnet:158d0001c02fd6:lowBattery received command REFRESH
14:34:56.940 [DEBUG] [ihome.handler.XiaomiDeviceBaseHandler] - Device 158d0001c02fd6 on channel mihome:sensor_magnet:158d0001c02fd6:lastOpened received command REFRESH
14:34:56.938 [DEBUG] [ihome.handler.XiaomiDeviceBaseHandler] - Device 158d0001c02fd6 on channel mihome:sensor_magnet:158d0001c02fd6:batteryLevel received command REFRESH
14:34:56.935 [DEBUG] [ihome.handler.XiaomiDeviceBaseHandler] - Device 158d0001c02fd6 on channel mihome:sensor_magnet:158d0001c02fd6:isOpen received command REFRESH
14:34:56.935 [DEBUG] [ihome.handler.XiaomiDeviceBaseHandler] - Device 158d0001c02fd6 on channel mihome:sensor_magnet:158d0001c02fd6:isOpenAlarmTimer received command REFRESH
14:34:56.975 [DEBUG] [ihome.handler.XiaomiDeviceBaseHandler] - Update Item 158d0001c02fd6 with retented message
14:34:57.134 [DEBUG] [ihome.handler.XiaomiDeviceBaseHandler] - Item got update: {“cmd”:“read_ack”,“model”:“magnet”,“sid”:“158d0001c02fd6”,“short_id”:9022,“data”:"{“voltage”:2985,“status”:“close”}"}
14:34:57.185 [INFO ] [smarthome.event.ItemStateChangedEvent] - mihome_sensor_magnet_158d0001c02fd6_batteryLevel changed from NULL to 71
14:34:57.188 [TRACE] [ihome.handler.XiaomiSensorBaseHandler] - Got status “close” - Apart from “report” all other status updates for sensors seem not right (Firmware 1.4.1.145)
14:34:57.209 [INFO ] [smarthome.event.ItemStateChangedEvent] - mihome_sensor_magnet_158d0001c02fd6_lowBattery changed from NULL to OFF

But in control

image

After a while I see the OFFLINE status on Things.

Thanks for the help.

As long as there is no status change, the xiaomi sensor transmits its data only once per hour.
Did you trigger an event?

For monitoring events, I used the mi home app. yes, in it events occurred across all sensors.
But in OH, not one event unfortunately.

Hi, I’m also having problems getting Xiaomi working on OH 2.3
(I had everything working fine on openhab 2.0)

My setup is similar:
Raspberry Pi 3, openHABian, OH 2.3.0
(I’m having exactly the same problems running openHAB on Synology)
V3 gateway, standard motion sensor and aqara motion sensor
Wifi, Gateway and raspberry pi all on the same network (192.168.128.255)

I’m pretty sure the problem is something to do with the interaction between the binding and the gateway
The Xiaomi binding continually confuses the terms binding and gateway making it very confusing
I did get it working via PaperUI but can’t reproduce the steps and can’t make it work via a things file
(I want to use things and items files - makes disaster recovery so easy)

Manually adding the bridge via PaperUI
The dialogue title says Bridge yet it says you are about to manually add a Gateway despite the fact that the type is “mihome:bridge:12345678” and it offers a default name Xiaomi Gateway
02BingingAdd

My thing file appears to conform to the openHAB 2.0 documentation for the Xiaomi binding

Bridge mihome:bridge:7811dcb2600e "Xiaomi Bridge" [ serialNumber="7811dcb2600e", ipAddress="192.168.128.194", port=9898, key="p669aaonk2pvh5ze", pollingInterval=6000 ] {
    Thing mihome:gateway:7811dcb2600e "Xiaomi Gateway" [itemId="7811dcb2600e"]

    Thing mihome:sensor_motion:158d0001f48d47 "Mi Motion Misc" [itemId="158d0001f48d47"]

    Thing mihome:sensor_motion_aq2:158d0002236b67 "Mi Motion Upstairs" [itemId="158d0002236b67"]
}

However this is the result within PaperUI - the gateway is offline and the sensors are not talking to openHAB
ThingsConfigResult

Really keen to solve this problem, assistance greatly appreciated

Worked out how to get it working via Paper UI
Added the bridge - edited IP and developer key
No gateway setup at all
The devices were auto found and they work

Now have a thing file that works

Used the new format and again just the bridge, no gateway

Bridge mihome:bridge:7811dcb2600e "Xiaomi Bridge" [ serialNumber="7811dcb2600e", ipAddress="192.168.128.183", port=9898, key="p669aaonk2pvh5ze", pollingInterval=6000 ] {
    Things:
        sensor_motion_aq2 158d0002236b67 "Mi Motion Upstairs" [itemId="158d0002236b67"]
        sensor_motion 158d0001f48d47 "Mi Motion Misc" [itemId="158d0001f48d47"]
    }

This gives me access to my sensors but no access to the gateway functionality

The downside of the new Thing file format is you now need to put the bridge id into each item

Dimmer   MiMotion_Downstairs_Lux        "Lux [%.1f %%]"                                <sun>           { channel="mihome:sensor_motion_aq2:**7811dcb2600e**:158d000224f700:illumination" }
Number   MiMotion_Downstairs_Timer      "Timer"                                        <time>          { channel="mihome:sensor_motion_aq2:**7811dcb2600e**:158d000224f700:motionOffTimer" }
Switch   MiMotion_Downstairs_Motion     "Motion"                                       <motion>        { channel="mihome:sensor_motion_aq2:**7811dcb2600e**:158d000224f700:motion" }
DateTime MiMotion_Downstairs_Last       "Last Motion [%1$tY-%1$tm-%1$td  %1$tH:%1$tM]" <time>          { channel="mihome:sensor_motion_aq2:**7811dcb2600e**:158d000224f700:lastMotion" }
Number   MiMotion_Downstairs_Battery    "Battery [%.1f %%]"                            <battery>       { channel="mihome:sensor_motion_aq2:**7811dcb2600e**:158d000224f700:batteryLevel" }
Switch   MiMotion_Downstairs_BatteryLow "Battery Low"                                  <lowbattery>    { channel="mihome:sensor_motion_aq2:**7811dcb2600e**:158d000224f700:lowBattery" }

The Xiaomi binding stops working after ~5 minutes
The devices show as online but no events in the openHAB log viewer

Hi, my OH2 and Mi is working.

  1. image
  2. Pi connecting to router via wifi (wlan0)

this scheme is certainly not quite what I wanted. but it works.

Hmmm, I don’t have that broadcast address option
Is that from the bridge or the gateway thing?

PaperUI System settings

Hi, using RPi + openhabian

Oh, yes, I have those settings correctly defined

The binding works after a reboot for about 5 to 10 minutes and then everything goes offline

Hi guys, @binderth has mentioned here that with openHABian the raspi wifi module has sleep mode enabled, which caused problems for him. can you try to disable sleep mode on your device?
also please verify that your pi is able to receive multicast messages:

root@raspberrypi:# netcat -ulk 9898

should give you messages like

{"cmd":"heartbeat","model":"gateway","sid":"xxx","short_id":"0","token":"xxx","data":"{\"ip\":\"xxx\"}"}

The gateway sends the heartbeat every 10 sec as soon as the developer mode is active in the MiHome app.
so if you don’t receive any messages after 10 sec, then your raspi is not receiving multicast messages. Mostly this is caused by the router not forwarding multicast traffic, e.g. between different subnets.

I can explain, why it’s showing online at startup:
Only at startup the binding is actively requesting values from the gateway - the gateway then sends the response via unicast, so no multicast involved. The binding receives the first answer and after that nothing anymore, causing a timeout and switching the gateway and all it’s things to offline after 5 mins.

1 Like

Hi,

How to configure the Xiaomi Aqara Fingerprint Door Lock? In console i don’n receive any message when user unlock by fingerprint, password or card. In MiHome all worked fine.

lock

Hi @ulug79, which device do you have? There are two different locks I think and only one is supported at the moment.
Do you have other devices as well? Was the lock automatically discovered or did you add it manually?

Hi @dimalo

I have mihome:sensor_lock_aq1.

I discover gateway hub in Paper UI. In properties key from MiHome entered.

With lock discovered all other devices (temperature and humidity sensor, door and window sensor). All devices give values to items in Paper UI and console except lock.

In home assistant lock worked fine!

I implemented the lock without having one, so there could be something wrong of course.
Please enable debug logging and try to get some informations in the logs about what the lock messages look like. You can find steps to do that in the binding documentation.

@dimalo i turn on debug for mihome addon and lock give correct information about verified card (as home assistant)

2018-12-22 03:21:54.045 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Data received and notified 1 listeners
2018-12-22 03:21:54.045 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-42,5,main] waiting for data on port 9898
2018-12-22 03:21:57.522 [DEBUG] [.mihome.internal.socket.XiaomiSocket] - Received Datagram from 192.168.7.108:4321 on Port 9898
2018-12-22 03:21:57.523 [TRACE] [internal.handler.XiaomiBridgeHandler] - Received message {“cmd”:“report”,“model”:“lock.aq1”,“sid”:“158d000222b64d”,“short_id
“:9297,“data”:”{“card_verified”:“196610”}”}
2018-12-22 03:21:57.523 [TRACE] [internal.handler.XiaomiBridgeHandler] - Updated “last time seen” for device 158d000222b64d
2018-12-22 03:21:57.523 [DEBUG] [internal.handler.XiaomiBridgeHandler] - Cancelled running timer
2018-12-22 03:21:57.524 [DEBUG] [rnal.handler.XiaomiDeviceBaseHandler] - Item got update: {“cmd”:“report”,“model”:“lock.aq1”,“sid”:“158d000222b64d”,“short_id
“:9297,“data”:”{“card_verified”:“196610”}”}
2018-12-22 03:21:57.525 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Data received and notified 1 listeners
2018-12-22 03:21:57.525 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-42,5,main] waiting for data on port 9898
2018-12-22 03:22:01.186 [DEBUG] [.mihome.internal.socket.XiaomiSocket] - Received Datagram from 192.168.7.108:4321 on Port 9898
2018-12-22 03:22:01.186 [TRACE] [internal.handler.XiaomiBridgeHandler] - Received message {“cmd”:“report”,“model”:“sensor_magnet.aq2”,“sid”:“158d0002394298”,
“short_id”:6014,“data”:"{“status”:“close”}"}
2018-12-22 03:22:01.186 [TRACE] [internal.handler.XiaomiBridgeHandler] - Updated “last time seen” for device 158d0002394298

But in Paper UI items not updated.

this should be fixed in the latest snapshot version of the binding :v: