Xiaomi gateway light unavailable after exactly 2,5 hours (Solved)

@h4xxx did you solve it? i have same problem.

@h4xxx @Rodolfo_Vieira

I opened a bug report. It would help if you also post there that you have this same issue.

I have now updated your bug thread. It seems we are running pretty different setups as I use hass.io primarily and have set up a windows based python-virtual evnvironment home assitant installation for debugging of this issue and both suffered the same issue. We also have different gateway firmware version but the very same gateway hardware - which seems to be the common theme.

What is your gateway HW @Rodolfo_Vieira?

@h4xxx i use hass.io , my fw is 1.4.1_164 and hw_ver is MW300 model lumi.gateway v3

@Saturnus added to your created issue on github too…

So, I think this quick and dirty fix will help. I’ve checked it on 1.4.1_164.0158 firmware and HA 0.87.0

Don’t forget to backup files!
Right now I have no other xiaomi sensors, so can’t check. But I hope they should work as usual.

  1. Enable polling.

Find this code in the xiaomi_aquara component (xiaomi_aquara.py)
In my venv it’s located here at /opt/homeassistant/lib/python3.6/site-packages/homeassistant/components/

    @property
    def should_poll(self):
        """Return the polling state. No polling needed."""
        return False

And change False to True

    @property
    def should_poll(self):
        """Return the polling state. No polling needed."""
        return True
  1. Illumination sensor still does not change the value, no matter we turn light or not.
    Let’s add update def for sensor.
    File is nearby: ./sensor/xiaomi_aquara.py
    def update(self):
        """Get data from hub."""
        _LOGGER.debug("Update data from hub: %s", self._name)
        self._get_from_hub(self._sid)
  1. Next code is for light ./light/xiaomi_aquara.py

This might not needed, but it’s quick and dirty :slight_smile:

Add this to turn_on and turn_off defs:

self.schedule_update_ha_state()

Result should be like this:

    def turn_on(self, **kwargs):
        """Turn the light on."""
        if ATTR_HS_COLOR in kwargs:
            self._hs = kwargs[ATTR_HS_COLOR]

        if ATTR_BRIGHTNESS in kwargs:
            self._brightness = int(100 * kwargs[ATTR_BRIGHTNESS] / 255)

        rgb = color_util.color_hs_to_RGB(*self._hs)
        rgba = (self._brightness,) + rgb
        rgbhex = binascii.hexlify(struct.pack('BBBB', *rgba)).decode("ASCII")
        rgbhex = int(rgbhex, 16)

        if self._write_to_hub(self._sid, **{self._data_key: rgbhex}):
            self._state = True
            self.schedule_update_ha_state()

    def turn_off(self, **kwargs):
        """Turn the light off."""
        if self._write_to_hub(self._sid, **{self._data_key: 0}):
            self._state = False
            self.schedule_update_ha_state()
  1. Restart HA and wait 2.5 hours :slight_smile:
  2. Check traffic by ngrep. You should see read and read_ack every 30 sec.
3 Likes

It is weird that I need to enable multicast_snooping under my merlin router setting then I can see package to reach the host of the container. However, the multicast package does not pass to the container and the value of /sys/devices/virtual/net/docker0/bridge/multicast_snooping is always 1. I changed it to 0 and reboot and it turns back to 1. So I cannot test if it really work if disabling snooping under the host really works. I am using debain + docker + hass.io setting, are there any means to correct the multicast_snooping setting under the host? thank you.

Hi! I have the same problem on hassio installed on raspberry pi3b+… could you explain me where can I find this file?
Thanks a lot!

Another fix has been posted by @sonartribe at https://github.com/home-assistant/home-assistant/issues/20329#issuecomment-466821849

Very likely that it’s going to be in a new HA version coming the next weeks.

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 solved my problem by opening port in firewall

Which port are we talking about here? Thanks
Right now I am using latest firmware 1.4.1_167_0158, HA on Dockers 0.91.4, gateway light still same issue.

9898

My solution was this:
In configuration.yaml:
change:

xiaomi_aqara:
  discovery_retry: 5
  gateways:
    - key: xxxxxxxxxxxxxxxx

to:

xiaomi_aqara:
  discovery_retry: 99999
  gateways:
    - key: xxxxxxxxxxxxxxxx

Had no disconnects now for more than 24 hours.

I don’t get why open port is a solution.
Home assistant and xiaomi gateway are in the same lan, so firewall is ineffective.

Hi, after days of investigation, I found a solution. But it depend by my installation.
I’m using Hass.io with a virtual machine on vmware and before I had a nat lan in the configuration of the virtual machine. I opened the port in the nat settings of vmware, but probably there’s some limitation. When I changed to bridged lan, xiaomi gateway started to work, since all the traffic passed through my real router.
Hope it helps.

hi,
i still have this problem.
any update about it ?

Hi, I have been working on trying to get my Xiaomi sensor to stop showing unavailable. I had to abandon the Xiaomi bridge as it just stopped working after a firmware update. Before the update, the bridge was in the middle of the house, and I had no problem to view the sensor in the app or Hassio. I bought the Nortek Zigbee HUSBZB-1 device and loaded the sensor, they stopped working after a while, always said “unavailable.” I thought I had issues with the network and bought some Ge Zigbee switches, as I thought they would function as a repeater. The Ge switches did not work, and I gave up for a while. I changed out batteries, and that seems to work for about an hour, then again the “unavailable.”

Then, I had to move my Hassio setup to an area that was less than 15 feet from my Nortek Zigbee HUSBZB-1 sensor to a temp sensor. I replaced the batteries on the temp and water sensor, and for a week, I have not lost connections. So I concluded, I need better repeaters, but which ones. I found a write up from a blog post on Hubitant site about network issues affect these sensors and the recommended repeaters. I bout the 4 Ikea switches and two repeaters and scattered them across the house. I replaced some Sonoff device and replaced them with these, so far it is all working. I will let you know in a week if I get the evil “unavailable.”

Are you sure you don’t have WiFi interferences?
What channel do you use for WiFi and for zigbee?
I had issues like yours and it was channel overlapping

`
Since about 2 weeks i have the same problem. My xiaomi sensors (aqara / mi) after 2.5 hours seems to become unavailable but I see that they don’t work immediately.
I checked several things:

  • wifi / zigbee interference
  • multicast forwarding
  • device batteries
  • firmware versions and software version
  • configuration of the xiaomi_aquara component in home assistant
  • gateway xiaomi and my 11 device

and everything was ok.
With the idea of ​​having to wait for a firmware or HA update, I started a new and clean home assistant on another container docker with only the configuration of the xiaomi gateway and VOILA , device works perfectly!!!
Now I have to find out what to do in the home assistant production installation without having to reinstall everything!!
`