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

Updated (including config) to 0.55. PyXiaomiGateway component did not get an update. Still the same ;-(

me, too. i updated to 0.55, the problem is the same.

I confirm HA v.0.55 the proble is still here:

2017-10-10 08:09:00 ERROR (Thread-6) [PyXiaomiGateway] Got error element in data {"error":"Invalid key"}
2017-10-10 08:09:00 ERROR (Thread-12) [PyXiaomiGateway] Got error element in data {"error":"Invalid key"}
2017-10-10 08:09:00 ERROR (Thread-4) [PyXiaomiGateway] Got error element in data {"error":"Invalid key"}
2017-10-10 08:09:00 ERROR (Thread-8) [PyXiaomiGateway] Got error element in data {"error":"Invalid key"}
2017-10-10 08:09:00 ERROR (Thread-10) [PyXiaomiGateway] Got error element in data {"error":"Invalid key"}

1 configuration.yaml:

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

Discover disabled

# Discover some devices automatically
#discovery:

2 pip show homeassistant:

Name: homeassistant
Version: 0.55.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: /srv/homeassistant/lib/python3.4/site-packages
Requires: async-timeout, voluptuous, jinja2, typing, pip, pytz, astral, chardet, pyyaml, aiohttp, requests

3 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: /srv/homeassistant/lib/python3.4/site-packages
Requires: pyCrypto

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: 

5 Xiaomi Gateway(s) Firmware version(s): both 1.4.1_150.0143

@Danielhiversen tell us if we can help with some log and thanks for your time!

EDIT: I’m running all on a Raspberry Pi 0 W with a manual installation of HA in a virtual environment (followed this guide: https://home-assistant.io/docs/installation/raspberry-pi/)
CPU load: 10%
Ram free: 269 MB

1 Like

Could you enable the debug log by

logger:
  default: warn
  logs:
    homeassistant.components.xiaomi_aqara: debug
    homeassistant.components.binary_sensor.xiaomi_aqara: debug
    homeassistant.components.sensor.xiaomi_aqara: debug
    homeassistant.components.light.xiaomi_aqara: debug
    homeassistant.components.switch.xiaomi_aqara: debug

and provide the log messages of a startup of HA up to the first “invalid key” message? You can filter the output for xiaomi_aqara:

tail -f home/homeassistant/.homeassistant/home-assistant.log | grep aqara

Thanks!

Hy syssi,

I followed your instruction and now I’m trying to reproduce the invalid key error, but without success.

At the moment the problem is that when I single click the xiaomi button sometimes it doesn’t trigger the relative action (switch off), maybe for the condition i put in the automation.

However for the “invalid key” problem I’ll let run the system with logger activated…

Here is the log at the moment:

2017-10-11 19:00:41 DEBUG (Thread-12) [homeassistant.components.xiaomi_aqara] Expecting 2 gateways
2017-10-11 19:00:41 INFO (Thread-12) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 1)
2017-10-11 19:00:47 DEBUG (Thread-12) [homeassistant.components.xiaomi_aqara] Gateways discovered. Listening for broadcasts
2017-10-11 19:00:49 DEBUG (Thread-2) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d00010ad259: off>: {'no_motion': '120'}
2017-10-11 19:01:14 DEBUG (Thread-11) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Plug_158d0001024ae5: on>: {'inuse': '1', 'power_consumed': '15380', 'voltage': 3600, 'load_power': '23.52', 'status': 'on'}
2017-10-11 19:01:29 DEBUG (Thread-11) [homeassistant.components.binary_sensor.xiaomi_aqara] Updating xiaomi sensor by polling
2017-10-11 19:01:29 DEBUG (Thread-12) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d00010ad259: off>: {'status': 'motion'}
2017-10-11 19:01:29 DEBUG (Thread-8) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Illumination_f0b429b452be: 619.0>: {'illumination': 917, 'rgb': 0}
2017-10-11 19:01:29 DEBUG (Thread-8) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Gateway Light_f0b429b452be: off>: {'illumination': 917, 'rgb': 0}
2017-10-11 19:01:29 DEBUG (Thread-11) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Door Window Sensor_158d00019ff192: on>: {'voltage': 3025, 'status': 'close'}
2017-10-11 19:01:30 DEBUG (Thread-11) [homeassistant.components.binary_sensor.xiaomi_aqara] Updating xiaomi sensor by polling
2017-10-11 19:01:30 DEBUG (Thread-11) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Door Window Sensor_158d0001210ad3: on>: {'voltage': 2985, 'status': 'open'}
2017-10-11 19:01:43 DEBUG (Thread-5) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d00010a7dbc: off>: {'status': 'motion'}
2017-10-11 19:01:43 DEBUG (Thread-7) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d00010ad2c7: off>: {'no_motion': '1800'}
2017-10-11 19:01:51 DEBUG (Thread-8) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Switch_158d0001151d6a: off>: {'status': 'click'}
2017-10-11 19:01:57 DEBUG (Thread-11) [homeassistant.components.binary_sensor.xiaomi_aqara] Updating xiaomi sensor by polling
2017-10-11 19:01:57 DEBUG (Thread-11) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d00010a7dbc: on>: {'voltage': 3035, 'status': 'motion'}
2017-10-11 19:01:57 DEBUG (Thread-5) [homeassistant.components.binary_sensor.xiaomi_aqara] Updating xiaomi sensor by polling
2017-10-11 19:01:58 DEBUG (Thread-5) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d00010ad259: on>: {'voltage': 3025, 'status': 'motion'}
2017-10-11 19:01:58 DEBUG (Thread-2) [homeassistant.components.binary_sensor.xiaomi_aqara] Updating xiaomi sensor by polling
2017-10-11 19:01:58 DEBUG (Thread-2) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Door Window Sensor_158d0001210ad3: on>: {'voltage': 2985, 'status': 'open'}
2017-10-11 19:02:15 DEBUG (Thread-12) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d00012915fc: off>: {'no_motion': '600'}
2017-10-11 19:02:28 DEBUG (Thread-3) [homeassistant.components.binary_sensor.xiaomi_aqara] Updating xiaomi sensor by polling
2017-10-11 19:02:28 DEBUG (Thread-3) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d00010a7dbc: on>: {'voltage': 3035, 'status': 'motion'}
2017-10-11 19:02:28 DEBUG (Thread-12) [homeassistant.components.binary_sensor.xiaomi_aqara] Updating xiaomi sensor by polling
2017-10-11 19:02:29 DEBUG (Thread-12) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d00010ad259: on>: {'voltage': 3025, 'status': 'motion'}
2017-10-11 19:02:29 DEBUG (Thread-4) [homeassistant.components.binary_sensor.xiaomi_aqara] Updating xiaomi sensor by polling
2017-10-11 19:02:29 DEBUG (Thread-4) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Door Window Sensor_158d0001210ad3: on>: {'voltage': 2985, 'status': 'open'}
2017-10-11 19:02:29 DEBUG (Thread-7) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d00013f796f: off>: {'no_motion': '300'}
2017-10-11 19:02:33 DEBUG (Thread-4) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d0000fd309e: off>: {'status': 'motion'}
2017-10-11 19:02:57 DEBUG (Thread-9) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Switch_158d0001151d6a: off>: {'status': 'click'}
2017-10-11 19:02:57 DEBUG (Thread-6) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Plug_158d0001024ae5: off>: {'status': 'off'}
2017-10-11 19:02:58 DEBUG (Thread-5) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Plug_158d0001291cad: off>: {'status': 'off'}
2017-10-11 19:02:58 DEBUG (Thread-8) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch Left_158d00014cedc5: off>: {'channel_1': 'off'}
2017-10-11 19:02:58 DEBUG (Thread-8) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch Right_158d00014cedc5: off>: {'channel_1': 'off'}
2017-10-11 19:02:59 DEBUG (Thread-3) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Illumination_f0b429a9ecc6: 236.0>: {'illumination': 494, 'rgb': 0}
2017-10-11 19:02:59 DEBUG (Thread-3) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Gateway Light_f0b429a9ecc6: off>: {'illumination': 494, 'rgb': 0}
2017-10-11 19:02:59 DEBUG (Thread-9) [homeassistant.components.binary_sensor.xiaomi_aqara] Updating xiaomi sensor by polling
2017-10-11 19:02:59 DEBUG (Thread-9) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d00010a7dbc: on>: {'voltage': 3035, 'status': 'no_motion'}
2017-10-11 19:03:00 DEBUG (Thread-2) [homeassistant.components.binary_sensor.xiaomi_aqara] Updating xiaomi sensor by polling
2017-10-11 19:03:00 DEBUG (Thread-2) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d00010ad259: on>: {'voltage': 3025, 'status': 'no_motion'}
2017-10-11 19:03:00 DEBUG (Thread-6) [homeassistant.components.binary_sensor.xiaomi_aqara] Updating xiaomi sensor by polling
2017-10-11 19:03:00 DEBUG (Thread-6) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Door Window Sensor_158d0001210ad3: on>: {'voltage': 2985, 'status': 'open'}
2017-10-11 19:03:00 DEBUG (Thread-9) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d00010ad2c7: off>: {'status': 'motion'}
2017-10-11 19:03:00 DEBUG (Thread-8) [homeassistant.components.binary_sensor.xiaomi_aqara] Updating xiaomi sensor by polling
2017-10-11 19:03:00 DEBUG (Thread-8) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d0000fd309e: on>: {'voltage': 2985, 'status': 'motion'}
2017-10-11 19:03:05 DEBUG (Thread-2) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Switch_158d0001151d6a: off>: {'status': 'click'}
2017-10-11 19:03:05 DEBUG (Thread-5) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Plug_158d0001024ae5: on>: {'status': 'on'}
2017-10-11 19:03:05 DEBUG (Thread-9) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Illumination_f0b429a9ecc6: 194.0>: {'illumination': 405, 'rgb': 0}
2017-10-11 19:03:05 DEBUG (Thread-9) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Gateway Light_f0b429a9ecc6: off>: {'illumination': 405, 'rgb': 0}
2017-10-11 19:03:19 DEBUG (Thread-5) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Switch_158d0001151d6a: off>: {'status': 'click'}
2017-10-11 19:03:30 DEBUG (Thread-3) [homeassistant.components.binary_sensor.xiaomi_aqara] Updating xiaomi sensor by polling
2017-10-11 19:03:30 DEBUG (Thread-3) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Door Window Sensor_158d0001210ad3: on>: {'voltage': 2985, 'status': 'open'}
2017-10-11 19:03:30 DEBUG (Thread-12) [homeassistant.components.binary_sensor.xiaomi_aqara] Updating xiaomi sensor by polling
2017-10-11 19:03:31 DEBUG (Thread-12) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d00010ad2c7: on>: {'voltage': 3015, 'status': 'motion'}
2017-10-11 19:03:31 DEBUG (Thread-3) [homeassistant.components.binary_sensor.xiaomi_aqara] Updating xiaomi sensor by polling
2017-10-11 19:03:31 DEBUG (Thread-3) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d0000fd309e: on>: {'voltage': 2985, 'status': 'motion'}
2017-10-11 19:03:40 DEBUG (Thread-6) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Illumination_f0b429b452be: 617.0>: {'illumination': 1038, 'rgb': 0}
2017-10-11 19:03:40 DEBUG (Thread-6) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Gateway Light_f0b429b452be: off>: {'illumination': 1038, 'rgb': 0}
2017-10-11 19:03:42 DEBUG (Thread-9) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d00010a7dbc: off>: {'no_motion': '120'}
2017-10-11 19:03:43 DEBUG (Thread-4) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d0000fd309e: on>: {'status': 'motion'}
2017-10-11 19:03:49 DEBUG (Thread-3) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Illumination_f0b429b452be: 738.0>: {'illumination': 1036, 'rgb': 0}
2017-10-11 19:03:49 DEBUG (Thread-3) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Gateway Light_f0b429b452be: off>: {'illumination': 1036, 'rgb': 0}
2017-10-11 19:03:51 DEBUG (Thread-9) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Illumination_f0b429b452be: 736.0>: {'illumination': 1052, 'rgb': 0}
2017-10-11 19:03:51 DEBUG (Thread-9) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Gateway Light_f0b429b452be: off>: {'illumination': 1052, 'rgb': 0}

and here is my configuration for the automation triggered by the button binary_sensor.switch_158d0001151d6a:

###Turn On###
#
- alias: Button Room Turn On lights
  hide_entity: True
  initial_state: 'on'
  trigger:
    - platform: event
      event_type: click
      event_data:
          entity_id: binary_sensor.switch_158d0001151d6a
          click_type: single
  condition:
    condition: and
    conditions:
     - condition: state
       entity_id: group.miastanzaluci
       state: "off"
  action:
   - service: switch.turn_on
     entity_id: switch.plug_158d0001024ae5
#
###Turn Off###
#
- alias: Button Room Turn Off lights
  hide_entity: True
  initial_state: 'on'
  trigger:
    - platform: event
      event_type: click
      event_data:
          entity_id: binary_sensor.switch_158d0001151d6a
          click_type: single
    - platform: event
      event_type: click
      event_data:
          entity_id: binary_sensor.switch_158d00015cc8bf
          click_type: single
  condition:
    condition: and
    conditions:
     - condition: state
       entity_id: group.miastanzaluci
       state: "on"
  action:
   - service: light.turn_off
     entity_id: light.miastanza
   - service: light.turn_off
     entity_id: light.gateway_light_f0b429a9ecc6
   - service: light.turn_off
     entity_id: light.desk_lamp
   - service: switch.turn_off
     entity_id: switch.wall_switch_right_158d00014cedc5
   - service: switch.turn_off
     entity_id: switch.plug_158d0001024ae5
   - service: switch.turn_off
     entity_id: switch.plug_158d0001024aee
   - service: switch.turn_off
     entity_id: switch.plug_158d0001291cad
   - service: switch.turn_off
     entity_id: switch.wemo_led

Thanks

Hi any luck with this, I’m experiencing the same issue, what’s weird is everything works perfectly fine with Openhab. But I really enjoy the support, community and simplicity of HASS. Would really appreciate if this worked.

Same Error:
2017-10-12 14:19:41 ERROR (Thread-7) [PyXiaomiGateway] Got error element in data {“error”:“Invalid key”}

Interesting. Are you using the same key with Openhab and HA?

Does everyone with the “Invalid key” problem have two gateways?
Do you have the same problem if you disconnect one of the gateways?

I thought that might be the issue and turned off the second gateway, I still have the same issue.

whether I try xiaomi or xiaomi_aqara

xiaomi_aqara:
gateways:
- sid: xxxxxxx
key: e41471Xxxxxxx50

Got only one gateway ;-(

Did you try changing the wifi password?

Nope…The gateway is connected to my network and controllable via app. So I can‘t see, why I should change the Wifi Key. What leads you to point towards wifi, if I‘d ask?

Thanks and regards

Jakob

I got same issue sine Hass 0.52. One gateway, no mac configured in configuration.yaml.

Someone told me it is a transport protocol issue…

no, i only got one gateway.

Any more details?

I just set up my gateway this week and am having some similar issues. I will be able to use the light for a short time before it becomes unresponsive and I get the Invalid key error. Sometimes, when I try to turn on the light the switch will turn on, then turn back off. When this happens, the light will sometimes turn on by the 3rd or 4th time, and there are no errors in the log when this happens. The problems are usually fixed by restarting hassio, but today I had to restart my Pi. It doesn’t work for too long before it happens again. I’ve got a RPi 2 running hassio 0.55.0. My gateway has firmware 1.4.1_150.0143.

Don’t recall where I read this, but it requires that your router supports multicast.

1 Like

hello. i spent 2 days with “invalid key”. trying different
versions HA, python. on one installations HA (windows x32) - all good, on other(windows x64) - “invalid key”. and found a solution for me. on second HA also installed Docker. and in system present network adapter from Docker. if i disable this adapters, leaving hardware netcard - all work very GOOD. if enable -" “invalid key”. in configuration.yaml i write and host , and mac , and key for xiaomi_aqara gw. with 2 or >2 adapters NOT WORK for me.
good luck.

1 Like

I am also having invalid key issue as described here: New Xiaomi gateway firmware (xiaomi_aqara component) - #30 by uiguy

Could you possibly describe your docker solution in more detail?

Additionally following my post, i am now receiving this error on my primary docker HA instance:

2017-10-24 00:12:23 ERROR (SyncWorker_9) [PyXiaomiGateway] Cannot connect to Gateway
2017-10-24 00:12:23 ERROR (SyncWorker_9) [PyXiaomiGateway] No data in response from hub None

Getting this in my RPI3 running AIO HA when trying to turn off the light on the gateway

2017-10-24 00:14:05 ERROR (Thread-9) [PyXiaomiGateway] Cannot connect to Gateway
2017-10-24 00:14:05 ERROR (Thread-9) [PyXiaomiGateway] No data in response from hub None

Thanks

Try to add --net=host