Xiaomi gateway not discovered

Main thing: It’s working now and we know a solution how to fix the issue.

Nice to read that the hard reset of the gateway also worked for you guys!

All sensors from gateway are connected and the config is valid if check it from the configuration page. But somehow I still see invalid config error during the start process and in the History page.

Have you tried hass --script check_config ?
And read this https://home-assistant.io/docs/configuration/troubleshooting/

After reading the protocol documentation, it seems that it’s implemented with UDP protocol (I guess there must be a good reason for this), which explains why the probable gateway reply is not being received by Hassio.

I’m trying to figure out how to use the docker option that you referred, but I’ve yet to figure this out.

Thanks for the help.

1 Like

According to some information I got on Discord, “Homeassistant run on host network with full privileged”.

What would help diagnose this issue? A traffic capture?

Am I the only person who’s still having issues with discovery on 1.4.1_149 after a hard reset?

Have held the button down on the gateway for 10seconds and re-added it in the app.

Enabled/Disabled LAN access within the app.

Bizarely, nmap briefly reports that the UDP port is filtered for a few seconds after the button is ticked in the app, so it’s communicating with my gateway.

Home assistant refuses to discover it obviously.

I’m running a Ubiquiti network. Have just restarted my AP and Router.
Same result.

Tried hass --script check_config, config all good.
Double checked the startup log “sudo journalctl -fu [email protected]”, did not see the invalid config error.
Delete the /home/homeassistant/.homeassistant/home-assistant_v2.db file to clear the history.

Now it is gone.

Seems the History keep the record for all entities including the removed ones

no, you are not the only one :frowning:

When I’m executing nmap command to check the port, the port is open:
Starting Nmap 7.01 ( https://nmap.org ) at 2017-08-30 22:59 WEST
Nmap scan report for 192.168.1.125
Host is up (0.0022s latency).
PORT STATE SERVICE
9898/udp open unknown
MAC Address: F0:B4:29:FF:FF:FF (Xiaomi Communications)
Nmap done: 1 IP address (1 host up) scanned in 0.57 seconds

The configuration that I have is:
xiaomi:
gateways:

  • mac:
    key: ‘qmox2jewd8t3ra1v’
    discovery_retry: 10

I’m using the discovery retry with value 10, however when looking into the logs I only see 3 attemps.
When checking configuration, it is ok, no errors.

I already have the gateway configured on Xiaomi cloud, can this be an issue?

All help is welcome :slight_smile:

Thank you for all shares done so far.

BR,
JJP

Yes a traffic capture (tcpdump -i wlan0 -s0 -w test.pcap) would help to identify the problem in detail. Two captures from different views (home assistant host & another host using the WiFi network a laptop f.e.) would be perfect.

I just tried this command

tcpdump -A -i wlan0 udp port 4321 or udp port 9898

shows all needed details.

No. This is okay. Do you use docker? Can how describe your network connection and involved devices between xiaomi gateway and home assistant host?

Well, I’m using hassIO image on my RPI3, so using I’m using docker. My network has 2 routers, but using the same network, the second router is used to extend my coverage.

I already saw someware that I probably need to change some configuration since I’m using docker, but I can’t find the file mentioned (docker-compose.yml).

but about the discovery retry field, do I have something wrong on the configuration? or why HA only tries 3 times to discover my gateway?

Thank you!

24hours later and nmap now reports the port has open.
I can see some progress in HASS on startup, however it’s mostly errors now…

I’m running HASS on a 2016 Server (python 3.6). Two nics. Have configured the xiaomi component to use the NIC that is connected to the network that the gateway is on.

Thoughts?

2017-08-31 20:23:23 ERROR (MainThread) [homeassistant.setup] Error during setup of component xiaomi

Traceback (most recent call last):

_ File “c:\program files\python36\lib\site-packages\homeassistant\setup.py”, line 194, in async_setup_component

_ component.setup, hass, processed_config)_

_ File “c:\program files\python36\lib\asyncio\futures.py”, line 331, in iter_

_ yield self # This tells Task to wait for completion._

_ File “c:\program files\python36\lib\asyncio\tasks.py”, line 244, in wakeup

_ future.result()_

_ File “c:\program files\python36\lib\asyncio\futures.py”, line 244, in result_

_ raise self.exception

_ File “c:\program files\python36\lib\concurrent\futures\thread.py”, line 55, in run_

_ result = self.fn(*self.args, **self.kwargs)_

_ File “c:\program files\python36\lib\site-packages\homeassistant\components\xiaomi.py”, line 78, in setup_

_ hass.data[PY_XIAOMI_GATEWAY].listen()_

_ File “C:\Users\Administrator\AppData\Roaming.homeassistant\deps\Python36\site-packages\PyXiaomiGateway_init_.py”, line 107, in listen_

_ self._mcastsocket = self.create_mcast_socket()

_ File “C:\Users\Administrator\AppData\Roaming.homeassistant\deps\Python36\site-packages\PyXiaomiGateway_init_.py”, line 97, in create_mcast_socket

_ sock.bind((self.MULTICAST_ADDRESS, self.MULTICAST_PORT))_

OSError: [WinError 10049] The requested address is not valid in its context

Yeah, the indent is wrong. discovery_retry has to be on the same level as interface or gateways.
And the key doesn´t need the quotation marks.

Thanks, Once I arrive at home I’ll fix it, I hope that solves my issue :grinning:
Thanks a lot

On windows it’s not allowed/possible to bind to the MULTICAST_ADDRESS (224.0.0.50). This case is handled here: https://github.com/Danielhiversen/PyXiaomiGateway/blob/master/PyXiaomiGateway/init.py#L89

Your call trace ends at L97:

https://github.com/Danielhiversen/PyXiaomiGateway/blob/master/PyXiaomiGateway/init.py#L97

Okay. It’s a bug. :wink: As workaround add the interface (IP of your NIC) to your configuration:

xiaomi:
  gateways:
    - mac: !secret xiaomi_sid
      key: !secret xiaomi_key
  interface: 192.168.130.6

It will be handled properly in future: Fixes "The requested address is not valid in its context" by syssi · Pull Request #7 · Danielhiversen/PyXiaomiGateway · GitHub

1 Like

Well, taking in consideration I was able to have HA doing multiple attempts in order to find my gateway.
I have also remove the quotation marks, but my HA is still not able to find my gateway. :disappointed_relieved:

Actual configuration:
"
xiaomi:
discovery_retry: 10
gateways:
key: xxxxxxxxxxxxx
"

any other ideas? all are welcome :slight_smile:

Thank you!!! Was just my indent for the interface.
I can now see my sensor values in HASS in the dev states

Debugging hass.io is a bit tricky and I don’t know much about docker but we can give it a try. Please install the SSH addon. Use a SSH client to login (user: root). I would like to dump the network traffic to get a better picture of what’s going on. hass.io is an alpine linux, right? Use apk add tcpdump to install tcpdump. Check the output of ip addr. Do you see a block which contains a ip address of your local network? It will look like this:

3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 7c:5c:ff:ff:ff:ff brd ff:ff:ff:ff:ff:ff
    inet 192.168.130.35/24 brd 192.168.130.255 scope global dynamic wlan0
       valid_lft 811191sec preferred_lft 811191sec

Pick the name of the interface (wlan0 in my case. eth0 in your case?) and start tcpdump:

tcpdump -A -i eth0 udp port 4321 or udp port 9898

The interface (-i) must match your name of the network interface. Restart homeassistant now. You should see a “whois” call of home assistant now. The xiaomi gateway should respond with “iam”:

$ tcpdump -A -i wlan0 udp port 4321 or udp port 9898
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on wlan0, link-type EN10MB (Ethernet), capture size 262144 bytes
21:44:15.667818 IP wolowitz.45376 > 224.0.0.50.4321: UDP, length 15
E..+o.@........#...2.@......{"cmd":"whois"}
21:44:15.818990 IP lumi-gateway-v3-miio52244965.4321 > wolowitz.45376: UDP, length 88
E..t......-........#...@.`..{"cmd":"iam","port":"9898","sid":"286fffffffff","model":"gateway","ip":"192.168.130.29"}
21:44:15.819816 IP wolowitz.57393 > lumi-gateway-v3-miio52244965.9898: UDP, length 23
E..3.H@.@......#.....1&.....{"cmd" : "get_id_list"}

I assume the response doesn’t arrive. Please report!

Well, thank you for your tip.

I executed a tcpdump on hassIO and in other ubuntu server that I have. Ubuntu server receives the multicast packages, hassIO doesn’t. :frowning:

I was investigating and I think my issue is related with this:

I’m now trying to check how to solve this. One I have news, I’ll let you know. Thanks for the help.