Multiple Xiaomi Gateways in one instance of Openhab?

In my home setup I have two Xiaomi Gateways to cover connection. I can’t seem to add two gateways as bridges in openhab.

If I manual add another gateway I can only select the current bridge and not create a new one

Any help is highly appreciated. thanks

The gateway is something else then the bridge. The gateway is a thing that can control the light and sound of the gateway that are on the same physical device that acts as the bridge for OH.

The bridge is the main element and should be defined first. Then you can add the gateway as first thing attached to the bridge

So your second Xiaomi device acts as second bridge. The gateway thing of the second device is attached to this second bridge

2 Likes

Thanks for the quick reply. You’re absolutely right, I mixed-up gateway with bridge.

I’ve now added another Bridge, with correct IP and dev key. I’ve waited for a number of minutes but the Bridge is still in status Initializing.

I also added this Bridge as a single bridge to a clean instance and it changed to Online status in seconds. Any idea where this goes wrong?

Quick update after restarting OpenHab.

The second bridge is online, the first one is now on INITIALIAZING (and all devices of the first bridge are uninitialized). I also receive following error in the OpenHab Console

       Exception in thread "Thread-59" java.lang.NullPointerException
        at java.util.concurrent.ConcurrentHashMap.replaceNode(Unknown Source)
        at java.util.concurrent.ConcurrentHashMap.remove(Unknown Source)
        at org.openhab.binding.mihome.handler.XiaomiBridgeHandler.defer(XiaomiBridgeHandler.java:158)
        at org.openhab.binding.mihome.handler.XiaomiBridgeHandler.onDataReceived(XiaomiBridgeHandler.java:147)
        at org.openhab.binding.mihome.internal.socket.XiaomiSocket$ReceiverThread.notifyAll(XiaomiSocket.java:234)
        at org.openhab.binding.mihome.internal.socket.XiaomiSocket$ReceiverThread.receiveData(XiaomiSocket.java:210)
        at org.openhab.binding.mihome.internal.socket.XiaomiSocket$ReceiverThread.run(XiaomiSocket.java:189)

This is on a Windows Machine. I will try on an RPI to see if that has different results.

I’ve installed OpenHab on an RPI. It runs two bridges without issues.

Thanks, Pieter

Well, I’m also trying to add a second gateway, but the bridge is still INITIALIZING
The first gateway works perfectly and I can see the heartbeat messages.
I tried to add the second gateway as a bridge and nothing…
Both gateways are connected to the same wifi network, they both have the same (latest) firmware and both have the developer mode enabled - I even changed the developer key a few times on the second one.
Here are some logs (running openhab 2.5.0.M1):

08:32:37.800 [DEBUG] [.internal.handler.XiaomiBridgeHandler] - Having 1 Item Discovery listeners
08:32:37.814 [DEBUG] [org.openhab.binding.mihome           ] - ServiceEvent REGISTERED - {org.eclipse.smarthome.config.discovery.DiscoveryService}={service.id=577, service.bundleid=270, service.scope=singleton} - org.openhab.binding.mihome
08:32:37.825 [DEBUG] [org.openhab.binding.mihome           ] - ServiceEvent REGISTERED - {org.eclipse.smarthome.config.core.status.ConfigStatusProvider}={service.id=578, service.bundleid=270, service.scope=singleton} - org.openhab.binding.mihome
08:32:37.829 [DEBUG] [.internal.handler.XiaomiBridgeHandler] - Init socket on Port: 9898
08:32:37.830 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'mihome:bridge:7811dcfab044' changed from UNINITIALIZED to INITIALIZING
08:32:37.831 [DEBUG] [me.internal.socket.XiaomiBridgeSocket] - Setup socket
08:32:37.832 [DEBUG] [me.internal.socket.XiaomiBridgeSocket] - Initialized socket to null:-1 on 0.0.0.0/0.0.0.0:9898
08:32:37.836 [DEBUG] [g.mihome.internal.socket.XiaomiSocket] - There are 1 open sockets: {9898=java.net.MulticastSocket@516bdc59}
08:32:37.837 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Adding socket listener org.openhab.binding.mihome.internal.handler.XiaomiBridgeHandler@48170a75
08:32:37.843 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Staring reveicer thread for socket on port 9898
08:32:37.856 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-42259,5,main] waiting for data on port 9898
08:32:38.838 [DEBUG] [.internal.handler.XiaomiBridgeHandler] - Send to bridge mihome:bridge:7811dcfab044: {"cmd": "get_id_list"}
08:32:38.842 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Sending message: {"cmd": "get_id_list"} to /192.168.200.19:9898
08:32:43.337 [DEBUG] [g.mihome.internal.socket.XiaomiSocket] - Received Datagram from 192.168.200.20:4321 on Port 9898
08:32:43.338 [TRACE] [.internal.handler.XiaomiBridgeHandler] - Received message {"cmd":"heartbeat","model":"gateway","sid":"34ce00906f78","short_id":"0","token":"O16E342frWwVytLt","data":"{\"ip\":\"192.168.200.20\"}"}
08:32:43.339 [TRACE] [.internal.handler.XiaomiBridgeHandler] - Updated "last time seen" for device 34ce00906f78
08:32:43.340 [DEBUG] [g.mihome.internal.socket.XiaomiSocket] - Received Datagram from 192.168.200.20:4321 on Port 9898
08:32:43.346 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Data received and notified 1 listeners
08:32:43.347 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-42259,5,main] waiting for data on port 9898
08:32:43.346 [DEBUG] [ernal.handler.XiaomiDeviceBaseHandler] - Item got update: {"cmd":"heartbeat","model":"gateway","sid":"34ce00906f78","short_id":"0","token":"O16E342frWwVytLt","data":"{\"ip\":\"192.168.200.20\"}"}
08:32:43.356 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Data received and notified 1 listeners
08:32:43.357 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-161,5,main] waiting for data on port 9898
08:32:53.326 [DEBUG] [g.mihome.internal.socket.XiaomiSocket] - Received Datagram from 192.168.200.20:4321 on Port 9898
08:32:53.327 [TRACE] [.internal.handler.XiaomiBridgeHandler] - Received message {"cmd":"heartbeat","model":"gateway","sid":"34ce00906f78","short_id":"0","token":"qJ25ABohKjsW7CHz","data":"{\"ip\":\"192.168.200.20\"}"}
08:32:53.328 [TRACE] [.internal.handler.XiaomiBridgeHandler] - Updated "last time seen" for device 34ce00906f78
08:32:53.330 [DEBUG] [g.mihome.internal.socket.XiaomiSocket] - Received Datagram from 192.168.200.20:4321 on Port 9898
08:32:53.341 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Data received and notified 1 listeners
08:32:53.342 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-42259,5,main] waiting for data on port 9898
08:32:53.343 [DEBUG] [ernal.handler.XiaomiDeviceBaseHandler] - Item got update: {"cmd":"heartbeat","model":"gateway","sid":"34ce00906f78","short_id":"0","token":"qJ25ABohKjsW7CHz","data":"{\"ip\":\"192.168.200.20\"}"}
08:32:53.344 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Data received and notified 1 listeners
08:32:53.347 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-161,5,main] waiting for data on port 9898
08:33:03.332 [DEBUG] [g.mihome.internal.socket.XiaomiSocket] - Received Datagram from 192.168.200.20:4321 on Port 9898
08:33:03.332 [DEBUG] [g.mihome.internal.socket.XiaomiSocket] - Received Datagram from 192.168.200.20:4321 on Port 9898
08:33:03.334 [TRACE] [.internal.handler.XiaomiBridgeHandler] - Received message {"cmd":"heartbeat","model":"gateway","sid":"34ce00906f78","short_id":"0","token":"027OavT2zj4e6xnl","data":"{\"ip\":\"192.168.200.20\"}"}
08:33:03.335 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Data received and notified 1 listeners
08:33:03.335 [TRACE] [.internal.handler.XiaomiBridgeHandler] - Updated "last time seen" for device 34ce00906f78
08:33:03.336 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-42259,5,main] waiting for data on port 9898
08:33:03.337 [DEBUG] [ernal.handler.XiaomiDeviceBaseHandler] - Item got update: {"cmd":"heartbeat","model":"gateway","sid":"34ce00906f78","short_id":"0","token":"027OavT2zj4e6xnl","data":"{\"ip\":\"192.168.200.20\"}"}
08:33:03.348 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Data received and notified 1 listeners
08:33:03.349 [TRACE] [g.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-161,5,main] waiting for data on port 9898
$ netcat -ukl 9898
{"cmd":"heartbeat","model":"gateway","sid":"34ce00906f78","short_id":"0","token":"KgXKhzk8XU3Vf8pM","data":"{\"ip\":\"192.168.200.20\"}"}
{"cmd":"heartbeat","model":"gateway","sid":"34ce00906f78","short_id":"0","token":"DvWAqrBUGhH5QPqF","data":"{\"ip\":\"192.168.200.20\"}"}
{"cmd":"heartbeat","model":"gateway","sid":"34ce00906f78","short_id":"0","token":"cqA9GhKash9SZ7UJ","data":"{\"ip\":\"192.168.200.20\"}"}

$ ping 192.168.200.19
PING 192.168.200.19 (192.168.200.19) 56(84) bytes of data.
64 bytes from 192.168.200.19: icmp_seq=1 ttl=255 time=14.7 ms
64 bytes from 192.168.200.19: icmp_seq=2 ttl=255 time=31.4 ms
64 bytes from 192.168.200.19: icmp_seq=3 ttl=255 time=6.23 ms
64 bytes from 192.168.200.19: icmp_seq=4 ttl=255 time=1.58 ms
64 bytes from 192.168.200.19: icmp_seq=5 ttl=255 time=147 ms
^C
--- 192.168.200.19 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4004ms
rtt min/avg/max/mdev = 1.589/40.368/147.760/54.655 ms

$ ping 192.168.200.20
PING 192.168.200.20 (192.168.200.20) 56(84) bytes of data.
64 bytes from 192.168.200.20: icmp_seq=1 ttl=255 time=4.34 ms
64 bytes from 192.168.200.20: icmp_seq=2 ttl=255 time=25.8 ms
64 bytes from 192.168.200.20: icmp_seq=3 ttl=255 time=28.7 ms
64 bytes from 192.168.200.20: icmp_seq=4 ttl=255 time=13.1 ms
64 bytes from 192.168.200.20: icmp_seq=5 ttl=255 time=27.7 ms
^C
--- 192.168.200.20 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4002ms
rtt min/avg/max/mdev = 4.343/19.960/28.751/9.630 ms
$ sudo nmap -P0 -sU 192.168.200.19

Starting Nmap 7.60 ( https://nmap.org ) at 2019-06-13 09:02 EEST
Nmap scan report for lumi-gateway-v3_2 (192.168.200.19)
Host is up (0.0087s latency).
Not shown: 998 closed ports
PORT      STATE         SERVICE
5353/udp  open|filtered zeroconf
54321/udp open|filtered bo2k
MAC Address: 78:11:DC:FA:B0:44 (Xiaomi Electronics,co.)

Nmap done: 1 IP address (1 host up) scanned in 324.53 seconds

The first gateway, the ONLINE one has the IP 192.168.200.20 and the INITIALIZING one is 192.168.200.19.
Anybody with an advice on how to proceed further?

@marcel_verpaalen any thoughts?

@Mihai_Badea not really… I don’t have a gateway device, hence never played with the mihome binding…
I’m the author of the other Xiaomi binding (miio) :slight_smile:

Well, I know 'cause I’m using that also.
I just thought that you might have some clue :smile:
Thanks anyway!
I tried restarting, cleaning the cache…
No use…
The second gateway is not initialized.

Problem solved - see this thread.
I really gotta learn to search before doing anything… Turn out that I should have not upgraded the firmware on the new gateway first…
Stupid mistake!