Xiaomi devices do not update their states in HA

Hello,

For few weeks I’m having problems with Xiaomi devices like Door Window Sensor, Motion Sensor, Gateway Light. I’ve tried to find a solution for it, but without success.

All these devices load their initial state when I launch HA and then they do not update. I do not see any motion, or opened doors in the history of these devices in HA but in Mi Home everything works. I have automations notify.pushbullet when there is movement or doors open and I do not get anything, I have same notifications in Mi Home app and all works, I get everything.
When I manually change the state in HA I get pushbullet notfications.

Some additional comments…
In first days my HA adventure all devices worked correctly, then I added automations and maybe some another stuff and after one or two days I got this…
I thought that when I create new HA from scratch it will work, but I doesn’t work, I had a fresh environment with just xiaomi_aqara and states are the same all the time, also checked automations - don’t work.
I tried with new key from xiaomi_aqara also no success.
I’m using virtualbox, ubuntu 16.04.

I’ve seen an issue related to timeing out xiaomi devices but it is not about this, however I experience that too.

Has anyone of you HA users experienced same problems with Xiaomi devices? I’m building HA on Xiaomi so it’s important for me to have it working all the time.

2 Likes

I have seen the same thing for myself

I think I probably found something in the logs… please could you help me with this?

First thing:

JSON file not found: /usr/local/lib/python3.6/site-packages/homeassistant/components/binary_sensor/.translations/xiaomi_aqara.pl.json

second, is this… the 14charkey is from wall swtich which works fine, so not sure why it’s invalid.:

2018-10-08 14:08:18 DEBUG (SyncWorker_0) [xiaomi_gateway] _send_cmd >> b'{"cmd": "write", "sid": "14charkey", "data": {"channel_0": "on", "key": "32charkey"}}'
2018-10-08 14:08:18 DEBUG (SyncWorker_0) [xiaomi_gateway] _send_cmd resp << {'cmd': 'write_ack', 'sid': '14charkey', 'data': '{"error":"Invalid key"}'}
2018-10-08 14:08:18 DEBUG (SyncWorker_0) [xiaomi_gateway] write_ack << {'cmd': 'write_ack', 'sid': '14charkey', 'data': '{"error":"Invalid key"}'}
2018-10-08 14:08:18 ERROR (SyncWorker_0) [xiaomi_gateway] Got error element in data {"error":"Invalid key"}

third tihng is that when I turn on the aqara wall switch I can see this, and it works fine in HA:

2018-10-08 14:08:17 DEBUG (MainThread) [homeassistant.components.websocket_api] WS 140149458514104: Received {'type': 'call_service', 'domain': 'switch', 'service': 'turn_on', 'service_data': {'entity_id': 'switch.wall_switch_14charkey'}, 'id': 14}
2018-10-08 14:08:17 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=switch, service=turn_on, service_data=entity_id=switch.wall_switch_14charkey, service_call_id=32charkey>

when I turn on xiaomi gateway light, the switch in HA go to right side but in second it goes back to grey, however the light is on, and I cannot turn it off in HA, only in Mi Home app. The log is:

2018-10-08 14:08:39 DEBUG (MainThread) [homeassistant.components.websocket_api] WS 140149458514104: Received {'type': 'call_service', 'domain': 'light', 'service': 'turn_on', 'service_data': {'entity_id': 'light.gateway_light_12charkey'}, 'id': 16}
2018-10-08 14:08:39 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=light, service=turn_on, service_data=entity_id=light.gateway_light_12charkey, service_call_id=32charkey>
2018-10-08 14:08:39 DEBUG (SyncWorker_4) [xiaomi_gateway] _send_cmd >> b'{"cmd": "write", "sid": "12charkey", "data": {"rgb": 1694498815, "key": "32charkey"}}'
2018-10-08 14:08:39 DEBUG (SyncWorker_4) [xiaomi_gateway] _send_cmd resp << {'cmd': 'write_ack', 'model': 'gateway', 'sid': '12charkey', 'short_id': 0, 'data': '{"rgb":1694498815,"illumination":1292,"proto_version":"1.1.2"}'}
2018-10-08 14:08:39 DEBUG (SyncWorker_4) [xiaomi_gateway] write_ack << {'cmd': 'write_ack', 'model': 'gateway', 'sid': '12charkey', 'short_id': 0, 'data': '{"rgb":1694498815,"illumination":1292,"proto_version":"1.1.2"}'}

and this:

2018-10-08 13:52:26 DEBUG (SyncWorker_1) [homeassistant.util.json] JSON file not found: /config/.storage/core.device_registry
2018-10-08 13:52:32 DEBUG (SyncWorker_0) [homeassistant.util.json] JSON file not found: /config/.storage/cloud
2018-10-08 13:55:29 DEBUG (SyncWorker_1) [homeassistant.util.json] JSON file not found: /config/.storage/auth_module.totp

Hi @canibalo,

I’ve got the same issue, it drives me crazy. By any chance, have you figured a solution out ?

I’m running HA in a Synology Docker. It was running perfectly for several days, until I changed my IP topology (replaced my old Cisco router by a Synology rt2600ac, which also changed the IP range from 192.168.1.x to 10.0.4.x). I suspect this came from that, but not sure though…

I tried a few actions (re-generate the key from the Xiaomi GW, cleaned the HA /config folder, …). After the router change, I had to manually add the host and MAC address in the configuration.yaml file, otherwise I got a ‘gateway not found’ in the logs (even if the key was correct and on the same subnet).

The only thing I didn’t test (yet, but I want your feedback first), is to factory reset the Xiaomi GW and start the integration all over again…

@njambe I unfortunately have not fixed the problem, however I am doing fine now…

Initially I was playing on VM on my computer using different options to run the HA, but when I installed HA hass.io on my precious RP, all problems gone and now for more than 4 weeks all is good.

I’m sorry but I don’t think I can help you, but I suspect your new router… :thinking:

@canibalo Damn, I knew it was too easy…

Have you reset the Xiaomi GW in the way ?

Not really a fix but I resolved by rebuilding on Hassio

FYI: 0.83 changed the syntax of the calls to the devices which bit my automations on the rear:

Was: event_type: click
Now is: event_type: xiaomi_aqara.click

trigger:
- platform: event
  event_type: xiaomi_aqara.click
  event_data:
    entity_id: binary_sensor.switch_158d00020eb750
    click_type: single

@njambe Nope I did not.

I’ve removed it from Mi Home only I think, and then added again, but this action did not remove any of the sensor linked to gateway, so it’s wasn’t a reset I think… :thinking:

@AlphaJosh unfortunately our problem is a bit different and more complicated…

@canibalo

Tried several things, like

  • disconnect the GW from the WiFi and app and re-pair it
  • changed every possible setting in the router
  • shout at it and cry

but nothing helped. So I followed your path and put it on the Raspberry Pi. It’s way slower than on the Syno, but IT WORKS !

Maybe it’s a problem on the link between physical and Docker interfaces, probably due to the changes made on the network. I won’t investigate… :slight_smile:

Thanks for the advice !

Read my thread: I hope this helps you guys. Let me know if it did or didn’t
https://community.home-assistant.io/t/binary-sensor-problem/

@njambe happy to hear that I helped someone even if I’m a noob! :sweat_smile:

I also gave up, and just happy like hell that it works now :sunglasses:

@StimpyMGS no, it’s not the same problem. Unfortunately I don’t know how to do that… maybe it’s saved on that usg stick that you have to use for zigbee2mqtt? I have it too but had no time to add any sensor to it, yet. Try on discord maybe.