Xiaomi Gateway Integration

Hey,
as i remeber right, i did update the gateway again, tripple-checked the sid and key and bought i fritzbox, have had a easybox from vodafone before.

A few minutes ago my Xiaomi Gateway stopped working in hass:

Aug 20 19:28:02 hass dockerd[674]: 2017-08-20 19:28:02 ERROR (SyncWorker_10) [PyXiaomiGateway] Got error element in data {"error":"Invalid key"}

I have already tried to change the network key in the app but I still get this error. I can still see the sensors in the gateway in home assistant. But I cannot change the light or see any new movement events… What could be the reason?

I have not changed anything in home assistant before this error occured…

The gateway works fine in the mi app.

I had a kinda similar issue, try going to the MIHome app, go to the gateway, disable the “Lan” access and make sure you get a “Result: OK” or whatever it says, then re-enable the LAN access, get a “Result: OK”, then put you new code into the config and restart

i’m running hassbian v50.2 and my config is :

xiaomi:
  gateways:
    - mac: XXMacHereXX
      key: XXKeyHereXX

You can do it without the app by pressing the button on the gateway three times to get it in pairing mode and then whatever needs to be done on the device. (I think - google it first or search this thread for @syssi instructions.)

That said, last week I thought I had completely messed mine up trying to do this because I held the button in for to long and did a reset. The good news is that once I added the gateway into the app it had kept all its sub devices, the bad news is that I had to put it in developer mode again and get a new key.

Also, I’ll mention here that setup wouldn’t work at all with Android O (8), I had to get an older tablet out and install the mi-app on that. Again, once signed in to my Xiaomi account it pulled everything in.

Enable debugging for the xiaomi component and check the log

I’ve just started switching from domoticz to home assistant. I’m impressed.
I’ve managed to add my xiaomi gateway. All 8 motion sensors, 8 smoke detectors, 3 switches / buttons and a few outlet switches are properly recognized.

I’ve added some alarm automation rules, while motion detected when armed_away, I get a push message in my iphone.

Currently I’m on vacation… and I scared a bit… because all my motion sensors got triggered in the span of about an hour.
I opened my mi home app, there hasn’t been any motion detected in the log’s since I’ve left home.

The motion sensors remain active in home assistant. Because i’m running HASS in a docker container i’ve pulled some log engtries.

{
"log": "\u001b[32m2017-08-21 11:37:16 INFO (MainThread) [homeassistant.core] Bus:Handling \u003cEvent motion[L]:entity_id=binary_sensor.motion_sensor_158d00013fb0af\u003e\u001b[0m\n",
"stream": "stderr",
"time": "2017-08-21T09:37:16.338920377Z"
}
{"log":"\u001b[32m2017-08-21 11:37:16 INFO (MainThread) [homeassistant.core] Bus:Handling \u003cEvent motion[L]: entity_id=binary_sensor.motion_sensor_158d00013fb0af\u003e\u001b[0m\n","stream":"stderr","time":"2017-08-21T09:37:16.338920377Z"}
{"log":"\u001b[32m2017-08-21 11:37:16 INFO (MainThread) [homeassistant.core] Bus:Handling \u003cEvent state_changed[L]: entity_id=binary_sensor.motion_sensor_158d00013fb0af, old_state=\u003cstate binary_sensor.motion_sensor_158d00013fb0af=off; No motion since=0, battery_level=53.0, friendly_name=Woonkamer, device_class=motion @ 2017-08-21T00:46:09.987461+02:00\u003e, new_state=\u003cstate binary_sensor.motion_sensor_158d00013fb0af=on; No motion since=0, battery_level=53.0, friendly_name=Woonkamer, device_class=motion @ 2017-08-21T11:37:16.339105+02:00\u003e\u003e\u001b[0m\n","stream":"stderr","time":"2017-08-21T09:37:16.340825998Z"}
{"log":"\u001b[32m2017-08-21 11:37:16 INFO (MainThread) [homeassistant.components.automation] Executing iOs beweging woonkamer\u001b[0m\n","stream":"stderr","time":"2017-08-21T09:37:16.343232024Z"}

All motion sensors report state “on” in the states panel.

{
 "No motion since": 0,
 "battery_level": 49,
 "friendly_name": "Keuken",
 "device_class": "motion"
}

After restarting HASS the states remain “on”

Can anyone tell me what’s happening?

I’m running the latest firmware and hass version.

Hi guys,

Just wondering if the Xiaomi smart power strip (https://www.zapals.com/xiaomi-mi-smart-power-strip-6-sockets-wi-fi-remote-control.html) is supported by the Gateway component?

Cheers.

The power strip is a WiFi device (and not a zigbee one). It can be integrated by another (so far) unoffical component: GitHub - syssi/xiaomiplug: Xiaomi Mi Smart WiFi Socket integration for Home Assistant.

Thank you.

thanks for the reply but i solved the problem, i repleced the “sid” with mac (with colon) and it starts working again.

is it possible to set in the automation how much time the gateway has to fire the alarm?

Great, thanks a lot! I also had an easybox - changed that, now everything works just fine.

I seem to be getting this error message quite often lately.

However, I can still control gateway light via HASS which means gateway is working?

Is this a known problem?

2017-08-22 18:49:05 WARNING (MainThread) [homeassistant.helpers.entity] Update of binary_sensor.motion_sensor_158d000155df00 is taking over 10 seconds 2017-08-22 18:49:05 ERROR (Thread-11) [PyXiaomiGateway] Cannot connect to Gateway 2017-08-22 18:49:05 ERROR (Thread-11) [PyXiaomiGateway] No data in response from hub None 2017-08-22 18:52:24 ERROR (Thread-5) [homeassistant.components.light.yeelight] Unable to update bulb status: A socket error occurred when sending the command. 2017-08-22 19:05:06 WARNING (MainThread) [homeassistant.helpers.entity] Update of binary_sensor.motion_sensor_158d000155df00 is taking over 10 seconds 2017-08-22 19:05:06 ERROR (Thread-5) [PyXiaomiGateway] Cannot connect to Gateway 2017-08-22 19:05:06 ERROR (Thread-5) [PyXiaomiGateway] No data in response from hub None 2017-08-22 19:14:54 WARNING (MainThread) [homeassistant.helpers.entity] Update of binary_sensor.motion_sensor_158d000155df00 is taking over 10 seconds 2017-08-22 19:14:54 ERROR (Thread-8) [PyXiaomiGateway] Cannot connect to Gateway 2017-08-22 19:14:54 ERROR (Thread-8) [PyXiaomiGateway] No data in response from hub None 2017-08-22 19:21:23 ERROR (Thread-2) [homeassistant.components.light.yeelight] Unable to update bulb status: Bulb closed the connection. 2017-08-22 19:22:07 WARNING (MainThread) [homeassistant.helpers.entity] Update of binary_sensor.motion_sensor_158d000155df00 is taking over 10 seconds 2017-08-22 19:22:07 ERROR (Thread-7) [PyXiaomiGateway] Cannot connect to Gateway 2017-08-22 19:22:07 ERROR (Thread-7) [PyXiaomiGateway] No data in response from hub None 2017-08-22 19:23:53 ERROR (Thread-6) [homeassistant.components.light.yeelight] Unable to update bulb status: A socket error occurred when sending the command. 2017-08-22 19:25:13 WARNING (MainThread) [homeassistant.helpers.entity] Update of binary_sensor.motion_sensor_158d000155df00 is taking over 10 seconds 2017-08-22 19:25:13 ERROR (Thread-11) [PyXiaomiGateway] Cannot connect to Gateway 2017-08-22 19:25:13 ERROR (Thread-11) [PyXiaomiGateway] No data in response from hub None 2017-08-22 19:26:15 WARNING (MainThread) [homeassistant.helpers.entity] Update of binary_sensor.motion_sensor_158d000155df00 is taking over 10 seconds 2017-08-22 19:26:15 ERROR (Thread-7) [PyXiaomiGateway] Cannot connect to Gateway 2017-08-22 19:26:15 ERROR (Thread-7) [PyXiaomiGateway] No data in response from hub None 2017-08-22 19:30:54 WARNING (MainThread) [homeassistant.helpers.entity] Update of binary_sensor.motion_sensor_158d000155df00 is taking over 10 seconds 2017-08-22 19:30:54 ERROR (Thread-3) [PyXiaomiGateway] Cannot connect to Gateway 2017-08-22 19:30:54 ERROR (Thread-3) [PyXiaomiGateway] No data in response from hub None 2017-08-22 19:32:27 WARNING (MainThread) [homeassistant.helpers.entity] Update of binary_sensor.motion_sensor_158d000155df00 is taking over 10 seconds 2017-08-22 19:32:27 ERROR (Thread-3) [PyXiaomiGateway] Cannot connect to Gateway 2017-08-22 19:32:27 ERROR (Thread-3) [PyXiaomiGateway] No data in response from hub None 2017-08-22 19:47:57 WARNING (MainThread) [homeassistant.helpers.entity] Update of binary_sensor.motion_sensor_158d000155df00 is taking over 10 seconds 2017-08-22 19:47:57 ERROR (Thread-3) [PyXiaomiGateway] Cannot connect to Gateway 2017-08-22 19:47:57 ERROR (Thread-3) [PyXiaomiGateway] No data in response from hub None 2017-08-22 19:54:40 WARNING (MainThread) [homeassistant.helpers.entity] Update of binary_sensor.motion_sensor_158d000155df00 is taking over 10 seconds 2017-08-22 19:54:40 ERROR (Thread-11) [PyXiaomiGateway] Cannot connect to Gateway 2017-08-22 19:54:40 ERROR (Thread-11) [PyXiaomiGateway] No data in response from hub None 2017-08-22 20:46:08 WARNING (MainThread) [homeassistant.helpers.entity] Update for light.lr_standing_lamp is already in progress 2017-08-22 20:50:55 WARNING (MainThread) [homeassistant.helpers.entity] Update of binary_sensor.motion_sensor_158d000155df00 is taking over 10 seconds 2017-08-22 20:50:55 ERROR (Thread-2) [PyXiaomiGateway] Cannot connect to Gateway 2017-08-22 20:50:55 ERROR (Thread-2) [PyXiaomiGateway] No data in response from hub None

Im wondering how do you install this? I am on raspberry pi 3 virtualenv.
thanks

Just put the xiaomiplug.py in your custom components folder.

This topic should be moved, it’s not a Third party integration anymore? or just create a new one and move on…

1 Like

Hi @sjee I am not sure where is the custom component folder? Is there a manual or official guide surrounding this? Thanks

As @syssi wrote you’re in the wrong topic. This is the one dailing with the wifi plug https://community.home-assistant.io/t/xiaomi-mi-wifi-plug-air-purifier

As for the custom component folder, it depends on you installation but it’s probably here:
/home/homeassistant/.homeassistant/custom_components

1 Like

Hi @sjee @syssi
Thanks but in my HASS instance, i cant find that folder custom_component.
Sorry if this is in the wrong thread/topic, I’ll ask on the other thread
Cheers

This is fine. Just create the custom_component folder. It should look like this:

$ find .homeassistant
.homeassistant
.homeassistant/custom_components
.homeassistant/custom_components/switch
.homeassistant/custom_components/switch/xiaomiplug.py
.homeassistant/.HA_VERSION
.homeassistant/home-assistant.log
.homeassistant/automations.yaml
.homeassistant/groups.yaml
.homeassistant/configuration.yaml
[...]

The configuration.yaml is a good orientation.