Xiaomi aqara gateway - All ports open - but cannot be discovered

Hi, I have a xiaomi aqara gateway and a bunch of xiaomi devices which I wanted to use in Home Assistant.

This is my configuration yaml entries:

xiaomi_aqara:
  discovery_retry: 10
  gateways:
    - key: redacted

Home Assistant’s logs:

Setup failed for xiaomi_aqara: Integration failed to initialize.
7:59:06 PM – setup.py (ERROR)

No gateway discovered
7:59:06 PM – xiaomi_aqara (ERROR)

Setup of xiaomi_aqara is taking over 10 seconds.
7:56:46 PM – __main__.py (WARNING)

I have tried the discovery_retry up to 30s. same no go.

I then thought I have some ports blocked.

So nmap shows this:

root@mypc:~# nmap -sU -Pn 192.168.3.100 -p 9898,4321,54321,5353

Starting Nmap 6.47 ( http://nmap.org ) at 2020-03-17 20:33 AWST
Unable to find nmap-services!  Resorting to /etc/services
Cannot find nmap-payloads. UDP payloads are disabled.
Nmap scan report for 192.168.3.100
Host is up (0.0028s latency).
PORT      STATE         SERVICE
4321/udp  open|filtered unknown
5353/udp  open|filtered mdns
9898/udp  open          unknown
54321/udp open|filtered unknown

So it seems all the important ports are opened but I am still having issues.

I must be missing something? I have searched everywhere but i could not find a working solution.

Help much appreciated.

Thanks

Is multicast enabled on your network?

I have always struggled to get my gateways to discover. I have configured as follows

xiaomi_aqara:
  gateways:
    - mac: removed
      key: removed
    - mac: removed
      key: removed

Also, make sure the gateway has a static IP address.

Same for me. The only way I can make it work is to add both host and mac address to the config. The older gateways works better with discovery.

xiaomi_aqara:
  gateways:
    - mac: xxx  # Without the colon delimiters,  ie. only 12AB34CD56EF
      key: xxx
      host: 192.168.1.xx  # If added, multicast discovery is skipped. 
    - mac: xxx 
      key: xxx
      host: 192.168.1.xx 

Hi. Yes it is currently already setup with a static IP.

Yes I have also tried to setup the mac address from within Home Assistant. No go still.

How do I check please?

On my windows 10 computer I typed

route print

part of the output was

IPv4 Route Table
===========================================================================
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0     192.168.20.1    192.168.20.70     35
        127.0.0.0        255.0.0.0         On-link         127.0.0.1    331
        127.0.0.1  255.255.255.255         On-link         127.0.0.1    331
  127.255.255.255  255.255.255.255         On-link         127.0.0.1    331
     192.168.20.0    255.255.255.0         On-link     192.168.20.70    291
    192.168.20.70  255.255.255.255         On-link     192.168.20.70    291
   192.168.20.255  255.255.255.255         On-link     192.168.20.70    291
        224.0.0.0        240.0.0.0         On-link         127.0.0.1    331
        224.0.0.0        240.0.0.0         On-link     192.168.20.70    291
  255.255.255.255  255.255.255.255         On-link         127.0.0.1    331
  255.255.255.255  255.255.255.255         On-link     192.168.20.70    291

The 224.0.0.0 are multicast routes, so I conclude multicast is enabled on my network.

Sorry for the late reply. I was at work.

I tried the route print on my windows PC as well. This is what I get:

        224.0.0.0        240.0.0.0         On-link         127.0.0.1    331
        224.0.0.0        240.0.0.0         On-link     192.168.1.101    281
        224.0.0.0        240.0.0.0         On-link    169.254.40.100    271
        224.0.0.0        240.0.0.0         On-link      192.168.1.44    281

So I guess that means multicast is also enabled on my network?

If so, what else can I do to get the gateway working?

Odd, I use colon delimiters!

I did too before, but then I read the docs that says no colons, so I went with that.

include your mac and ip.

Ok I will give it another try. Reporting back tonight.

Okay. I added the mac and ip to configuration yaml now. did not work.

Then I see that the Mihome app on my ipad has a new version. So I updated that. Tried the same again no deal.

I must have then reset the gateway and restart home assistant at least a dozen times and then tried again and again. I lost count.

Finally it works! The gateway is finally detected in home assistant.

However, the devices are very sluggish. For instance, when the sensor detected a change in state, it reported very slow in home assistant. I am wondering if this is due to Home assistant or due to the Xiaomi devices. Suffice to say I will not be buying anymore xiaomi stuff for home assistant.

I find the integration very snappy.

There are a number of versions of these gateways though, so YMMV.

I have found mine to be very stable and the Xiaomi zigbee sensors very good. However I am gradually moving them to zigbee2mqtt.

same - mine are pretty quick/sub-second

That said both of my gateways complain about high (>40%) packet loss on my network. :frowning:

Thanks. I think i will have to explore this to do the same. I still cannot get my devices to be working with the gateway in a snappy manner.