New Xiaomi gateway firmware (xiaomi_aqara component)

Hi, today I’ve updated my Xiaomi gateway to the 150 build and everything appears to function fine apart from all of mine temperature & humidity sensors, which in HA don’t report any values. Tried creating and moving to a new room (in MI app, per suggestion above), no success. What can I do? Some of you said that after a couple of days things normalized, is this true?

There is a bug in 0.56 for the temperature sensors, but it is fixed in the dev branch: https://github.com/home-assistant/home-assistant/pull/10024

3 Likes

Is there a smart way to patch this bug somehow ?

I know that this thread isn’t for Xiaomi support but I’m not sure where else to ask this:

Has anyone else had trouble setting up sensors through the MiHome app on Android? I can setup my Xiaomi gateway smoothly but when I try to add a door sensor, I can’t get it to come up on the app. When I try to manually add the door sensor and tap on the door sensor icon, nothing happens.

The support page for Xiaomi says to make sure that your phone’s bluetooth is on. The door sensor is within 2 feet of my gateway and my phone. I’ve reset the bluetooth on my phone and taken the batteries out of the door sensor multiple times, and have uninstalled/reinstalled the MiHome app multiple times. The door sensor will not show up in my MiHome app on Android.

Has anyone had a similar issue or could offer any advice on how to get around this? I’m trying to set my gateway up with Home Assistant but I haven’t been able to get that far yet because of this issue. Thanks!

0.56.1 is out & fix this bug.

I am losing the will to live with this gateway… It connected twice, I was able to setup and customise my components, then restarted core and then nothing… tried for another 2 days and now it is connected again…

I am however getting this error when I try and turn off the light on the gateway:

ERROR (SyncWorker_1) [PyXiaomiGateway] Got error element in data {"error":"Invalid key"}

This thing is so super flaky…

I have the follwing thoughts around possible problem areas:

  1. Server is set to mainland (china) in the iOs App, could this be causing issues? It is the only way I can see to add the gateway…
  2. I have a UniFi® Security Gateway, although I am told this has muticast by default…
  3. I have a linksys mesh wifi network in bridge mode… could the gateway changing between 2 AP’s on the mesch be causing issues?
  4. I am running HA in docker on my Synology NAS, however have net=host in my docker run cli command.

I am about to reboot, but will bet anyone a beer the Xiaomi gateway cannot be discovered on reboot…

Super frustrating as I managed to open my OpenGarage component (once) using the wireless button… so it works… sometimes and more often not…

Any ideas here? Any help much appreciated, otherwise, this little, noisy, screamin kit is heading back to china…

Just keep calm and stick to this topic: PyXiaomiGateway Problem: {"error":"Invalid key"} - #39 by uiguy

If you are willing to do some testing we will find a proper solution and I will guide you to a stable setup. You will need to spent some more hours because your infrastructure is the cause and we have to identify the critical parts.

Hi, so my button appears to be working fine now… the light on the gateway seems to theow invalid key, happy to help test where i can :sunglasses:

Just to add, i tried turning off the gayeway light with the app and this also failed, so i think the issue is with the gateway and my infrastructure and not with home assistant per se…

I will try to explain the local network protocol of the gateway a bit: The communication between Gateway and Home Assistant uses UDP. A protocol without handshaking dialogues and error correction if a packet gets lost. At the discovery of the Gateway a command requests the first token. All further needed tokens are published via a heartbeat message (multicast (udp), port 9898). The latest published token is always needed to execute a command on the gateway. If Home Assistant just receives the first token and none of the heartbeats with new tokens you will receive the “Invalid key” error message and the control of devices will fail.

There are two possibilities now: You network / wireless connection is very bad. There is packet loss and Home Assistant doesn’t receive all needed heartbeat messages. Second possibility: Your network doesn’t transport multicast messages properly and your Home Assistant instance just receives the first token (received directly by UDP (no multicast)) and this token never gets updated because of the missing multicast traffic.

Hi guys,

I have a Xiaomi Gateway and it worked well before “aqara” update and it seems to work well now, but I got this message all the time when I restart HA:

Failed config
  General Errors: 
    - Component not found: xiaomi_aquara
    - Setup failed for xiaomi_aquara: Component not found.

I don’t know whats wrong because everything works well. This is what in my configuration.yaml:

xiaomi_aqara:
  discovery_retry: 5
  gateways:
    - mac: Gateway MAC address here
      key: Gateway token here

This is the repeatedly error message in log file:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/xiaomi.py", line 113, in _retrieve_list
    res = requests.get(url, timeout=5, **kwargs)
  File "/usr/lib/python3.6/site-packages/requests/api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/lib/python3.6/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 518, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 639, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3.6/site-packages/requests/adapters.py", line 514, in send
    raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPConnectionPool(host='192.168.31.1', port=80): Read timed out. (read timeout=5)
2017-10-27 08:09:28 WARNING (MainThread) [homeassistant.components.device_tracker] Updating device list from xiaomi took longer than the scheduled scan interval 0:00:12
2017-10-27 08:09:30 ERROR (SyncWorker_9) [homeassistant.components.device_tracker.xiaomi] Connection to the router timed out at URL http://192.168.31.1/cgi-bin/luci/;stok=036ace34426fc19f588c6c2cb226eef9/api/misystem/devicelist
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 386, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 382, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.6/http/client.py", line 1331, in getresponse
    response.begin()
  File "/usr/lib/python3.6/http/client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.6/http/client.py", line 258, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)
socket.timeout: timed out

I can use my gateway light, xiaomi button, cube, sensors, everything. What’s wrong than? :tired_face:

Please check your network. Your OpenWRT router (192.168.31.1) isn’t available and Home Assistant is unable to contact the Xiaomi Gateway.

Hi, thank you for your answer. It was my fault. I had been stupid because I use bad string “xiaomi_aquara” instead of “xiaomi_aqara”.

I have the same problem as the previous poster but does not appear to be a typo.

Error is:

2017-11-02 13:21:55 ERROR (MainThread) [homeassistant.loader] Unable to find component xiaomi_aqara
2017-11-02 13:21:55 ERROR (MainThread) [homeassistant.setup] Setup failed for xiaomi_aqara: Component not found.
2017-11-02 13:21:56 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=persistent_notification, service=create, service_data=title=Invalid config, message=The following components and platforms could not be set up:
xiaomi_aqara
2017-11-02 13:21:56 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=persistent_notification.invalid_config, old_state=None, new_state=<state persistent_notification.invalid_config=The following components and platforms could not be set up:
xiaomi_aqara

I have not had any other issues with anything else I have setup. eg. mysensors gateways (x2), Philips Hue, Wemo,

I am currently running Hass.io 0.52.1 on a Raspberry Pi which is connected to my LAN via Ethernet. Wifi supplied to the Xiaomi Gateway is via a router running Gargoyle firmware. I have tried a variety of configuration.yaml entries but it is currently:

xiaomi_aqara:
  discovery_retry: 10
  interface: '192.168.1.168'
  gateways:
    - host: 192.168.1.168
      mac: 34ce00fa5e77
      key: xxxxduu9ybt6xxxx

Help?

You need to upgrade to a newer version of Ha

Thanks Daniel. Some progress though I now have this error:

2017-11-02 16:51:08 ERROR (MainThread) [homeassistant.setup] Error during setup of component xiaomi_aqara
Traceback (most recent call last):
File “/usr/lib/python3.6/site-packages/homeassistant/setup.py”, line 194, in _async_setup_component
component.setup, hass, processed_config)
File “/usr/lib/python3.6/asyncio/futures.py”, line 331, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.6/asyncio/tasks.py”, line 244, in _wakeup
future.result()
File “/usr/lib/python3.6/asyncio/futures.py”, line 244, in result
raise self._exception
File “/usr/lib/python3.6/concurrent/futures/thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/lib/python3.6/site-packages/homeassistant/components/xiaomi_aqara.py”, line 95, in setup
interface)
File “/usr/lib/python3.6/site-packages/PyXiaomiGateway/init.py”, line 31, in init
self._socket.bind((interface, 0))
OSError: [Errno 99] Address not available
2017-11-02 16:51:09 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=persistent_notification, service=create, service_data=title=Invalid config, message=The following components and platforms could not be set up:

  • xiaomi-aqara
    Please check your config, notification_id=invalid_config, service_call_id=1966250672-2>
    2017-11-02 16:51:09 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=persistent_notification.invalid_config, old_state=None, new_state=<state persistent_notification.invalid_config=The following components and platforms could not be set up:
  • xiaomi-aqara
    Please check your config; title=Invalid config @ 2017-11-02T16:51:09.107352+10:00>>

I have slimmed down my configuration.yaml to this:

xiaomi_aqara:
  discovery_retry: 10      
  interface: '192.168.1.168'      
  gateways:
    - mac:          
      key: xxxxduu9ybt6xxxx

Something is wrong the interface adress

Might be an issue with the instructions or the underlying code as I thought I had the config correct as per the docs? I have changed my configuration.yaml to the following and it is working. Thanks for the help Daniel!

xiaomi_aqara:
  discovery_retry: 10
  gateways:
    - host: 192.168.1.168
    - mac:
      key: xxxxduu9ybt6xxxxx

Then it would be great if you can help update and improve the documentation. In the upper right corner of any documentation page, you will find “Edit this page on GitHub”. Follow the link and submit your suggested change. Demonstrated here: https://youtu.be/dRfk9JAlPJk?t=1h16m17s

I would be happy to but I am not sure what the issue is with the interface line. Should it not have the single quotes around it? If they are supposed to be there I don’t know why it did not work?

Edit: I will try the interface line without the quotes and see if it works.