Xiaomi gateway not discovered

What would be the best way to proceed in this case? There seems to be a problem with hassio and the way the discovery is performed. I would assume that the situation here is that the multicast reply is not being received by the container. Has anyone figured out a solution for this? Could we at least brainstorm on how to solve this?

I’ve looked at the code, and if I understand correctly, after discovering the Xiaomi gateway, the communication between homeassistant and the xiaomi gateway is performed by udp sockets. Could we start from here?

Well, during these last days I spent some time trying to have the hassIO working with Xiaomi gateway, but without success. :frowning: Multicast traffic is not arriving into the container, it arrives at host level but then that info doesn’t arrive to the container. I tried with iptable rules,nothing, tried to change network mode of the container from bridge to host, nothing… Well no ideia how we can solve this :frowning:

This seems to be a limitation of the docker network stack. As far as I understand, the Xiaomi component also listens on a multicast address with a specific port, and afaik, the docker network stack still doesn’t know how to deliver multicast packets to the container interface.

What I’m trying to understand is if discovery is the only valid method to configure the Xiaomi gateways. I understand that direct IP access is not implemented (yet?), but I’m also trying to understand if by configuring the gateway IP address we would be able to communicate with it without using multicast discovery. Anyone can give some more info on this topic?

Do you like to do some testing? Do you have access to your hassio instance by SSH and are you able to change this file:
PyXiaomiGateway/__init__.py

If you confirm, we can give it a try to remove/hack the discovery method and set a static entry:

_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
_socket.bind((self._interface, 0))
self.gateways['192.168.x.x'] = XiaomiGateway('192.168.x.x', 9898, '28fffffffffff', 'keykeykey', self._socket)

It’s just a test. I don’t believe the gateway response if it wasn’t discovered properly previously.

If I’m able to access the code through SSH, I’ll test this later today and report back.

This is the idea: Provide a “host” parameter and skip the discovery.

I’m unable to change the code using the SSH add-on on Hassio. However, I believe it might be possible to test the code on a regular Homeassistant installation. If so, I’ll try your changes on a regular installation, with discovery disabled, and see if it works.

The code should be tested on a docker environment to make sure it solves your problem. I changed the home assistant component slightly to introduce the new parameter (“host” and “port”):

This is an example of a static configuration without discovery:

xiaomi:
  gateways:
    - mac: 34ffffffffff
      key: asdfasdfasdfasdf
      host: 192.168.130.63

You have to change both. The home assistant component and the underlying library (PyXiaomiGateway).

Ok, I’ll do this today, I’ll install on my Linux Desktop using docker and see if it works and report back

Thank you for your help.

I had to do some small changes to the code because it was not running (was not finding XIAOMI_SERVICE_GW in discovery.py)

This is the result that I’m getting:

2017-09-13 20:01:09 ERROR (Thread-2) [PyXiaomiGateway] Unknown gateway ip 192.168.1.157

Sounds like you copied the whole file and not just the changed part. The file is based on the current development branch where mDNS recovery was recently introduced. Your changed line belongs to the new mDNS/netdisco auto-discovery feature.

Is this (192.168.1.157) the ip address of the gateway? If yes, there is something wrong with your static configuration.

L58 adds the static configuration / a gateway to the list of known gateways. L158 looks up the ip address of a received multicast in the list of gateways. If the gateway isn’t found the error message is thrown.

Hello,

I’m running HassIO and trying to make the Xiaomi gateway to work. Your patch look promising!

I had no problem to override the xiaomi component, thanks to the custom_components directory, but I don’t know how to override the PyXiaomiGateway library with HassIO… I don’t know docker very well.

Any idea how I could patch the library?

Thanks.

Just replace this lines:

by

REQUIREMENTS = ['https://github.com/syssi/PyXiaomiGateway/archive/feature/no-discovery.zip#PyXiaomiGateway==0.3.2']

I hope the new requirement will override the old one also.

Hello i got same problem, on ethernet the ha dont dectect the gateway, and with tcpdump i see the gateway msg, but when ha call whois the gateway dont reply, but on wireless all work fine!

the only problem is that I use the RPI as a VPN server and connect wireless is very slow, it is possible to put it to work by ethernet. Or ethernet + wifi?

:smiley:

thanks

The good news: changing the requirement worked. The component doesn’t crash anymore because PyXiaomiGateway doesn,t support the host parameter.

The bad news is my gateway is still not working.

2017-09-15 16:52:56 WARNING (MainThread) [custom_components.xiaomi] IP address (host) of the gateway provided.Discovery of this host will be skipped.
2017-09-15 16:53:02 INFO (SyncWorker_13) [custom_components.xiaomi] Discovering Xiaomi Gateways (Try 1)
2017-09-15 16:53:02 INFO (SyncWorker_13) [PyXiaomiGateway] Xiaomi Gateway 34ce00xxxxxx found at IP 192.168.77.3
2017-09-15 16:53:02 INFO (SyncWorker_13) [PyXiaomiGateway] Discovering Xiaomi Devices
2017-09-15 16:53:02 INFO (SyncWorker_13) [PyXiaomiGateway] Found 1 devices
2017-09-15 16:53:02 ERROR (SyncWorker_13) [PyXiaomiGateway] Not a valid device. Check the mac adress and update the firmware.

I also get the “not a valid device” with the original library. Maybe I have a different problem… My firmware version is 1.3.1_140. I read that the most current firmware is causing issues so I didn’t upgraded.

Well, in fact my gateway seem to work partially. I added switch with the Mi Home app and I see them in Home Assistant. Automation on theses switches also work. But I don’t see the gateway (like the light sensor) and the play_ringtone do nothing. But I suspect my problem is not related with the original topic…

To return to the original topic… I tried to revert the changes to try again with the original component/lib in order to check if your change helped me or not (and confirming if this is required to make it work on hass.io). When home assistant start, I get this exception:

2017-09-15 22:27:45 ERROR (MainThread) [homeassistant.setup] Error during setup of component xiaomi
  File "/usr/lib/python3.6/site-packages/homeassistant/components/xiaomi.py", line 71, in setup
    hass.data[PY_XIAOMI_GATEWAY].discover_gateways()
  File "/usr/lib/python3.6/site-packages/PyXiaomiGateway/__init__.py", line 45, in discover_gateways

So for now, I returned with the modified version and I’m able to make my switch to work, but I don’t have access to the gateway itself.

Your firmware is pretty old. The support for ringtones was introduced with version 1.4.1_145. Please try to open the update dialog of your gateway (at the Mi Home app) and check the available version. The gateway cannot be updated to the latest version without intermediate (version) steps. Just take care you are not updating to version 149. If the available version not equals 1.4.1_149 the update will be safe.

Could you post the complete error message? I guess the important part is missing and please check your home assistant and PyXiaomiGateway library “versions” are in sync.

Your firmware is pretty old. The support for ringtones was introduced with version 1.4.1_145. Please try to open the update dialog of your gateway (at the Mi Home app) and check the available version. The gateway cannot be updated to the latest version without intermediate (version) steps. Just take care you are not updating to version 149. If the available version not equals 1.4.1_149 the update will be safe.

I was able to upgrade from 1.3.1_140.0141 to 1.3.1_141.0143 but after that the next update is 1.4.1_149.0143 :frowning:

Could you post the complete error message? I guess the important part is missing and please check your home assistant and PyXiaomiGateway library “versions” are in sync.

I pasted the complete message unless I miss something.