core icon indicating copy to clipboard operation
core copied to clipboard

Shelly Gen1 DeviceConnectionError - HTTP Connect call failed

Open Zahnweh opened this issue 2 years ago • 13 comments

The problem

After restarting HA some Shelly devices appear sporadically unconnected. All devices types are affected, be it Shelly1 oder 2.5. What helps is to force them to reconnect (yes, they are already connected and can be pinged via terminal) them to my wifi (in my Unifi controller add-on) and reload the integration afterwards. As this affects all device types and after every particular restart of HA different devices appear unconnected I am putting it down to an issue with the integration. I cannot say exactly when the issue occurred first but what I am sure about is that it started during the 2022.12 cycle.

Logger: homeassistant.components.websocket_api.http.connection
Source: components/shelly/entity.py:349 
Integration: Home Assistant WebSocket API (documentation, issues) 
First occurred: 08:25:54 (11 occurrences) 
Last logged: 09:02:11

[547177164672] Setting state for entity Rollo Wohnzimmer failed, state: {'go': 'open'}, error: DeviceConnectionError()
[547177164672] Setting state for entity Rollo Küche failed, state: {'go': 'to_pos', 'roller_pos': 100}, error: DeviceConnectionError()
[547177164672] Setting state for entity Rollo Schlafzimmer failed, state: {'go': 'open'}, error: DeviceConnectionError()
[547177164672] Setting state for entity Rollo Bad failed, state: {'go': 'open'}, error: DeviceConnectionError()
[547559197904] Setting state for entity Lenes Rollo failed, state: {'go': 'open'}, error: DeviceConnectionError()
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 986, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore[return-value]  # noqa
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1064, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1049, in create_connection
    sock = await self._connect_sock(
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 960, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 500, in sock_connect
    return await fut
  File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 535, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
OSError: [Errno 113] Connect call failed ('192.168.0.84', 80)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioshelly/block_device.py", line 259, in http_request
    resp: ClientResponse = await self.aiohttp_session.request(
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 535, in _request
    conn = await self._connector.connect(
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 542, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 907, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 1206, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 1175, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 992, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host 192.168.0.84:80 ssl:default [Connect call failed ('192.168.0.84', 80)]

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/shelly/entity.py", line 346, in set_state
    return await self.block.set_state(**kwargs)
  File "/usr/local/lib/python3.10/site-packages/aioshelly/block_device.py", line 481, in set_state
    return await self.device.http_request(
  File "/usr/local/lib/python3.10/site-packages/aioshelly/block_device.py", line 276, in http_request
    raise DeviceConnectionError from err
aioshelly.exceptions.DeviceConnectionError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 200, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1745, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1782, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 678, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 943, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 715, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/shelly/cover.py", line 123, in async_open_cover
    self.control_result = await self.set_state(go="open")
  File "/usr/src/homeassistant/homeassistant/components/shelly/entity.py", line 349, in set_state
    raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: Setting state for entity Rollo Küche failed, state: {'go': 'open'}, error: DeviceConnectionError()

What version of Home Assistant Core has the issue?

2022.12.8

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

Shelly

Link to integration documentation on our website

https://www.home-assistant.io/integrations/shelly/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

Zahnweh avatar Jan 03 '23 09:01 Zahnweh

Hey there @balloob, @bieniu, @thecode, @chemelli74, @bdraco, mind taking a look at this issue as it has been labeled with an integration (shelly) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of shelly can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Change the title of the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign shelly Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


shelly documentation shelly source (message by IssueLinks)

home-assistant[bot] avatar Jan 03 '23 09:01 home-assistant[bot]

I had a similar issue today, also using Unifi as you already noted the only way to resolve it is to force the devices to reconnect to the WIFI (I just rebooted the device). The local device web page was also not reachable during that time (although it might be confusing since it sometime works for a few seconds) so this is not a problem with the Shelly integration. The error you show above (same as I had) is received in OS level, so unless the IP of the device is incorrect we can't do anything about it.

thecode avatar Jan 03 '23 10:01 thecode

Since Update to HA 2023.1 all of my 2nd gen Shelly are no longer available in HA.

Here is one error:

`Logger: homeassistant.config_entries Source: components/shelly/init.py:274 First occurred: 06:51:44 (2 occurrences) Last logged: 06:51:44

Error setting up entry Shelly-Router for shelly Error setting up entry Außensteckdose Garage for shelly Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/aioshelly/common.py", line 74, in get_info async with aiohttp_session.get( File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 1138, in aenter self._resp = await self._coro File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 466, in _request with timer: File "/usr/local/lib/python3.10/site-packages/aiohttp/helpers.py", line 721, in exit raise asyncio.TimeoutError from None asyncio.exceptions.TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/aioshelly/rpc_device/device.py", line 136, in initialize self.shelly = await get_info(self.aiohttp_session, self.options.ip_address) File "/usr/local/lib/python3.10/site-packages/aioshelly/common.py", line 83, in get_info raise error from err aioshelly.exceptions.DeviceConnectionError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 382, in async_setup result = await component.async_setup_entry(hass, self) File "/usr/src/homeassistant/homeassistant/components/shelly/init.py", line 112, in async_setup_entry return await _async_setup_rpc_entry(hass, entry) File "/usr/src/homeassistant/homeassistant/components/shelly/init.py", line 274, in _async_setup_rpc_entry await device.initialize() File "/usr/local/lib/python3.10/site-packages/aioshelly/rpc_device/device.py", line 169, in initialize await self._disconnect_websocket() File "/usr/local/lib/python3.10/site-packages/aioshelly/rpc_device/device.py", line 190, in _disconnect_websocket self._unsub_ws() File "/usr/local/lib/python3.10/site-packages/aioshelly/rpc_device/wsrpc.py", line 447, in return lambda: self.subscriptions.pop(ip) KeyError: '192.168.33.1' ` The Devices are still connected to WLAN and i can access them via the Web UI

This warning appears also**

`Logger: homeassistant.config_entries Source: config_entries.py:1133 First occurred: 06:53:03 (5 occurrences) Last logged: 08:56:22

Config entry 'Außensteckdose Waschraum' for shelly integration not ready yet: DeviceConnectionError(DeviceConnectionError(TimeoutError())); Retrying in background`

smartmatic avatar Jan 05 '23 08:01 smartmatic

This error pops also up in the log

`Logger: homeassistant Source: components/shelly/bluetooth/init.py:54 First occurred: 07:00:33 (1 occurrences) Last logged: 07:00:33

Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/aioshelly/rpc_device/device.py", line 275, in call_rpc return await self._wsrpc.call(method, params) File "/usr/local/lib/python3.10/site-packages/aioshelly/rpc_device/wsrpc.py", line 347, in call resp = await self._rpc_call(method, params, timeout) File "/usr/local/lib/python3.10/site-packages/aioshelly/rpc_device/wsrpc.py", line 379, in _rpc_call resp: dict[str, Any] = await call.resolve aioshelly.exceptions.DeviceConnectionError: <aioshelly.rpc_device.wsrpc.RPCCall object at 0x7f95e90f10>

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/shelly/coordinator.py", line 405, in _async_update_listener await self._async_run_connected_events() File "/usr/src/homeassistant/homeassistant/components/shelly/coordinator.py", line 512, in _async_run_connected_events await self._async_connect_ble_scanner() File "/usr/src/homeassistant/homeassistant/components/shelly/coordinator.py", line 535, in _async_connect_ble_scanner await async_connect_scanner(self.hass, self, ble_scanner_mode) File "/usr/src/homeassistant/homeassistant/components/shelly/bluetooth/init.py", line 54, in async_connect_scanner await async_start_scanner( File "/usr/local/lib/python3.10/site-packages/aioshelly/ble/init.py", line 83, in async_start_scanner await device.script_start(ble_script_id) File "/usr/local/lib/python3.10/site-packages/aioshelly/rpc_device/device.py", line 239, in script_start await self.call_rpc("Script.Start", {"id": script_id}) File "/usr/local/lib/python3.10/site-packages/aioshelly/rpc_device/device.py", line 281, in call_rpc raise DeviceConnectionError from err aioshelly.exceptions.DeviceConnectionError `

smartmatic avatar Jan 05 '23 08:01 smartmatic

Since Update to HA 2023.1 all of my 2nd gen Shelly are no longer available in HA.

@smartmatic please create a new issue, this is not the same issue. Thanks 👍

thecode avatar Jan 05 '23 08:01 thecode

I started having the exact same issue. I am using Unifi as well! Did anyone here find a solution? This is quite annoying since I have many Shelly 2.5 devices, rendering my setup useless :(

Winor avatar Mar 21 '23 23:03 Winor

At least for me it seems to be resolved with one of the Unifi firmware updates. Can't guarantee that it is 100% solved since also disconnected one of the APs but the frequency of the error is very low now.

thecode avatar Jun 25 '23 17:06 thecode

I am still having this issue from time to time, I have no clue on what triggers it, but it happens sometimes. I did read somewhere that changing the 2.4 network channel width to 40MHz make it happen less often, and I can confirm that this is the case, at least for me. However, I think this is not an issue with HA but with Shelly or Unify, probably. This all only started happening here after I introduced a new U6-Lite device to the network, so I wonder if it is somehow related...

Edit: I'm considering either to flash Esphome on my Shellys or just getting another device because this can be quite annoying

Winor avatar Jun 26 '23 11:06 Winor

I am still having this issue from time to time, I have no clue on what triggers it, but it happens sometimes. I did read happening here after I introduced a new U6-Lite device to the network, so I wonder if it is somehow related...

Since someone woke this issue, I had issues with U6-Lite myself, for few months I don't have any problems, one of the U6 firmware upgrades resolved the issue or maybe something I changed in the config.

thecode avatar Aug 21 '23 09:08 thecode

I have the same problem. Even with the new Shelly firmware 2.2.1 it still happens. I guess this issue isn't related to Home Assistant, it also happens if you just try to ping the devices. It got a little better but a lot of calls still get lost. I guess it's origin is because of the sleeping behavior of this devices.

gatonero avatar Oct 29 '23 07:10 gatonero

Another Unifi user here, and also was able to reproduce this occasionally. The Shelly’s are connected just fine according to the console, but stop letting me or HA access them over the network. restarted my Unifi console and everything is back to normal. So my hunch is that the dream machine or the network app is the issue here…

jonathanlang avatar Jan 14 '24 23:01 jonathanlang

As the general consensus is that the issue is linked to the network and not to HA, I'm going to close this issue. Once network connection between Shelly and AP is stable, if there are still problems with HA please feel free to open a new issue here.

chemelli74 avatar Feb 04 '24 12:02 chemelli74