home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
74.04k stars 31.07k forks source link

Shelly: Repetitive DeviceConnectionError errors #114270

Closed Friedrieck closed 7 months ago

Friedrieck commented 8 months ago

The problem

A few weeks ago, I decided to move from HACS' Shelly4Hass to the core Shelly integration. Since then, my Shelly devices are not reliable anymore. They sometimes work, sometimes not. When they don't, the Shelly Android app controls them fine and the related device_trackers are at_home in HA. I have followed all instructions I could find: all devices' firmware are up-to-date; CoIoT/unicast set for the old ones, WS for the most recent; static IPs in the app, reserved IPs in my router's DHCP; AP roaming activated... Please help. It's really annoying not being able to rely on these devices anymore.

What version of Home Assistant Core has the issue?

core-2024.3.3

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

Some sample diag files config_entry-shelly-1be5f26e22cf196438da65a8571b14f2-couv.json config_entry-shelly-3a3a067d2bb109b6b3bca3d35070000c-portail.json

Debug log file: home-assistant_shelly_2024-03-26T19-45-14.937Z.log

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Example failed call (in attached debug log file):
2024-03-26 20:43:38.695 DEBUG (MainThread) [aioshelly.block_device.device] host 192.168.178.82: http request retry error: DeviceConnectionError(TimeoutError())
2024-03-26 20:43:38.695 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [281471539194176] Setting state for entity Portail failed, state: {'turn': 'off'}, error: DeviceConnectionError()
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aioshelly/block_device/device.py", line 296, in http_request
    resp: ClientResponse = await self.aiohttp_session.request(
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 504, in _request
    with timer:
  File "/usr/local/lib/python3.12/site-packages/aiohttp/helpers.py", line 735, in __exit__
    raise asyncio.TimeoutError from None
TimeoutError

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 343, in set_state
    return await self.block.set_state(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aioshelly/block_device/device.py", line 526, in set_state
    return await self.device.http_request(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aioshelly/block_device/device.py", line 315, in http_request
    return await self.http_request(method, path, params, retry=False)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aioshelly/block_device/device.py", line 320, 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 239, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2319, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2356, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 905, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 975, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 639, in async_handle_light_off_service
    await light.async_turn_off(**filter_turn_off_params(light, params))
  File "/usr/src/homeassistant/homeassistant/components/switch_as_x/entity.py", line 165, in async_turn_off
    await self.hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 2319, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2356, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 905, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 975, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/shelly/switch.py", line 272, in async_turn_off
    self.control_result = await self.set_state(turn="off")
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/shelly/entity.py", line 346, in set_state
    raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: Setting state for entity Portail failed, state: {'turn': 'off'}, error: DeviceConnectionError()

Additional information

No response

home-assistant[bot] commented 8 months ago

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` Renames 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. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


shelly documentation shelly source (message by IssueLinks)

thecode commented 8 months ago

Please only Setup websocket for Shelly battery operated devices (Shelly Plus HT for example). You should not setup websocket for other Shelly Gen2/3 devices as it will cause problems (although this is not the problem you are experiencing.

The logs shows that Gen1 devices and are setup correctly. There are many errors related to custom component nuki_ng, please first disable it, if possible disable all custom components and check if you still have errors.

The errors that you show are not direct problem of Shelly integration, they are reported by it since we timeout sending a command to the device. I understand that you can control the devices from Shelly App, but this not passing through HA and your HA can't reach the devices.

Can you add information how your Home Assistant server is connected to the network? WiFi, wired? What type of APs/router you have?

bocsteganau commented 8 months ago

I have just swapped out my HA installation from a Pi3 to a Pi4 and since the transfer i am having a similar issue, Shelly Device Push update error. I have checked and refreshed the CoIoT peer settings a number of times. I'm on the same IP address as before. Strange thing is i can still control my shelly devices from HA??

chemelli74 commented 8 months ago

Did you reboot the device after modifying CoIoT ? If push doesn't work then the integration switch to polling and this is why it still works but it's not realtime

thecode commented 8 months ago

@bocsteganau please create a new issue, make sure to follow the docs before and add diagnostics from the device card in HA.

Friedrieck commented 8 months ago

Thanks for your response.

Can you add information how your Home Assistant server is connected to the network? WiFi, wired? What type of APs/router you have?

I use a Home Assistant Blue / Hardkernel ODROID-N2, wired directly to the FritzBox router. WiFi is otherwise extended with several repeaters of the same brand.

Sorry to repeat it, maybe a coincidence, but I never had these problems when using Shelly4Hass.

For the custom integrations, I'll have to find a time slot to test that (disabling them is quite impacting).

endrju666 commented 7 months ago

I have same problem. My log is also full of Error fetching data: DeviceConnectionError() I don't have a nuki_ng so it will be something else. Right now I am on core-2024.4.0 but the problem is same through multiple versions back. The Shelly is fully accessible via IP all the time, so there is some problem between Shelly and HA. It's extremely unreliable, almost unusable.

thecode commented 7 months ago

I have same problem. My log is also full of Error fetching data: DeviceConnectionError()

@endrju666 this is a different issue, please create a new issue and add diagnostics and logs.

Friedrieck commented 7 months ago

this is a different issue

Are you sure? I have several occurrences of that message in my posted log as well. Between 26/03 and today, I got 465 times the error Error fetching data: DeviceConnectionError() in my log, all in relation with Shelly devices (mainly plugs, but also switches, ix3):

Enregistreur: homeassistant.components.shelly
Source: helpers/update_coordinator.py:350
intégration: Shelly (documentation, problèmes)
S'est produit pour la première fois: 26 mars 2024 à 20:29:11 (465 occurrences)
Dernier enregistrement: 09:17:12

Error fetching Couverture chauffante data: Error fetching data: DeviceConnectionError()
Error fetching Hêtre data: Error fetching data: DeviceConnectionError()
Error fetching Portail data: Error fetching data: DeviceConnectionError()
Error fetching Séchoir data: Error fetching data: DeviceConnectionError()
Error fetching Lave-vaisselle data: Error fetching data: DeviceConnectionError()
issue-triage-workflows[bot] commented 7 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.