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
73.67k stars 30.8k forks source link

Shelly Gen3 devices (PM1 and 1 Mini) randomly go unavailable #122055

Open webjester0 opened 4 months ago

webjester0 commented 4 months ago

The problem

Shelly Gen3 devices (PM1 and 1 Mini) randomly go unavailable in HA. Sometimes for hours. Even though the devices are running fine in the Shelly app. Reloading the integration works, temporarily.

What version of Home Assistant Core has the issue?

core-2024.7.2

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 Gen3 PM1 and 1 mini

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?

Logger: homeassistant.components.shelly
Source: helpers/update_coordinator.py:344
integration: Shelly (documentation, issues)
First occurred: 07:19:48 (10 occurrences)
Last logged: 16:00:58

    Error fetching Sprinkler Main data: Device disconnected: DeviceConnectionError()
    Error fetching Sprinkler Main data: Device reconnect error

***********

Logger: homeassistant
Source: components/shelly/entity.py:362
First occurred: 10:02:57 (716 occurrences)
Last logged: 15:59:41

Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 255, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 411, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 165, in async_update_listeners
    update_callback()
  File "/usr/src/homeassistant/homeassistant/components/shelly/entity.py", line 372, in _update_callback
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1007, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1133, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1068, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1013, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 533, in state
    value = self.native_value
            ^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/shelly/sensor.py", line 1106, in native_value
    return self.attribute_value
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/shelly/entity.py", line 523, in attribute_value
    self._last_value = self.sub_status
                       ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/shelly/entity.py", line 512, in sub_status
    return self.status[self.entity_description.sub_key]
           ^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/shelly/entity.py", line 362, in status
    return cast(dict, self.coordinator.device.status[self.key])
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aioshelly/rpc_device/device.py", line 360, in status
    raise NotInitialized
aioshelly.exceptions.NotInitialized

********************

Logger: homeassistant.components.shelly
Source: helpers/debounce.py:137
integration: Shelly (documentation, issues)
First occurred: 10:29:08 (8 occurrences)
Last logged: 15:38:36

Unexpected exception from <bound method DataUpdateCoordinator.async_refresh of <homeassistant.components.shelly.coordinator.ShellyRpcCoordinator object at 0xffff8237ab40>>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/debounce.py", line 137, in _handle_timer_finish
    await task
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 288, in async_refresh
    await self._async_refresh(log_failures=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 411, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 165, in async_update_listeners
    update_callback()
  File "/usr/src/homeassistant/homeassistant/components/shelly/entity.py", line 372, in _update_callback
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1007, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1133, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1068, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1013, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/binary_sensor/__init__.py", line 293, in state
    if (is_on := self.is_on) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/shelly/binary_sensor.py", line 297, in is_on
    return bool(self.attribute_value)
                ^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/shelly/entity.py", line 520, in attribute_value
    self.status.get(self.entity_description.sub_key), self._last_value
    ^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/shelly/entity.py", line 362, in status
    return cast(dict, self.coordinator.device.status[self.key])
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aioshelly/rpc_device/device.py", line 360, in status
    raise NotInitialized
aioshelly.exceptions.NotInitialized

*************

Logger: homeassistant.components.shelly
Source: components/shelly/coordinator.py:170
integration: Shelly (documentation, issues)
First occurred: 10:01:55 (1 occurrences)
Last logged: 10:01:55

Error connecting to Shelly device Sprinkler Main, error: DeviceConnectionError(TimeoutError())

Additional information

No response

home-assistant[bot] commented 4 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)

kelddamsbo commented 4 months ago

I have the same problem with Shelly Plug 1

kelddamsbo commented 3 months ago

After upgrading my local router, the problems seams to be gone

CC-JION commented 3 months ago

Same here, Gen3 1pm mini , constantly becomes unavalible in HA.

makerwolf commented 3 months ago

Same here. One interesting note is the shelly is online and reachable through shelly app, and if I restart through the shelly app it reconnects just fine.

normalee1993 commented 3 months ago

I am having a very similar issue that is documented in this thread but with a Shelly Plus 1UL. I have about 12 of them on my home network with all fixed IPs. Every now and then they become unavailable and I and seeing these 3 debugs with each error instance of code at every instance.

2024-07-29 07:49:13.610 ERROR (MainThread) [homeassistant.components.shelly] Error fetching shellyplus1-d48afc75d328 data: Device disconnected: DeviceConnectionError()
2024-07-29 07:49:13.610 DEBUG (MainThread) [homeassistant.components.shelly] Finished fetching shellyplus1-d48afc75d328 data in 10.001 seconds (success: False)
2024-07-29 07:49:13.610 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.sh_1_uptime, old_state=<state sensor.sh_1_uptime=2024-07-28T18:53:56+00:00; device_class=timestamp, friendly_name=shellyplus1-d48afc75d328 uptime @ 2024-07-28T22:21:02.759027-05:00>, new_state=<state sensor.sh_1_uptime=unavailable; device_class=timestamp, friendly_name=shellyplus1-d48afc75d328 uptime @ 2024-07-29T07:49:13.610311-05:00>>
2024-07-29 07:49:13.610 DEBUG (Recorder) [homeassistant.components.recorder.core] Processing task: <Event state_changed[L]: entity_id=sensor.sh_1_uptime, old_state=<state sensor.sh_1_uptime=2024-07-28T18:53:56+00:00; device_class=timestamp, friendly_name=shellyplus1-d48afc75d328 uptime @ 2024-07-28T22:21:02.759027-05:00>, new_state=<state sensor.sh_1_uptime=unavailable; device_class=timestamp, friendly_name=shellyplus1-d48afc75d328 uptime @ 2024-07-29T07:49:13.610311-05:00>>
axlback commented 3 months ago

All my gen 3 mini 1s are disconnecting also, only started happening after the Shelly 1.4.0 firmware update. No other issues on my network. Resolves briefly if I reboot the device but always go offline again. Example logs below.

Logger: homeassistant.components.shelly Source: components/shelly/coordinator.py:171 integration: Shelly (documentation, issues) First occurred: August 2, 2024 at 10:04:29 AM (7698 occurrences) Last logged: 7:33:51 AM

Error connecting to Shelly device Shelly Front Deck, error: DeviceConnectionError(DeviceConnectionError(ClientConnectorError(ConnectionKey(host='2404:4400:41fc:3401: :::', port=80, is_ssl=False, ssl=True, proxy=None, proxy_auth=None, proxy_headers_hash=8289076281446336964), OSError(113, "Connect call failed ('2404:4400:41fc:3401: :::', 80, 0, 0)")))) Error connecting to Shelly device Back Deck, error: DeviceConnectionError(DeviceConnectionError(TimeoutError())) Error connecting to Shelly device Dining, error: DeviceConnectionError(DeviceConnectionError(TimeoutError())) Error connecting to Shelly device Dining, error: DeviceConnectionError(DeviceConnectionError(ClientConnectorError(ConnectionKey(host='2404:4400:41fc:3401: :::', port=80, is_ssl=False, ssl=True, proxy=None, proxy_auth=None, proxy_headers_hash=8289076281446336964), OSError(113, "Connect call failed ('2404:4400:41fc:3401: :::', 80, 0, 0)")))) Error connecting to Shelly device Back Deck, error: DeviceConnectionError(DeviceConnectionError(ClientConnectorError(ConnectionKey(host='2404:4400:41fc:3401: :::', port=80, is_ssl=False, ssl=True, proxy=None, proxy_auth=None, proxy_headers_hash=8289076281446336964), OSError(113, "Connect call failed ('2404:4400:41fc:3401::::', 80, 0, 0)"))))

bieniu commented 3 months ago

@axlback Your problem is different and has already been fixed. The fix will be available in HA 2024.8.0.

bieniu commented 3 months ago

@webjester0 @normalee1993 @makerwolf1 @CC-JION I recommend to restart HA in safe mode and check if problem still exists https://www.home-assistant.io/docs/troubleshooting_general/#restarting-home-assistant-in-safe-mode

axlback commented 3 months ago

@axlback Your problem is different and has already been fixed. The fix will be available in HA 2024.8.0.

Thanks very much. You guys are fantastic.

makerwolf commented 3 months ago

@webjester0 @normalee1993 @makerwolf1 @CC-JION I recommend to restart HA in safe mode and check if problem still exists https://www.home-assistant.io/docs/troubleshooting_general/#restarting-home-assistant-in-safe-mode

Ever since updating to 1.4.0 the issue has not happened again (since August 1st). Running safe mode is thus very impractical, as also before the issue could take a few days to re-appear.

russilui commented 3 months ago

Hi I have got the same issue with a Pro EM 50 after updating to 1.4.0. Here is the log:

> Logger: homeassistant.config_entries
> Source: config_entries.py:594
> First occurred: 01:38:01 (10 occurrences)
> Last logged: 22:38:05
> 
> Error setting up entry shellyproem50-08f9e0e5c910 for shelly
> Error setting up entry shellyproem50-08f9e0e61d50 for shelly
> Traceback (most recent call last):
>   File "/usr/local/lib/python3.12/site-packages/yarl/_url.py", line 191, in __new__
>     port = val.port
>            ^^^^^^^^
>   File "/usr/local/lib/python3.12/urllib/parse.py", line 182, in port
>     raise ValueError(f"Port could not be cast to integer value as {port!r}")
> ValueError: Port could not be cast to integer value as '676:aa82:0:af9:e0ff:fee5:c910:80'
> 
> The above exception was the direct cause of the following exception:
> 
> Traceback (most recent call last):
>   File "/usr/src/homeassistant/homeassistant/config_entries.py", line 594, in async_setup
>     result = await component.async_setup_entry(hass, self)
>              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>   File "/usr/src/homeassistant/homeassistant/components/shelly/__init__.py", line 128, in async_setup_entry
>     return await _async_setup_rpc_entry(hass, entry)
>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>   File "/usr/src/homeassistant/homeassistant/components/shelly/__init__.py", line 265, in _async_setup_rpc_entry
>     shelly_entry_data.rpc.async_setup()
>   File "/usr/src/homeassistant/homeassistant/components/shelly/coordinator.py", line 695, in async_setup
>     super().async_setup(pending_platforms)
>   File "/usr/src/homeassistant/homeassistant/components/shelly/coordinator.py", line 142, in async_setup
>     device_entry = dev_reg.async_get_or_create(
>                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>   File "/usr/src/homeassistant/homeassistant/helpers/device_registry.py", line 663, in async_get_or_create
>     configuration_url = _validate_configuration_url(configuration_url)
>                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>   File "/usr/src/homeassistant/homeassistant/helpers/device_registry.py", line 234, in _validate_configuration_url
>     url = value if type(value) is URL else _cached_parse_url(url_as_str)
>                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>   File "/usr/local/lib/python3.12/site-packages/yarl/_url.py", line 193, in __new__
>     raise ValueError(
> ValueError: Invalid URL: port can't be converted to integer
> 

It worked just fine for a few months before the update. It works for a few minutes if I do a manual reload or reconfigure from the shelly device list in HA. Any ideas?

AnthonyBe commented 3 months ago

I installed 3 x Shelly 1PM Mini Gen3 2 days ago (already have numerous Shelly Plus 1PM and Plus 2PM devices running fine) and am seeing the same issue. Interestingly, I only ever have 2 out of 3 go offline in HA; never all 3 at the same time. All of mine were updated to firmware v1.4.0 as soon as I set them up.

image

As others have observed,

  1. they come back online when I run Re-configure on the device in HA or reload the integration
  2. they are always still available in the Shelly app (i.e. it's an issue within HA)

I'm running: Version core-2024.7.4 Installation type Home Assistant OS Supervisor true Docker true User root Virtual environment false Python version 3.12.4 Operating system family Linux Operating system version 6.6.33-haos

I'll enable Debugging and grab Debug logs and Diagnostics later today.

EDIT: ah. I think I'm seeing the issue resolved by this fix in 2024.8 https://github.com/home-assistant/core/pull/123081

issue-triage-workflows[bot] commented 1 week 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.

kelddamsbo commented 1 week ago

Can confirm it works now