Xiaomi Gateway Integration

@rave I have found a way to reproduce the ghost issue! I manually sent the following message to the gateway (the id was valid, not 111):
{“cmd”:“read”,“sid”:111111111111}

Notice that “” is missing around the id! That caused the gateway to stop responding for about 5 seconds (no heartbeats), and after that the sensor was “open”! Could the component be sending an invalid message? I’m not on the latest code due to the following issue, so I may be delayed on fixes: https://github.com/lazcad/homeassistant/issues/28

1 Like

This is a community for an open source software. There are no obligation to response.

“do anyone know the answer?” looks so much better than “please respond, thanks”.

Anyway, read the Readme.md and you’ll know that gateway alarm is not a supported feature. That’s why i didn’t respond to your question.

2 Likes

Good finding. Did anything shows up in the error log? If HA sends something to gateway and it doesn’t respond in 10 seconds, it will log an error below

Cannot connect to Gateway

I’ll have to check the next time it happens and I’ll let you know.

So, tonight all sensors went into ghost mode. I’ve checked the logs and saw no timeouts or errors. I do see the heartbeats from the sensors with the “open” status. I don’t see any pooling message sent from HA to the gateway on the logs, is that normal? I have the following config on the logger, do I need anything else?

logger:
  default: warn
  logs:
    custom_components.xiaomi: debug
    custom_components.sensor.xiaomi: debug
    custom_components.binary_sensor.xiaomi: debug
    custom_components.light.xiaomi: debug
    custom_components.switch.xiaomi: debug

Anyway, I’ll try to use the latest version of the component to check if theres any difference.

Config looks fine. And polling is only for motion sensor. It could be network connection because i still haven’t experienced another ghost event. Maybe try another router if you have an extra sitting around?

I had the last 2 days unfortunately as well ghost openings and motions… its really annoying. It’s not necessarily connected with the wifi connection, i unplugged and replugged the gateway and the same happens directly. I can confirm that there is a heartbeat “open” status send from the gateway without a report before.

Does anywant knows why this happen? i would be very happy if you help me, i have the ip but i cant make this work. i only have xiaomi: in configuration

17-03-18 03:28:20 INFO (MainThread) [homeassistant.loader] Loaded xiaomi from custom_components.xiaomi

17-03-18 03:28:20 INFO (MainThread) [homeassistant.setup] Setting up xiaomi
17-03-18 03:28:20 WARNING (<concurrent.futures.thread.ThreadPoolExecutor object at 0x102ee7588>_9) [custom_components.xiaomi] Gateway Key is not provided. Controlling gateway device will not be possible.
17-03-18 03:28:20 INFO (<concurrent.futures.thread.ThreadPoolExecutor object at 0x102ee7588>_9) [custom_components.xiaomi] Expecting 1 gateways
17-03-18 03:28:20 INFO (<concurrent.futures.thread.ThreadPoolExecutor object at 0x102ee7588>_9) [custom_components.xiaomi] Discovering Xiaomi Gateways (Try 1)
17-03-18 03:28:25 INFO (<concurrent.futures.thread.ThreadPoolExecutor object at 0x102ee7588>_9) [custom_components.xiaomi] Gateway finding finished in 5 seconds
17-03-18 03:28:25 INFO (<concurrent.futures.thread.ThreadPoolExecutor object at 0x102ee7588>_9) [custom_components.xiaomi] Discovering Xiaomi Gateways (Try 2)
17-03-18 03:28:30 WARNING (MainThread) [homeassistant.setup] Setup of xiaomi is taking over 10 seconds.
17-03-18 03:28:30 INFO (<concurrent.futures.thread.ThreadPoolExecutor object at 0x102ee7588>_9) [custom_components.xiaomi] Gateway finding finished in 5 seconds
17-03-18 03:28:30 INFO (<concurrent.futures.thread.ThreadPoolExecutor object at 0x102ee7588>_9) [custom_components.xiaomi] Discovering Xiaomi Gateways (Try 3)
17-03-18 03:28:35 INFO (<concurrent.futures.thread.ThreadPoolExecutor object at 0x102ee7588>_9) [custom_components.xiaomi] Gateway finding finished in 5 seconds
17-03-18 03:28:35 ERROR (<concurrent.futures.thread.ThreadPoolExecutor object at 0x102ee7588>_9) [custom_components.xiaomi] No gateway discovered
17-03-18 03:28:35 ERROR (MainThread) [homeassistant.setup] Setup failed for xiaomi: Component failed to initialize.

I think I have found a workaround for the ghost problem. When I get an event from a sensor I connect to the hub for a confirmation. This result in a short delay (less than 1 sec) before an event is fired.

It seams to solve the ghost problem, but it would be great if other want to test it too.
You will find the code here: https://github.com/Danielhiversen/homeassistant Add check_ghost to the config

xiaomi:
 check_ghost: True
 gateways:
   - sid:
     key: XXXXXXXXXXXXx

@DuckY1987 @abmantis

1 Like

wow, that’s great news! I updated my component already, lets see if its working, that would be awesome, i think 1 second delay is acceptable, anyway since i updated to 0.40 i have quite a delay in hass itself till my light automations are taking effect.

do you have the interface option in your component, i had troubles without, or is it solved with multiple interfaces?

my config looks like:

check_ghost: true
gateways:
  - sid: xxxxx
    key: !secret xiaomi_key
interface: xxx.xxx.xxx.xxx

Check_ghost is an invalid option after i updated the custom_comp with your version.

17-03-18 20:46:34 ERROR (MainThread) [homeassistant.config] Invalid config for [xiaomi]: [check_ghost] is an invalid option for [xiaomi]. Check: xiaomi->xiaomi->check_ghost. (See /root/.homeassistant/configuration.yaml, line 280). Please check the docs at https://home-assistant.io/components/xiaomi/

it doesn’t seems to be included in your master, is the code included in some branch?

Sorry, had forgotten to push the changes to the public repo. Fixed now.

@rave Many thanks for your component. It works like a charm.

I’ve bought the cube switch from Xiaomi. I want to activate an automation when I rotate the cube. The cube send value like “rotate: 12.500” with positive or negative values depending on the direction.
I have no idea how to retrieve the rotate value.

I want use this like a dimmer for the light.

Maybe someone knows how I could set it up ?

Here is how I do it https://github.com/Danielhiversen/home-assistant_config/blob/master/automation/audio.yaml#L214

Awesome ! I could not think it would be so fast ! :smiley_cat:

Thank you !

Hey Daniel,

great it worked, i will let you know my experience. Thanks a lot in advance if it works! :wink: I was already worried, that i can dump my 25 devices from xiaomi because they are not reliable enough.

Hmm… since i use your code i have plenty of:

17-03-19 23:59:41 ERROR (Thread-3) [custom_components.xiaomi] Cannot connect to Gateway
17-03-19 23:59:41 ERROR (Thread-3) [custom_components.xiaomi] No data in response from hub None
17-03-20 00:02:06 ERROR (Thread-7) [custom_components.xiaomi] Cannot connect to Gateway
17-03-20 00:02:06 ERROR (Thread-7) [custom_components.xiaomi] No data in response from hub None
17-03-20 00:03:39 ERROR (Thread-3) [custom_components.xiaomi] Cannot connect to Gateway
17-03-20 00:03:39 ERROR (Thread-3) [custom_components.xiaomi] No data in response from hub None

in my log, seems to be that the connection fails sometimes when the comp ask for confirmation, the result is no movement detected.

I read on this page (well google translated version) that newest version of API supports now the gateway sensor and gateway audio:

https://lunarok-domotique.com/2017/03/mi-smart-gateway-domotique-jeedom/

Translated: “But it has caught up well: we have the sounds of the gateway and the brightness sensor as a bonus.”

1 Like

I’ve tested it and I think this works! I was having my sensors permanently in “motion” and “open” state after a power cut and this fixed it!

I also saw that domoticz has implementation for the Xiaomi hub and I don’t see anyone there complaining about ghost openings. I think what they are doing is to rely only on the broadcast without polling (i.e. cmd: “read”) the gateway.

I also reported this API bug to Xiaomi but the response I got was that they can’t understand the issue :slight_smile: I think any bug reports should be submitted in chinese to get this up the chain and this API bug resolved.