@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.
- 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
Illumination
sensor still does not change the value, no matter we turn light or not.
Let’s addupdate
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)
- Next code is for light
./light/xiaomi_aquara.py
This might not needed, but it’s quick and dirty
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()
- Restart HA and wait 2.5 hours
- Check traffic by
ngrep
. You should seeread
andread_ack
every 30 sec.
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!!
`
i also ran into problems with my Aqara Gateway Light, it does exactly this behavior - light turn off after 2.5 hours repeatedly - im on Hassio 0.118, so do you have found a solution without reinstalling everything? I don’t have problems with the connected devices they work through this 2.5h interval but the gateway light turns unavailable…
Hello,
Did you ever found a solution to it. Or have a fresh install is the only way to go.
Thanks.
Sorry, i got rid of it in the end.
Resurecting an old thread, since this issue was still a PITB for me.
A fresh install of HA with the latest version as on the day, on Intel NUC didnt solve the problem for me. Not sure now what could be the issue, the Aqara Gateway and Light and connected Aqara cuve is detected on a reboot and works fine, however becomes unavailable after 2.5 hours. Not sure is it due to having two VLANs on my home network config, as other devices do interoperate well between the VLANs.
To make a similar solution like all other buggy integrations (which I read across in a number of threads in the community) , i resorted to the solution of restarting the integration whenever it becomes unavailable.
Have created the following automation and waiting it to be fired for the first time to prove its success. Maybe someone in a similar dilemma can find this useful
alias: Restart Xiaomi Aqara Gateway Integration
description: >-
Restart Xiaomi Aqara Gateway Integration after it becomes unavailable every
2.5 hours by checking light availability status
trigger:
- platform: state
entity_id:
- light.gateway_light_7811dcfabff2 (replace with your device entity ID)
to: unavailable
for:
hours: 0
minutes: 0
seconds: 3
condition: []
action:
- service: homeassistant.reload_config_entry
data:
entry_id: a40da9995a053550524cde628cb59fdd (replace with your GUID from config/.storage/core.config_entries)
mode: single
Use this thread to find the IDs for your devices.
Make sure you differentiate between device_ID, entry_ID and entity_ID as it was a bit confusing and overlapping for me at first.
The automation checks the entity ID of the aqara gateway light and if it becomes unavailable for 3 sec, it reloads the integration for entry_ID of the Aqara Gateway.
Hope it becomes useful.