Shelly DeviceConnectionError() and "Can not connect"

They no longer connect in HA, “unable to connect” > DeviceConnectionError… they always worked, never a problem, they have a fixed IP, nothing has changed in my network…

2023-01-02 09:36:43.104 WARNING (MainThread) [homeassistant.config_entries] Config entry 'Shelly EM' for shelly integration not ready yet: DeviceConnectionError(); Retrying in background

2023-01-02 17:18:11.798 DEBUG (MainThread) [aioshelly.common] host 192.168.1.80: error: DeviceConnectionError(ClientResponseError(RequestInfo(url=URL('http://192.168.1.80/shelly'), method='GET', headers=<CIMultiDictProxy('Host': '192.168.1.80', 'User-Agent': 'HomeAssistant/2022.12.8 aiohttp/3.8.1 Python/3.10', 'Accept': '/', 'Accept-Encoding': 'gzip, deflate')>, real_url=URL('http://192.168.1.80/shelly')), (), status=400, message='Bad Request', headers=<CIMultiDictProxy('Server': 'Mongoose/6.18', 'Content-Type': 'text/plain', 'Connection': 'close', 'Content-Length': '11')>))
2 Likes

Same issue here but not for all of my Shellys. I got 24 devices and 20 of throw the same error (even after restart, delete and add again).

1 Like

Replying to myself:

Found the solution here: Shelly via HTTP or MQTT? - #2 by tom_l

Works like a charm!

1 Like

I have the same issue with 4 devices. A restart of the whole host system fixes is for a little while.

1 Like

the problem was due to the latest version of Docker, 4.15. Going back to 4.14 fixed everything!!

1 Like

I’ve also had similar issues with my Shellys recently, and also haven’t changed settings on Shelly recently either.

1 Like

Same issue here.
Can’t autodetect or manually connect my shelly1 and shelly1L devices with build in Shelly integration.
The devices ip are pingable by hass, and fully functional with Shelly App and browser interface.
CoIoT properly set with haas ip address and 5683 port.
I don’t know where to look anymore…

Same here!

Same Problem here since Version 2024.1.1

2 Likes

I have exactly the same issue after same update. :cry:

Considering the large number of people affected and this being a highly used integration (almost 18% of installs, according to our analytics), I will ship an extra release today.

…/Frenck

/
2024.1.2 - Working ! :+1:

It looks like it is fixed after upgrading to 2024.1.2: Fix Shelly missing Gen value for older devices by thecode · Pull Request #107294 · home-assistant/core · GitHub

Still having odd issues in 2024.1.3, I can ping the device and it works for a bit then it drops out. I have removed it and tired to re-add it but it just does not want to connect I can open the web browser connection and that works fine

2 Likes

Same issue even with latest update to 2024.1.5

1 Like

I have this issue too with a shell EM, when trying to turn off the switch I have this error and overpowering on the shelly turns on for few seconds to… Even it’s no power on this one because it’s just controlling a relay switch… It always fails on the same turn off at 5am. I have another turn off at 5pm but this one nevers fails (and never go to overpowering)… I made a second try 10 sec later after the failing one and it works… I can’t understand it.
image

Logger: homeassistant.components.websocket_api.http.connection
Source: components/websocket_api/commands.py:238
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 6 février 2024 à 05:00:03 (2 occurrences)
Last logged: 05:00:04

[140444533162816] Setting state for entity ShellyEM_ecs_ret-grid failed, state: {'turn': 'off'}, error: DeviceConnectionError()
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aioshelly/block_device/device.py", line 287, in http_request
    resp: ClientResponse = await self.aiohttp_session.request(
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 605, in _request
    await resp.start(conn)
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client_reqrep.py", line 966, in start
    message, payload = await protocol.read()  # type: ignore[union-attr]
                       ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/streams.py", line 622, in read
    await self._waiter
aiohttp.client_exceptions.ClientOSError: [Errno 104] Connection reset by peer

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.11/site-packages/aioshelly/block_device/device.py", line 510, in set_state
    return await self.device.http_request(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aioshelly/block_device/device.py", line 304, 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 238, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2149, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2186, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 272, in handle_service
    return await service.entity_service_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 882, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 952, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/shelly/switch.py", line 269, in async_turn_off
    self.control_result = await self.set_state(turn="off")
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/shelly/entity.py", line 349, in set_state
    raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: Setting state for entity ShellyEM_ecs_ret-grid failed, state: {'turn': 'off'}, error: DeviceConnectionError()

I just made the effort to move from Shelly4Hass to the official integration, and now I get this same problem. Never had that before. Really painful, I can’t rely on my devices anymore.

Same issues here, really painful… hope someone has or gets an idea how to fix this.

“Kan service light/turn_on niet aanroepen. Setting state for entity shellydimmer2-98CDAC0BEF7F failed, state: {‘turn’: ‘on’}, error: DeviceConnectionError()”

The crazy thing is that the feedback works fine, so if I enable the same lights via the Shelly app, I see them enabled in HA. And when I turn them of the also turn of in HA.

I’m also having the same issue with a Pro 3EM. It doesn’t matter if it’s connected using an ethernet cable, WiFi or both. It randomly changes to a different IP address in a totally different subnet. E.g 192.168.1.102 when the address is on 192.168.20.104.

I’ve tried tried using DCHP reservation to keep it’s IP address on the wired and wireless connection.

Power cycling doesn’t work.

I’m also able access it via the IP address via a browser with no issues or drop outs.

I’ve set up Uptime Kuma to ping it at its ethernet address every 30 seconds with no alerts.

Anyone else have any ideas?

Hey @melvin2 , did you manage to resolve this.

I’ve got the same issue, using the web or Shelly app it instantly updates HASS, however when going from HASS it constantly gives the error you shared.

Hoping you solved this as I’m tempted to do a full reset or try mqtt but I’ve got about 50 devices and some work and others don’t.