PyXiaomiGateway Problem: {"error":"Invalid key"}

Hey there,

I´ve tried a lot, to fix this. Now I got duplicate devices, but the issue still exists. But lets start at the beginning :slight_smile:

I´m using PyXiaomiGateway because $$ and it seems to work very nice for sensors and buttons. Thanks to the developers and testers! Recently I´ve tried, to use the Gateway light and the ringtone integration and smart wallplug.

Unfortunatelly I cant use the devices - every issued service call leads to

[PyXiaomiGateway] Got error element in data {"error":"Invalid key"}

In order to fix the thing, I followed the troubleshooting guide, wich is part of the official component documentation.
That for I´ve:

  • Factory reset the Gateway
  • Disabled & Reenabled local access
  • Regenerated the Access Key several times

What I got now, is still the same error message (the key is correctly formed and consists of the 16 characters, that it should :wink:

The versions are all current -

[homeassistant] % pip show homeassistant
Name: homeassistant
Version: 0.54.0
Summary: Open-source home automation platform running on Python 3.
Home-page: https://home-assistant.io/
Author: The Home Assistant Authors
Author-email: [email protected]
License: Apache License 2.0
Location: /usr/local/homeassistant/lib/python3.5/site-packages
Requires: chardet, jinja2, pyyaml, typing, aiohttp, pip, pytz, astral, voluptuous, requests, async-timeout

[homeassistant] % pip show PyXiaomiGateway
Name: PyXiaomiGateway
Version: 0.5.1
Summary: a library to communicate with the Xiaomi Gateway
Home-page: https://github.com/Danielhiversen/PyXiaomiGateway/
Author: Daniel Hoyer Iversen
Author-email: UNKNOWN
License: UNKNOWN
Location: /usr/local/homeassistant/lib/python3.5/site-packages
Requires: pyCrypto

[homeassistant] % pip show pyCrypto
Name: pycrypto
Version: 2.6.1
Summary: Cryptographic modules for Python.
Home-page: http://www.pycrypto.org/
Author: Dwayne C. Litzenberger
Author-email: [email protected]
License: UNKNOWN
Location: /usr/local/homeassistant/lib/python3.5/site-packages
Requires:

The Config is
xiaomi:
gateways:
- mac: xxxxxxxxxxxx
key: xxxxxxxxxxxxxxxx

Anyone has an idea, on how to fix this? Second thing, can somebody help me, cleaing out the duplicates - I´ve all devices twice (with a “_2”) since the last gateway reset.

Thanks in advance and greetings

Jakob

Please change from xiaomi to xiaomi_aqara in your config, then the duplicates will disappear and maybe the other problem too.

Thanks Daniel! The duplicates disappeared as promised :slight_smile:
Unfortunately the error still comes up, when I try to interact with devices:
[PyXiaomiGateway] Got error element in data {"error":"Invalid key"}

Thanks and regards,

Jakob

Your key is probably invalid.
Make sure it is correct or try to generate a new one.

I´ve disabled and reenabled local access, generated new key multiple times and even factory reset the gateway. No change :frowning: I got a not 100% common setup - I´m running HA on FreeBSD (in a VirtualEnv via “activate.csh”). The python modules are all in place and current. Any ideas, on how my setup can influence the Xiaomi-Gateway?

Is the mac address correct? Try with a blank mac address

Double checked the mac and copied from the discovery log entry:
[homeassistant.components.xiaomi_aqara] Discovered: {'properties': {'epoch': '1', 'mac': 'xxxxxxxxxxxxxxxx'},
No mac adress - the same :frowning:

You are using a single gateway, right?

Yepp. Single gateway. Added a “bind interface” now - just to be sure.
I got no NAT between Ha and Xiaomi Gateway. Ideas, how to nail it down?

Could you post your configuration well formatted? Please just anonymize a few characters of the values.

Hi, I have exactly the same problem.

It fetches the data of the sensors on restart but on any command sent to the GW it gets
PyXiaomiGateway Problem: {“error”:”Invalid key”} in the log

Here is the xiaomi part of the config

xiaomi_aqara:             
  gateways:                                             
   - host: 192.168.0.24                                                   
     mac: fxxxxxxxxxxa                                         
     key: 4xxxxxxxxxxxxxxk

Its the first time on this update (54) that i manage to get data from the GW.
I had already tried the DOMOTICZ with the same key of the GW with success so it is correct.

Thank you for your efforts on this!

BR/Aris Greece.

@arts: Could you describe your setup a bit? Do you use hassbian, hassio? It’s a fresh install or did you just enable the xiaomi_aqara component recently and updated to HA 0.54? I’m trying to reproduce the issue locally.

1 Like

Thank you syssi,

My setup is new ,on Rasberry p1 hassio 1.1 and HA 0.54.
The components that I already have and want to use are

One gateway with 3 magnetic contacts, one motion sensor , 3 temperature, and 3 motion sensors.

One Sonos AMP, one apple TV and 2 mac plex players on one plex server, one Broadlink SPMini wifi plug, one xiaomi wifi LED RGB.

I have also 2 WiFi inventor A/C (not supported on HA yet?)

I want to buy and add on HA IKEA GW with LED lamps and some sonof wifi switches.

I love this project, my main problems are the Xiaomi GW and the Broadlink spmini.

BR/Aris

1 Like

same here. im running hass.io on a raspberry pi. i set it up directly with the newest version and the xiaomi gateway is the only smart home component i run so far (the other one is yahoo weather).

my log file says:

2017-10-04 20:48:58 WARNING (MainThread) [homeassistant.components.xiaomi_aqara] Static address (10.0.0.2:9898) of the gateway provided. Discovery of this host will be skipped.
2017-10-04 20:49:09 WARNING (MainThread) [homeassistant.setup] Setup of sensor is taking over 10 seconds.
2017-10-04 20:49:09 WARNING (MainThread) [homeassistant.setup] Setup of weather is taking over 10 seconds.
2017-10-04 20:49:13 WARNING (MainThread) [homeassistant.setup] Setup of tts is taking over 10 seconds.
2017-10-04 20:49:35 WARNING (SyncWorker_7) [netdisco.ssdp] Error fetching description at 10.0.0.11
2017-10-04 20:49:41 WARNING (SyncWorker_7) [netdisco.ssdp] Error fetching description at http://192.168.1.250:49152/description.xml
2017-10-04 20:49:50 ERROR (SyncWorker_3) [PyXiaomiGateway] Got error element in data {"error":"Invalid key"}
2017-10-04 20:49:56 ERROR (SyncWorker_18) [PyXiaomiGateway] Got error element in data {"error":"Invalid key"}
2017-10-04 20:50:04 ERROR (SyncWorker_4) [PyXiaomiGateway] Got error element in data {"error":"Invalid key"}

my config:

xiaomi_aqara:
  gateways:
   - host: 10.0.0.2
     mac: f0b4299aaaxx
     key: aa70f5f513ac43xx

So…what now. It seems, that some people do have auth issues with the Xiaomi Aquara gateways. Can we open an issue/bug on that? How can we nail the issue down? If there is need for debug info, please let me know. Alternatively I can create a bug/issue (if I´d now, how to open them :wink:).

1 Like

I got that error once when the gateway had no connectivity. Can you double check (using the Mi app) that the gateway is connected?

i checked a couple of times, i was perfectly connected with the mi-app. i also tried to regenerate the keys, which changed nothing.

Same issue here: ERROR (Thread-6) [PyXiaomiGateway] Got error element in data {"error":"Invalid key"}

But If I insist and try to trigger repeatedly the button associated with a Xiaomi gateway’s sub-device finally HA works and trigger the acction without any “Invalid key” on the log.

I tried to revert to older versions of HA, but the issue is still here.

my configuration is:

1 configuration.yaml (xiaomi and not xiaomi_aquara as i reverted HA to version 0.52.1)

xiaomi:
 gateways:
   - mac: FXXXXXXXXXX6
     key: fxxxxxxxxxxxxxxw
   - mac: FXXXXXXXXXXE
     key: 9xxxxxxxxxxxxxx8

Discover disabled

# Discover some devices automatically
#discovery:

2 pip show homeassistant

Name: homeassistant
    Version: 0.52.1
    Summary: Open-source home automation platform running on Python 3.
    Home-page: https://home-assistant.io/
    Author: The Home Assistant Authors
    Author-email: [email protected]
    License: Apache License 2.0
    Location: /srv/homeassistant/lib/python3.4/site-packages
    Requires: jinja2, pip, requests, pytz, voluptuous, async-timeout, typing, astral, aiohttp, pyyaml, charde

3 pip show PyXiaomiGateway:

Name: PyXiaomiGateway
    Version: 0.3.0
    Summary: a library to communicate with the Xiaomi Gateway
    Home-page: https://github.com/Danielhiversen/PyXiaomiGateway/
    Author: Daniel Høyer Iversen
    Author-email: UNKNOWN
    License: UNKNOWN
    Location: /srv/homeassistant/lib/python3.4/site-packages

4 pip show pyCrypto:

Name: pycrypto
    Version: 2.6.1
    Summary: Cryptographic modules for Python.
    Home-page: http://www.pycrypto.org/
    Author: Dwayne C. Litzenberger
    Author-email: [email protected]
    License: UNKNOWN
    Location: /srv/homeassistant/lib/python3.4/site-packages
    Requires:

PyXiaomiGateway is now at version 0.5.1, so try to upgrade HA to 0.55

thanks for reply. I came from HA 0.54 and reverted to 0.52.1 just to try if old versions have no issues.

Is the PyXiaomiGateway version that came with HA 0.55 newer than the version that came with HA 0.54?