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
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 !
Thank you !
Hey Daniel,
great it worked, i will let you know my experience. Thanks a lot in advance if it works! 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.”
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 I think any bug reports should be submitted in chinese to get this up the chain and this API bug resolved.
How did you fix the problem with the constantly working sensor?
The smoke and gas alarms are available for pre-order @ gearbest.
Currently smoke is £32 ($40)
http://www.gearbest.com/alarm-systems/pp_615081.html
And Gas is £40 (~$50)
http://www.gearbest.com/alarm-systems/pp_615080.html?wid=21
I’ve not yet tried @Danielhiversen code, but when my sensors went ghost mode, sending a “read” command would return with a “motion” message, so I don’t think that would fix the issue, but I may be wrong.
Relying only on the broadcast could indeed be a way around the issue. We could ignore the heartbeats which are the main issue here. But that would make it easier to miss states I guess.