core: Wemo Light Switches show unavailable every few minutes
The problem
I have six Belkin Wemo devices, three outlet plugs and three regular light switches (not dimmable). The three outlet plugs and one light switch occasionally show unavailable in the logs, maybe once a day at most. The other two light switches toggle between available and unavailable every minute or two. One did not used to do this (ran fine for a week or more, the other one has been doing this for a while). I have an automation that sends me a push notification if one of these two lights gets left on for one hour. After the first time the automation ran and sent the push notification, the other light switch started behaving this way.
I’m running the latest version of Home Assistant Core (2021.1.5) on a Raspberry Pi I upgraded the Belkin products to the latest firmware versions I tried rebooting Home Assistant Core and the Light Switches I know the light switches are connected to WiFi and available as I’ve been able to turn them on/off with the Wemo App and Apple Home App while Home Assistant showed them as unavailable.
What is version of Home Assistant Core has the issue?
2021.1.5
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant OS
Integration causing the issue
Belkin Wemo
Link to integration documentation on our website
https://www.home-assistant.io/integrations/wemo/
Example YAML snippet
# Put your YAML below this line
Anything in the logs that might be useful for us?
# Put your logs below this line
2021-02-01 21:37:47 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Wemo for wemo
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 445, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 440, in _make_request
httplib_response = conn.getresponse()
File "/usr/local/lib/python3.8/http/client.py", line 1347, in getresponse
response.begin()
File "/usr/local/lib/python3.8/http/client.py", line 307, in begin
version, status, reason = self._read_status()
File "/usr/local/lib/python3.8/http/client.py", line 268, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/local/lib/python3.8/socket.py", line 669, in readinto
return self._sock.recv_into(b)
socket.timeout: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "/usr/local/lib/python3.8/site-packages/urllib3/util/retry.py", line 531, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/local/lib/python3.8/site-packages/urllib3/packages/six.py", line 735, in reraise
raise value
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 447, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 336, in _raise_timeout
raise ReadTimeoutError(
urllib3.exceptions.ReadTimeoutError: HTTPConnectionPool(host='192.168.1.135', port=49153): Read timed out. (read timeout=10)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 236, in async_setup
result = await component.async_setup_entry(hass, self) # type: ignore
File "/usr/src/homeassistant/homeassistant/components/wemo/__init__.py", line 129, in async_setup_entry
await wemo_discovery.async_discover_and_schedule()
File "/usr/src/homeassistant/homeassistant/components/wemo/__init__.py", line 197, in async_discover_and_schedule
for device in await self._hass.async_add_executor_job(
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.8/site-packages/pywemo/discovery.py", line 48, in discover_devices
device = device_from_description(
File "/usr/local/lib/python3.8/site-packages/pywemo/discovery.py", line 72, in device_from_description
return device_from_uuid_and_location(
File "/usr/local/lib/python3.8/site-packages/pywemo/discovery.py", line 91, in device_from_uuid_and_location
return LightSwitch(
File "/usr/local/lib/python3.8/site-packages/pywemo/ouimeaux_device/__init__.py", line 122, in __init__
service = Service(self, svc, base_url)
File "/usr/local/lib/python3.8/site-packages/pywemo/ouimeaux_device/api/service.py", line 115, in __init__
xml = requests.get(url, timeout=10)
File "/usr/local/lib/python3.8/site-packages/requests/api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 529, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPConnectionPool(host='192.168.1.135', port=49153): Read timed out. (read timeout=10)
2021-02-01 21:39:20 WARNING (MainThread) [homeassistant.components.wemo.entity] Lost connection to Basement Light Switch Right
2021-02-01 21:39:20 WARNING (MainThread) [homeassistant.components.wemo.entity] Lost connection to Basement Light Switch Left
2021-02-01 21:39:30 WARNING (MainThread) [homeassistant.components.wemo.entity] Lost connection to Basement Light Switch Left
2021-02-01 21:39:40 WARNING (MainThread) [homeassistant.components.wemo.entity] Lost connection to Basement Light Switch Right
2021-02-01 21:39:40 WARNING (MainThread) [homeassistant.components.wemo.entity] Lost connection to Basement Light Switch Left
2021-02-01 21:39:49 WARNING (SyncWorker_4) [pywemo.ouimeaux_device.api.service] Error communicating with Basement Light Switch Left at 192.168.1.183:49153, retry 0
2021-02-01 21:40:30 WARNING (MainThread) [homeassistant.components.wemo.entity] Lost connection to Basement Light Switch Right
2021-02-01 21:42:50 WARNING (MainThread) [homeassistant.components.wemo.entity] Lost connection to Basement Light Switch Right
2021-02-01 21:42:58 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 445, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 440, in _make_request
httplib_response = conn.getresponse()
File "/usr/local/lib/python3.8/http/client.py", line 1347, in getresponse
response.begin()
File "/usr/local/lib/python3.8/http/client.py", line 307, in begin
version, status, reason = self._read_status()
File "/usr/local/lib/python3.8/http/client.py", line 268, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/local/lib/python3.8/socket.py", line 669, in readinto
return self._sock.recv_into(b)
socket.timeout: timed out
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 25 (14 by maintainers)
65% packet loss — ya that’ll cause some issues! Great to hear that the other devices are much improved though
New graphs.
I still see plenty of times where the device shows as unavailable in HA. Even with the the timeouts set to 25/20 seconds.
And now it’s clearer that reconnect_to_device takes a while.
This matches with my experience that it can take a few minutes for devices to appear as available again. I’ll try to re-arrange things a bit in pywemo.
I’ll keep the Prometheus monitoring in place too, so we can see if these changes will have any impact.
It does both for most devices. Local push isn’t currently working for these situations:
Mine unstick themselves after a few minutes. I suspect the issue here is that pywemo is too aggressive when it comes to handling connection failures. Normally the poll is one small network request. However when the poll fails, there can be an additional 7+ larger network requests as pywemo attempts to re-discover and re-establish a connection. My theory is that all this extra network activity makes an already slightly bad connection worse.
I’ve added some extra debugging on my end to try to find the common cases where the poll fails. Once identified my plan is to try to retry the poll rather than doing the more aggressive re-discovery. I want to build up some baseline data first, to capture the size of the issue, before I make these changes. That way I can verify my changes are making things better and not worse 😃 It’ll take a few days to collect that baseline data. Then I can start working on some fixes.