Cannot connect Xiaomi Gateway (lumi.gateway.v3) to HA

@Cee I never see the port to be ‘fully’ open, at most it’s just open|filtered and most of the time it’s just closed…

@nickrout yes I’ve tried to follow all the steps in troubleshooting. I have :

  1. enabled LAN access

  2. turn off firewall on my windows 10 (host) and ubuntu (guest in VM)
    fw-win

root@homeassistant:~# ufw status
Status: inactive
  1. multicast support on router. I’m not sure on this, I have Tenda AC6. I’ve tried searching in the manual, and the only place I found about multicast is in the IPTV setting. I’m not using the IPTV feature but I have enabled it, just in case. I’ve read here about using iperf to test multicast capability of my network. I don’t know whether this is the right tool and whether the result is valid, however I get good result using this method. I’ve already sent an email to Tenda support regarding this regard and still awaiting their response.
    multicast

  2. trying to set mac: blank → no effect, still error.

xiaomi_aqara:
  discovery_retry: 10
  gateways:
    - host: 192.168.0.108
      mac: 
      key: oqidperh9lptaa6h

result in following debug log :

2018-08-27 10:10:46 WARNING (MainThread) [homeassistant.components.http] Experimental auth api enabled and legacy_api_password support enabled. Please use access_token instead api_password, although you can still use legacy api_password
2018-08-27 10:10:46 WARNING (MainThread) [homeassistant.loader] You are using a custom component for sensor.broadlink_power which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2018-08-27 10:10:47 DEBUG (SyncWorker_1) [homeassistant.components.xiaomi_aqara] Expecting 1 gateways
2018-08-27 10:10:47 INFO (SyncWorker_1) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 1)
2018-08-27 10:10:52 INFO (SyncWorker_1) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 2)
2018-08-27 10:10:57 WARNING (MainThread) [homeassistant.setup] Setup of xiaomi_aqara is taking over 10 seconds.
2018-08-27 10:10:57 INFO (SyncWorker_1) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 3)
2018-08-27 10:10:59 WARNING (SyncWorker_4) [homeassistant.components.light.flux_led] Failed to connect to bulb 192.168.0.180, LED Tempat Tidur
2018-08-27 10:11:02 INFO (SyncWorker_1) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 4)
2018-08-27 10:11:07 INFO (SyncWorker_1) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 5)
2018-08-27 10:11:12 INFO (SyncWorker_1) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 6)
2018-08-27 10:11:17 INFO (SyncWorker_1) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 7)
2018-08-27 10:11:22 INFO (SyncWorker_1) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 8)
2018-08-27 10:11:27 INFO (SyncWorker_1) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 9)
2018-08-27 10:11:32 INFO (SyncWorker_1) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 10)
2018-08-27 10:11:37 ERROR (SyncWorker_1) [homeassistant.components.xiaomi_aqara] No gateway discovered
2018-08-27 10:11:37 ERROR (MainThread) [homeassistant.setup] Setup failed for xiaomi_aqara: Component failed to initialize.
  1. set discovery_retry: 10 → no effect also. If I don’t put host: and mac: specifically, the auto-discovery will fail even after 10 retries. I have to specifically put the IP address and mac of the xiaomi gateway for it to be found.

  2. disable-enable Lan access from miHome apps has no effect also.

  3. hard-reset gateway → I’ve tried several times but still same errors

  4. docker… I think I don’t use docker. I’ve installed hassio directly to the Ubuntu VM. CMIIW…

  5. I never get error about invalid key…

  6. I have no error about PyXiaomiGateway library… However I went ahead and install all dependencies

root@homeassistant:~# apt-get install python3-dev libssl-dev libffi-dev
Reading package lists… Done
Building dependency tree
Reading state information… Done
libffi-dev is already the newest version (3.2.1-8).
libssl-dev is already the newest version (1.1.0g-2ubuntu4.1).
python3-dev is already the newest version (3.6.5-3ubuntu1).
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.

In short, I have tried every toubleshooting steps in the documentation page, but still unsuccessful. I have some suspicion :

  1. My errorr always stopped at listening for broadcast. Could it be my router doesn’t support multicast?
  2. I may have too complicated network hops : xiaomi gateway ↔ wireless router (Tenda AC6) ↔ wireless USB stick (TP-Link TL-WN722N) ↔ VMware Ubuntu host (bridged).

I will try to run hassio from persistent-storage live ubuntu on flashdisk (bypassing windows and VMware), or change the wireless USB stick, or even try on a different wireless router…

Anything I can do again?

Hi,

When you talk about your gateway (lumi.gateway.v3), which one you refer exacly? Is the same as the image below?

In my case, the configuration that i have is this one, i don’t have mac and only the key, and works to me, i have more than 10 sensors…

xiaomi_aqara:
  discovery_retry: 10
  gateways:
    - mac:
      key: !secret xiaomi_key

As you say, time ago i also had problems with the discover of device, and i could see that problem was my router.

So try first my configuration, and if not works, then try to change router to see is that the problem, an you Trend AC6 block de multicast.

Hi @garvarma yes that is the model that I own. I have set the config as you suggest, but HA cannot find the device even after 10 retries

xiaomi_aqara:
  discovery_retry: 10
  gateways:
    - mac:
      key: oqidperh9lptaa6h

This results in error :

2018-08-27 11:21:20 WARNING (MainThread) [homeassistant.components.http] Experimental auth api enabled and legacy_api_password support enabled. Please use access_token instead api_password, although you can still use legacy api_password
2018-08-27 11:21:20 WARNING (MainThread) [homeassistant.loader] You are using a custom component for sensor.broadlink_power which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2018-08-27 11:21:20 DEBUG (SyncWorker_2) [homeassistant.components.xiaomi_aqara] Expecting 1 gateways
2018-08-27 11:21:20 INFO (SyncWorker_2) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 1)
2018-08-27 11:21:25 INFO (SyncWorker_2) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 2)
2018-08-27 11:21:30 WARNING (MainThread) [homeassistant.setup] Setup of xiaomi_aqara is taking over 10 seconds.
2018-08-27 11:21:30 INFO (SyncWorker_2) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 3)
2018-08-27 11:21:33 WARNING (SyncWorker_0) [homeassistant.components.light.flux_led] Failed to connect to bulb 192.168.0.180, LED Tempat Tidur
2018-08-27 11:21:35 INFO (SyncWorker_2) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 4)
2018-08-27 11:21:40 INFO (SyncWorker_2) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 5)
2018-08-27 11:21:45 INFO (SyncWorker_2) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 6)
2018-08-27 11:21:50 INFO (SyncWorker_2) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 7)
2018-08-27 11:21:55 INFO (SyncWorker_2) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 8)
2018-08-27 11:22:00 INFO (SyncWorker_2) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 9)
2018-08-27 11:22:05 INFO (SyncWorker_2) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 10)
2018-08-27 11:22:10 ERROR (SyncWorker_2) [homeassistant.components.xiaomi_aqara] No gateway discovered
2018-08-27 11:22:10 ERROR (MainThread) [homeassistant.setup] Setup failed for xiaomi_aqara: Component failed to initialize.

How was your problem like? How do you find it was the router that block the multicast? May I know what is your router back then, and what is your current router now?

I just bought the Tenda AC6 a month ago, and I really hope that the router was not the culprit. Don’t know what my wife will say if I buy another router… :frowning:

How was your problem like? How do you find it was the router that block the multicast? May I know what is your router back then, and what is your current router now?

I don’t remember exacly, but first i had 1 router from my company of internet, then they changed my router and then the gateway didn’t appeared in HA, so I installed my old one to test, and with old one, the gateway discovered.

The one that blocked multicast was a livebox, then old one that i was using was a ZTE. Now i have a Unifi.

If you look in forum, about xiaomi gateway discovered problem, you can see about that some routers block the multicast. Ask a friend if has old router…

Look if configuration of hassio has bridge mode activated also…

Hmm… I’ve spoken to the live support of Tenda. Not the best customer support though… Waiting 30 minutes for an answer, and they just answer in two lines and disconnect my session… They said the router supports multicast, although I cannot find any setting regarding multicast in my router web-admin…

However, I will still try to find another router to check this out…

@garvarma what did you mean by hassio bridge mode? I’ve tried googling a bit about it, but still haven’t found any information about it… How do we check the bridge mode of hassio?

what did you mean by hassio bridge mode? I’ve tried googling a bit about it, but still haven’t found any information about it… How do we check the bridge mode of hassio

In my case i’m using HA in dockers option. In my case when i configure the docker, i need to put in bridge mode, that all devices works in the same network.

If you didn’t find anything, in google, then maybe is not necessary in your case.

Here you can find some info:

https://community.home-assistant.io/t/xiaomi-gateway-not-discovered/25030/68

https://community.home-assistant.io/t/xiaomi-gateway-integration-help-needed/28563/32

https://community.home-assistant.io/search?q=xiaomi%20gateway%20multicast

Sorry i must go now to work. Try to find other router from a friend and check this.

speaking of this docker thing… I went ahead and try to see whether my system is actually running on a docker… So, when I issue this command from SSH (putty), this is the result that I get :

Does that mean I’m running hassio in docker? If yes, how do I make it running in –net:host mode? I’m really lost here, and I’ve tried searching around for instruction to run the already-installed docker in host mode… Any help would be appreciated…

Well i don’t understand so much about hassio.

But first i will recommend try other router if in that case continue not working, then see other things, like bridge or maybe configuration of HA.

Hmm… I’ve tried using different router D-LINK L7-N-R2000 which have multicast capability (there’s a menu about that in the setting). But the error persist. It seems like the port 9898 is closed most of the time. It only opens for a second after I disabled-enable LAN access. I assume this is the bug of the latest firmware…

i dont think it is multicast issue. Cause multicast issue you still can discover the gateway but will keep give key error in the logs
Possible migateway bug.

Try this.

  1. turn off wireless communication protocol
  2. change the password by press the button(avoid password with L / i / o / 9 / g. Sometime, cant differentiate it.)
  3. turn on wireless communication protocol
  4. try connect using new password.
  5. if step 4 fail. Reboot your migateway and wait 5 mins after reboot. Then restart your home assistant.

Other things you can try is running hassbian rather than hass.io.
I has problem with hass.io which it only listen to my lan port and not my wireless.

You can also see the broadcast from migateway using ngrep

$ ngrep port 9898
interface: eth0 (192.168.xx.0/255.255.255.0)
filter: (ip or ip6) and ( port 9898 )
#
U 192.168.xx.xx:4321 -> 224.0.0.50:9898
  {"cmd":"heartbeat","model":"gateway","sid":"xxxxxxx","short_id":"0","token":"xxxxxxxxxxxxx","data":"{\"ip\":\"192.168.xx.xx\"}"}
#
U 192.168.xx.xx:4321 -> 224.0.0.50:9898
  {"cmd":"heartbeat","model":"gateway","sid":"xxxxxxx","short_id":"0","token":"xxxxxxxxxx","data":"{\"ip\":\"192.168.xx.xx\"}"}
#

thanks for the suggesntion @tyjtyj
I will once again try to disable-enable wireless comm protocol, changing the password…

I’ve tried ngrep port 9898 but I’ve waited 30 mins there’s nothing on port 9898… not a heartbeat from the gateway… I really think the gateway doesn’t want to open himself to the network…

Anyway, what is you nmap result to the gateway? could you please perform

nmap -sU 192.168.0.x -p 9898,4321 to your gateway IP?

I’ve tempted to try to install hassbian. But don’t know how to install hassbian on ubuntu desktop pc?

Seems nmap test not accurate

root@raspberrypi:/home/homeassistant/.homeassistant# nmap -sU 192.168.xx.xx -p 9898,4321

Starting Nmap 7.40 ( https://nmap.org ) at 2018-09-05 15:49 +08
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 1.04 seconds
root@raspberrypi:/home/homeassistant/.homeassistant# nmap -sU 192.168.xx.xx -p 9898,4321

Starting Nmap 7.40 ( https://nmap.org ) at 2018-09-05 15:50 +08
Nmap scan report for lumi-gateway-v3_miio4516xxxx (192.168.xx.xx)
Host is up (0.036s latency).
PORT     STATE         SERVICE
4321/udp open|filtered rwhois
9898/udp open          monkeycom
MAC Address: F0:B4:29:xxxxxxxxxxx (Xiaomi Communications)

Nmap done: 1 IP address (1 host up) scanned in 2.26 seconds
root@raspberrypi:/home/homeassistant/.homeassistant# nmap -sU 192.168.xx.xx -p 9898,4321

Starting Nmap 7.40 ( https://nmap.org ) at 2018-09-05 15:50 +08
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 0.80 seconds

Yes, nmap is rather unreliable over wifi… If you use cable like me, you will get far more success doing nmap.

I see you have port 4321 and 9898 open on Gateway… I never have those port opens, eventhough I reset the gateway multiple times, and disable-enable LAN access numerous times. I wish I could send you my unit to test.

Follow the instructions and use -Pn in your commandline.

How hard can that be?

Also, there needs to be a space between the IP address and the -p

Why are you obfuscating the IP address? Do you really think we can access your gateway by knowing your private IP address?

No, you cant access my GW over the internet but I dont like to expose my private ip to the internet(full stop).

There is a space there in my command line. I am not sure why when I copy and paste, it disappear.
It does shows the port was open for a while and then closed then open and then close…
I ran few times and sometimes it open and sometimes it closed. I just copy the 2 that shows different result.

hoedha, maybe you wanna try run on host computer rather than virtual machine.

Was it stated as closed or was it the Nmap couldn’t connect to he gateway? In my case using LAN cable I can always Nmap the gateway but it always return the state of closed on both ports.

I’ve tried running HA in VMware, in virtualbox, and in Ubuntu desktop pc as host… All result in same situation… Do I get a defective gateway?

Why the hell don’t you follow the instructions and run nmap with -Pn.

who is from hell again ?

I give up on trying to help you. You seem oblivious to suggestions.

@tyjtyj @nickrout please don’t fight each other. We are here to help others having problems (like me)…

Back to topic, I’ve tried running nmap using -Pn as suggested, but the result is the same… So I really guess there’s something wrong with my gateway which won’t open its port. I’ve disabled-enabled LAN access from dev-mode in mi-home but still face the same problem. I’ve found a guy in another city with HA setup and xiaomi gateway, so I may try to send him my unit to try on his setup, or ask him to send his gateway for me to try in my network…

Really strange… I wish we could flash (custom) firmware to the Xiaomi gateway…

root@hoedha-m93p:~# nmap -sU -Pn 192.168.0.108 -p 9898,4321

Starting Nmap 7.60 ( https://nmap.org ) at 2018-09-08 09:24 WIB
Nmap scan report for 192.168.0.108
Host is up (0.22s latency).

PORT     STATE  SERVICE
4321/udp closed rwhois
9898/udp closed monkeycom
MAC Address: 78:11:DC:B3:7D:98 (Xiaomi Electronics,co.)

Nmap done: 1 IP address (1 host up) scanned in 14.07 seconds
root@hoedha-m93p:~# nmap -sU -Pn 192.168.0.108 -p 9898,4321

Starting Nmap 7.60 ( https://nmap.org ) at 2018-09-08 09:24 WIB
Nmap scan report for 192.168.0.108
Host is up (0.22s latency).

PORT     STATE  SERVICE
4321/udp closed rwhois
9898/udp closed monkeycom
MAC Address: 78:11:DC:B3:7D:98 (Xiaomi Electronics,co.)

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