core: Xiaomi gateway light - can't turn off, no colour
Running HA 0.85.1 on Docker on RPi 3, with --net-host (pretty default setup basically). Having a Xiaomi ‘Mi Hub’ lumi v3 gateway with a bunch of sensors attached and they work perfectly with the gateway and with HA, through the use of the LAN access feature, all the time. The config entry is fully manual:
xiaomi_aqara:
discovery_retry: 10
interface: LAN_ipaddress_RPi3
gateways:
- mac: xxx
host: LAN_ipaddress_Mi_Hub
key: yyy
The gateway light and illumination however, don’t work as expected at all.
- The switch of the gateway light in HA will move to turned off seconds after being turned on in HA, while the light itself actually did turn on and stays on.
- No color wheel for the gateway light.
- After 2,5 hours, HA gives up and with that also the illumination sensor values of the gateway are not processed anymore.
- Remember: all the time the other sensors work absolutely perfectly with both the Mi Hub and HA.
Debug data follows.
Turning on the light via HA:
DEBUG (SyncWorker_12) [xiaomi_gateway] _send_cmd >> b'{"cmd": "write", "sid": "(removed for privacy)", "data": {"rgb": 1694498815, "key": "(removed for privacy)"}}'
DEBUG (SyncWorker_12) [xiaomi_gateway] _send_cmd resp << {'cmd': 'write_ack', 'model': 'gateway', 'sid': '(removed for privacy)', 'short_id': 0, 'data': '{"rgb":1694498815,"illumination":1064,"proto_version":"1.1.2"}'}
DEBUG (SyncWorker_12) [xiaomi_gateway] write_ack << {'cmd': 'write_ack', 'model': 'gateway', 'sid': '(removed for privacy)', 'short_id': 0, 'data': '{"rgb":1694498815,"illumination":1064,"proto_version":"1.1.2"}'}
Not sure what “key” is. Not the gateway key. 34 characters, a-f, 1-9, maybe more numbers/letters possible.
Switching the light off (that was turned on in HA) via Mi Hub app:
DEBUG (Thread-2) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'gateway', 'sid': '(removed for privacy)', 'short_id': 0, 'data': '{"rgb":0,"illumination":1069}'}
DEBUG (Thread-2) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'gateway', 'sid': '(removed for privacy)', 'short_id': 0, 'data': '{"rgb":0,"illumination":996}'}
Switching the light on via Mi Hub app:
DEBUG (Thread-2) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'gateway', 'sid': '(removed for privacy)', 'short_id': 0, 'data': '{"rgb":1694498815,"illumination":769}'}
DEBUG (Thread-2) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'gateway', 'sid': '(removed for privacy)', 'short_id': 0, 'data': '{"rgb":1694498815,"illumination":769}'}
DEBUG (Thread-2) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'gateway', 'sid': '(removed for privacy)', 'short_id': 0, 'data': '{"rgb":1694498815,"illumination":800}'}
Switching the light off via Mi Hub app:
DEBUG (Thread-2) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'gateway', 'sid': '(removed for privacy)', 'short_id': 0, 'data': '{"rgb":0,"illumination":913}'}
DEBUG (Thread-2) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'gateway', 'sid': '(removed for privacy)', 'short_id': 0, 'data': '{"rgb":0,"illumination":869}'}
DEBUG (Thread-2) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'gateway', 'sid': '(removed for privacy)', 'short_id': 0, 'data': '{"rgb":0,"illumination":814}'}
Those MCAST reports always come in groups of 2-3.
Reporting this to my best knowledge and intentions. Please don’t close the report with a one-liner etc. In case suggestions are given I will test and report back.
Bug started as topic: https://community.home-assistant.io/t/xiaomi-gateway-light-unavailable-after-exactly-2-5-hours/89397
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 5
- Comments: 48 (11 by maintainers)
If the MAC address of your Xiaomi Gateway starts with ‘04’ please update HA to 0.88.2 because of: https://github.com/home-assistant/home-assistant/pull/21453 Some people here are affected. Some may be not.
I’ve posted fix here at community post.
I’ve checked it on 1.4.1_164.0158 firmware and HA 0.87.0. Should work on 0.87.1 My HA installation online 2 days+ and gateway light and sensor works as expected.
Find this code in the xiaomi_aquara component (
xiaomi_aquara.py) In myvenvit’s located here at/opt/homeassistant/lib/python3.6/site-packages/homeassistant/components/And change
FalsetoTrueIlluminationsensor still does not change the value, no matter we turn light or not. Let’s addupdatedef for sensor. File is nearby:./sensor/xiaomi_aquara.py./light/xiaomi_aquara.pyAdd this to
turn_onandturn_offdefs:Result should be like this:
ngrep. You should seereadandread_ackevery 30 sec.Also having the the issue whereby the gateway becomes unavailable, but the attached sensors keep functioning.
Issue: I can also turn on the gateway light via HA, but I cannot turn it off again via HA. Also after a second or so, the switch in HA reverts back to the off state. When I turn on the light via the Mi home app, the state in HA doesn’t change. This is on the NEW version (round text on the back) of the gateway. The firmware version is 1.4.1_164.0158. I have another gateway (with square text) and that one works fine (f/w 1.4.1_161.0143). I read on a forum (can’t remember which one) that if you have the NEW gateway and you enable LAN access before upgrading to the latest firmware and after it’s enabled upgrade the firmware, everything works as expected. Unfortunately, I don’t have another gateway to confirm that.
Troubleshooting: Reading a post on another forum (https://community.openhab.org/t/solved-openhab2-xiaomi-mi-gateway-does-not-respond/52963/113), I confirmed that udp port 9898 was closed. On my “old” working gateway, the port was open. I opened up the case and soldered the rx, tx and gnd wires to connect the gateway via serial interface. Following the instructions, I managed to open port 9898. Unfortunately, this did not fix the issue. The behavior is slightly different now though. I can still only turn on the light, but now the switch stays in the ‘on’ position in HA. After 2,5 hours the gateway still becomes unavailable again. After this, I tried:
Additional info: When still connected to the serial interface via Putty, I noticed that when I turn the gateway light on via HA, it registers the command ({“id”:52,“method”:“props”,“params”:{“rgb”:1694498815}}. But when I turn it off, no command registers in the terminal window. When I turn it on via the Mi Home app, it displays a different message “{“id”:56,“method”:“props”,“params”:{“light”:“on”,“from.light”:“4,”}}” When I turn it off in the MiHome app, it shows “{“id”:54,“method”:“props”,“params”:{“light”:“off”,“from.light”:“4,”}}”.