Core: Philips Hue: Connection reset by peer

Created on 22 Mar 2018  ·  23Comments  ·  Source: home-assistant/core

Home Assistant release with the issue:
0.65.6 (Docker)

Operating environment (Hass.io/Docker/Windows/etc.):
Docker on a reasonably powerful desktop (i5-2500K, 16GB RAM, SSD)

Component/platform:
Philips Hue

Description of problem:
My logs are constantly giving me the below errors. All of my lights are configured with fluxers so Home Assistant is regularly sending them requests. Sometimes only some of the lights in a room are updated to the correct color temperature.

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

hue:
  bridges:
    - host: philipshue.singularity.net
      allow_unreachable: true
      filename: hue_hub_token.conf

switch:
     - platform: flux
      name: Entryway Fluxer
      lights:
        - light.entryway_light_1
        - light.entryway_light_2
      start_time: '7:00'
      stop_time: '22:00'
      start_colortemp: 5000
      mode: mired

    - platform: flux
      name: Kitchen Fluxer
      lights:
        - light.kitchen_light_1
        - light.kitchen_light_2
        - light.kitchen_light_3
        - light.kitchen_light_4
      start_time: '7:00'
      stop_time: '22:00'
      start_colortemp: 5000
      sunset_colortemp: 3500

    - platform: flux
      name: Dining Fluxer
      lights:
        - light.dining_lights_level
      start_time: '7:00'
      stop_time: '22:00'
      start_colortemp: 5000
      sunset_colortemp: 3500
      stop_colortemp: 1000

    - platform: flux
      name: Living Room Fluxer
      lights:
        - light.living_room_lamp_1
        - light.living_room_lamp_2
        - light.entertainment_light_1
        - light.entertainment_light_2
      start_time: '7:00'
      stop_time: '22:00'
      start_colortemp: 5000
      sunset_colortemp: 3500

    - platform: template
      switches:
        living_area_fluxer:
          friendly_name: Living Area Fluxer
          value_template: >-
            {{ is_state('switch.entryway_fluxer', 'on') and
              is_state('switch.kitchen_fluxer', 'on') and
              is_state('switch.dining_fluxer', 'on') and
              is_state('switch.living_room_fluxer', 'on') }}
          turn_on:
            service: switch.turn_on
            entity_id:
              - switch.entryway_fluxer
              - switch.kitchen_fluxer
              - switch.dining_fluxer
              - switch.living_room_fluxer
          turn_off:
            service: switch.turn_off
            entity_id:
              - switch.entryway_fluxer
              - switch.kitchen_fluxer
              - switch.dining_fluxer
              - switch.living_room_fluxer

    - platform: flux
      name: Bedroom Fluxer
      lights:
        - light.nightstand_1
        - light.nightstand_2
        - light.tree_lamp_1
        - light.tree_lamp_2
        - light.tree_lamp_3
        - light.tree_lamp_4
        - light.tree_lamp_5
        - light.closet_light
      start_time: '7:00'
      stop_time: '22:00'
      start_colortemp: 5000
      mode: mired

    - platform: flux
      lights:
        - light.bathroom_mirror_1
        - light.bathroom_mirror_2
        - light.bathroom_mirror_3
        - light.bathroom_mirror_4
        - light.shower_light
      name: Bathroom Fluxer
      start_time: '7:00'
      stop_time: '22:00'
      start_colortemp: 5000
      mode: mired
  1. Turn on the lights to a setting other than what the fluxer would set
  2. Turn on the fluxers
  3. See that only some of the lights get set properly and the logs are full of errors

Traceback (if applicable):

homeassistant_1  | 2018-03-22T13:17:30.847723052Z 2018-03-22 09:17:30 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall light.turn_on: entity_id=['light.tree_lamp_2'], transition=30.0, brightness=209, color_temp=216>
homeassistant_1  | 2018-03-22T13:17:30.847742234Z Traceback (most recent call last):
homeassistant_1  | 2018-03-22T13:17:30.847748949Z   File "/usr/src/app/homeassistant/core.py", line 1006, in _event_to_service_call
homeassistant_1  | 2018-03-22T13:17:30.847755008Z     await service_handler.func(service_call)
homeassistant_1  | 2018-03-22T13:17:30.847760819Z   File "/usr/src/app/homeassistant/components/light/__init__.py", line 344, in async_handle_light_service
homeassistant_1  | 2018-03-22T13:17:30.847766862Z     await light.async_turn_on(**params)
homeassistant_1  | 2018-03-22T13:17:30.847772598Z   File "/usr/local/lib/python3.6/asyncio/futures.py", line 327, in __iter__
homeassistant_1  | 2018-03-22T13:17:30.847778444Z     yield self  # This tells Task to wait for completion.
homeassistant_1  | 2018-03-22T13:17:30.847784175Z   File "/usr/local/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup
homeassistant_1  | 2018-03-22T13:17:30.847790125Z     future.result()
homeassistant_1  | 2018-03-22T13:17:30.847795681Z   File "/usr/local/lib/python3.6/asyncio/futures.py", line 243, in result
homeassistant_1  | 2018-03-22T13:17:30.847801499Z     raise self._exception
homeassistant_1  | 2018-03-22T13:17:30.847807069Z   File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
homeassistant_1  | 2018-03-22T13:17:30.847812863Z     result = self.fn(*self.args, **self.kwargs)
homeassistant_1  | 2018-03-22T13:17:30.847818586Z   File "/usr/src/app/homeassistant/components/light/hue.py", line 342, in turn_on
homeassistant_1  | 2018-03-22T13:17:30.847824439Z     self._command_func(self.light_id, command)
homeassistant_1  | 2018-03-22T13:17:30.847830067Z   File "/usr/src/app/homeassistant/components/hue.py", line 270, in set_light
homeassistant_1  | 2018-03-22T13:17:30.847837109Z     return self.bridge.set_light(light_id, command)
homeassistant_1  | 2018-03-22T13:17:30.847842704Z   File "/usr/local/lib/python3.6/site-packages/phue.py", line 898, in set_light
homeassistant_1  | 2018-03-22T13:17:30.847848482Z     converted_light) + '/state', data))
homeassistant_1  | 2018-03-22T13:17:30.847853989Z   File "/usr/local/lib/python3.6/site-packages/phue.py", line 663, in request
homeassistant_1  | 2018-03-22T13:17:30.847860017Z     result = connection.getresponse()
homeassistant_1  | 2018-03-22T13:17:30.847865528Z   File "/usr/local/lib/python3.6/http/client.py", line 1331, in getresponse
homeassistant_1  | 2018-03-22T13:17:30.847871258Z     response.begin()
homeassistant_1  | 2018-03-22T13:17:30.847876667Z   File "/usr/local/lib/python3.6/http/client.py", line 297, in begin
homeassistant_1  | 2018-03-22T13:17:30.847882426Z     version, status, reason = self._read_status()
homeassistant_1  | 2018-03-22T13:17:30.847888020Z   File "/usr/local/lib/python3.6/http/client.py", line 258, in _read_status
homeassistant_1  | 2018-03-22T13:17:30.847893736Z     line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
homeassistant_1  | 2018-03-22T13:17:30.847899479Z   File "/usr/local/lib/python3.6/socket.py", line 586, in readinto
homeassistant_1  | 2018-03-22T13:17:30.847905193Z     return self._sock.recv_into(b)
homeassistant_1  | 2018-03-22T13:17:30.847910721Z ConnectionResetError: [Errno 104] Connection reset by peer
homeassistant_1  | 2018-03-22T13:17:30.849393717Z 2018-03-22 09:17:30 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall light.turn_on: entity_id=['light.tree_lamp_5'], transition=30.0, brightness=209, color_temp=216>
homeassistant_1  | 2018-03-22T13:17:30.849438544Z Traceback (most recent call last):
homeassistant_1  | 2018-03-22T13:17:30.849447713Z   File "/usr/src/app/homeassistant/core.py", line 1006, in _event_to_service_call
homeassistant_1  | 2018-03-22T13:17:30.849466524Z     await service_handler.func(service_call)
homeassistant_1  | 2018-03-22T13:17:30.849480709Z   File "/usr/src/app/homeassistant/components/light/__init__.py", line 344, in async_handle_light_service
homeassistant_1  | 2018-03-22T13:17:30.849492396Z     await light.async_turn_on(**params)
homeassistant_1  | 2018-03-22T13:17:30.849505437Z   File "/usr/local/lib/python3.6/asyncio/futures.py", line 327, in __iter__
homeassistant_1  | 2018-03-22T13:17:30.849511681Z     yield self  # This tells Task to wait for completion.
homeassistant_1  | 2018-03-22T13:17:30.849525161Z   File "/usr/local/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup
homeassistant_1  | 2018-03-22T13:17:30.849545676Z     future.result()
homeassistant_1  | 2018-03-22T13:17:30.849558874Z   File "/usr/local/lib/python3.6/asyncio/futures.py", line 243, in result
homeassistant_1  | 2018-03-22T13:17:30.849566354Z     raise self._exception
homeassistant_1  | 2018-03-22T13:17:30.849579740Z   File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
homeassistant_1  | 2018-03-22T13:17:30.849585964Z     result = self.fn(*self.args, **self.kwargs)
homeassistant_1  | 2018-03-22T13:17:30.849598427Z   File "/usr/src/app/homeassistant/components/light/hue.py", line 342, in turn_on
homeassistant_1  | 2018-03-22T13:17:30.849611321Z     self._command_func(self.light_id, command)
homeassistant_1  | 2018-03-22T13:17:30.849618658Z   File "/usr/src/app/homeassistant/components/hue.py", line 270, in set_light
homeassistant_1  | 2018-03-22T13:17:30.849639889Z     return self.bridge.set_light(light_id, command)
homeassistant_1  | 2018-03-22T13:17:30.849647172Z   File "/usr/local/lib/python3.6/site-packages/phue.py", line 898, in set_light
homeassistant_1  | 2018-03-22T13:17:30.849658957Z     converted_light) + '/state', data))
homeassistant_1  | 2018-03-22T13:17:30.849666588Z   File "/usr/local/lib/python3.6/site-packages/phue.py", line 663, in request
homeassistant_1  | 2018-03-22T13:17:30.849672507Z     result = connection.getresponse()
homeassistant_1  | 2018-03-22T13:17:30.849685972Z   File "/usr/local/lib/python3.6/http/client.py", line 1331, in getresponse
homeassistant_1  | 2018-03-22T13:17:30.849698565Z     response.begin()
homeassistant_1  | 2018-03-22T13:17:30.849705549Z   File "/usr/local/lib/python3.6/http/client.py", line 297, in begin
homeassistant_1  | 2018-03-22T13:17:30.849719207Z     version, status, reason = self._read_status()
homeassistant_1  | 2018-03-22T13:17:30.849724874Z   File "/usr/local/lib/python3.6/http/client.py", line 258, in _read_status
homeassistant_1  | 2018-03-22T13:17:30.849737169Z     line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
homeassistant_1  | 2018-03-22T13:17:30.849744424Z   File "/usr/local/lib/python3.6/socket.py", line 586, in readinto
homeassistant_1  | 2018-03-22T13:17:30.849756980Z     return self._sock.recv_into(b)
homeassistant_1  | 2018-03-22T13:17:30.849787417Z ConnectionResetError: [Errno 104] Connection reset by peer

Additional information:
Both the system running Docker and the Hue Bridge are hard wired. The Hue Bridge is the 2015 version (Model BSB002) and running the latest firmware (1802201122). All of the lights' firmwares are also fully up to date.
I think this may be caused by the combination of the fact that I have 23 hue lights and HomeAssistant sends a request for each individual light. I've also seen the below error on occasion, I think HomeAssistant is hammering my Hue bridge. Every now and again I also get a Cannot reach the bridge error due to Connection reset by peer. It sure would be nice if we could group the requests...

Update for light.living_room_lamp_2 fails
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/helpers/entity.py", line 204, in async_update_ha_state
    yield from self.async_device_update()
  File "/usr/src/app/homeassistant/helpers/entity.py", line 327, in async_device_update
    yield from self.hass.async_add_job(self.update)
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 327, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup
    future.result()
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 243, in result
    raise self._exception
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/app/homeassistant/components/light/hue.py", line 366, in update
    self.update_lights(no_throttle=True)
  File "/usr/src/app/homeassistant/components/light/hue.py", line 142, in <lambda>
    lambda **kw: update_lights(hass, bridge, add_devices, **kw))
  File "/usr/src/app/homeassistant/util/__init__.py", line 319, in wrapper
    result = method(*args, **kwargs)
  File "/usr/src/app/homeassistant/util/__init__.py", line 319, in wrapper
    result = method(*args, **kwargs)
  File "/usr/src/app/homeassistant/components/light/hue.py", line 112, in update_lights
    return unthrottled_update_lights(hass, bridge, add_devices)
  File "/usr/src/app/homeassistant/components/light/hue.py", line 123, in unthrottled_update_lights
    api = bridge.get_api()
  File "/usr/src/app/homeassistant/components/hue.py", line 266, in get_api
    return self.bridge.get_api()
  File "/usr/local/lib/python3.6/site-packages/phue.py", line 838, in get_api
    return self.request('GET', '/api/' + self.username)
  File "/usr/local/lib/python3.6/site-packages/phue.py", line 667, in request
    return json.loads(response.decode('utf-8'))
  File "/usr/local/lib/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.6/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
in progress hue waiting-for-reply

Most helpful comment

Anyone else still experiencing this problem? Because the work around would probably work.

All 23 comments

Still exists in 0.70.

Still exists in 0.73.2.

However, I found that if I use the hue rooms instead identifying each bulb individually the problem goes away:

diff --git a/homeassistant/switches/flux.yaml b/homeassistant/switches/flux.yaml
--- a/homeassistant/switches/flux.yaml
+++ b/homeassistant/switches/flux.yaml
@@ -1,8 +1,7 @@
 - platform: flux
   name: Entryway Fluxer
   lights:
-    - light.entryway_light_1
-    - light.entryway_light_2
+    - light.entryway
   mode: mired

   start_time: '6:00'
@@ -17,10 +16,7 @@
 - platform: flux
   name: Kitchen Fluxer
   lights:
-    - light.kitchen_light_1
-    - light.kitchen_light_2
-    - light.kitchen_light_3
-    - light.kitchen_light_4
+    - light.kitchen
   mode: xy

   start_time: '6:00'
@@ -50,10 +46,7 @@
 - platform: flux
   name: Living Room Fluxer
   lights:
-    - light.living_room_lamp
-    - light.desk_lamp
-    - light.entertainment_light_1
-    - light.entertainment_light_2
+    - light.living_room
   mode: xy

   start_time: '6:00'
@@ -94,13 +87,7 @@
 - platform: flux
   name: Bedroom Fluxer
   lights:
-    - light.nightstand_1
-    - light.nightstand_2
-    - light.tree_lamp_1
-    - light.tree_lamp_2
-    - light.tree_lamp_3
-    - light.tree_lamp_4
-    - light.tree_lamp_5
+    - light.bedroom
     - light.closet_light
   mode: mired

@@ -116,11 +103,7 @@
 - platform: flux
   name: Bathroom Fluxer
   lights:
-    - light.bathroom_mirror_1
-    - light.bathroom_mirror_2
-    - light.bathroom_mirror_3
-    - light.bathroom_mirror_4
-    - light.shower_light
+    - light.bathroom
   mode: mired

   start_time: '6:00'

While this is an okay workaround, it limits my ability to turn off individual lights within the room and still flux the remaining lights that are on.

I have this problem also and grouping them works for some instances but others I need to control them individually.

My HASS and 3 Hue bridges are all hardwired and I have HASS running on a 4790K with 32GB RAM so I do not think its a limitation of the hardware HASS is running on.

I have ~35 bulbs and 3 hubs I am trying to work with.

I get the same problem/error when turning on/off a single habridget device (emulated hue). Any ideas?

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 :+1:

Still exists.

Exists for me also.

Still a problem

I was having a similar problem (i.e. the same error in line 357 of /usr/local/lib/python3.6/json/decoder.py). Hopefully this will help:

In my case, if I had a simple automation such as:

##automation.yaml
- id: '1510464937408'
  alias: Bedroom at Night
  trigger:
    platform: time
    at: '23:30:00'
  action:
    service: light.turn_on
    entity_id:
      - light.bedroom_light
      - light.bedroom_fan

The "bedroom_light" would turn on, but not the "bedroom_fan". In fact, for any number of devices in the list, only the first one would work, the others devices would not switch.

I found out that an exception/error was not being caught and/or propagated up to the calling programs. In my case, the fix was done in python3.6/site-packages/aiohttp/client_reqrep.py because that was the function calling "___init___.py". You may find a similar way to fix your problem in python3.6/site-packages/phue.py, since this is the function calling "___init___.py" in your case.

Again, I solved my problem by adding the code below to line 947 of /srv/homeassistant/lib/python3.6/site-packages/aiohttp/client_reqrep.py

 ### GND ADDED LINES FROM HERE TO "ORIGINAL" BELOW
 while True:
    try:
        return loads(stripped.decode(encoding))
        break
    except ValueError:
        print("Oops! GND: Captured error  ...")
        return None
    except:
        print("Oops! GND: Non-Captured error  ...")
        return None

 ### GND ORIGNAL LINE return loads(stripped.decode(encoding))
> 

I know it's the "fault" of the Philips Hue bridge / API, as we're kinda DDoS'ing it with the API requests. But can't we just catch the ConnectionResetError exception and do some retries with some delays in between? Let's say 3 retries with increasing delays, something like:

  • Initial try
  • Delay 250ms
  • Retry 1
  • Delay 500ms
  • Retry 2
  • Delay 750ms
  • Retry 3
  • Raise (passthrough) initial exception

It's not a perfect solution, but the refused connection is how the Hue bridge reacts when bombing it with requests. We could workaround that :)

If you'd like, I can have a look at it and open a PR.

If we know the capabilities of the Hue bridge, we can also introduce a more "foresight" solution which will probably limit the requests per second. Of course still in combination with the solution I proposed above, as we're probably not the only client calling the Hue API. But a combination of exception handling (and this behaviour IS expected, so we should also handle it) & limit would be nice.

I'd still aim for the exception handling first and add limits later on.

Well… that reverse engineering was… quite an experience! ;)

I (probably) found the right spot to do some exception handling. I was playing around a bit and catched request errors. Worked a lot better, but there were still some response errors after that (text/html instead of another content type and alike).

So I finally decided to catch all request and response errors, and added 3 retries (with 0.5s & 1s delays).

Just gave it a quick shot and it worked much better than before. I tried to do more testing, however… pregnant women don't like it when the flat is going all dark & bright again… several times… when they're trying to read a book or something. "Calm down, everything's fine" is also not an appropriate answer (apparently). So to save my marriage & the nerves of my bumpy wifey, I've to postpone testing to another time ;)

If anyone wants to test it, feel free and report back! MR is open, but (mainly) untested yet.

Anyone else still experiencing this problem? Because the work around would probably work.

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 now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

I recently updated HA to 0.98.1 and the problem was still there. So,
I applied the same fix I mentioned before (see my post above of
Mar/18th) and everything works again now.

So, yes, the problem is still there and my suggestion fixes it!

With HA 0.100.2 the problem was still there.

Brand new install of latest Hassio stable on an RPi4, pretty much the only thing added to it is lights. When toggling all lights on/off using the entity card header toggle, sometimes one or two lights don't turn on/off and I get these errors in logs:

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 564, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/components/hue/light.py", line 429, in async_turn_on
    await self.light.set_state(**command)
  File "/usr/local/lib/python3.7/site-packages/aiohue/lights.py", line 117, in set_state
    json=data)
  File "/usr/local/lib/python3.7/site-packages/aiohue/bridge.py", line 69, in request
    ) from None
aiohue.errors.RequestError: Error requesting data from 192.168.86.62: [Errno 104] Connection reset by peer
Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 564, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/components/hue/light.py", line 429, in async_turn_on
    await self.light.set_state(**command)
  File "/usr/local/lib/python3.7/site-packages/aiohue/lights.py", line 117, in set_state
    json=data)
  File "/usr/local/lib/python3.7/site-packages/aiohue/bridge.py", line 62, in request
    'Invalid content type: {}'.format(res.content_type))
aiohue.errors.ResponseError: Invalid content type: text/html

Router is also brand new. Hue hub is the Gen 2 one. Dunno if this helps at all.

104 gives same problem
this happens when I activate a scene with 9 lights
triggering the scene a second time works

2020-01-18 18:55:14 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.1843709808] Error requesting data from x.x.x.x: [Errno 104] Connection reset by peer
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 134, in handle_call_service
connection.context(msg),
File "/usr/src/homeassistant/homeassistant/core.py", line 1226, in async_call
await asyncio.shield(self._execute_service(handler, service_call))
File "/usr/src/homeassistant/homeassistant/core.py", line 1251, in _execute_service
await handler.func(service_call)
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 201, in handle_service
self._platforms.values(), func, call, service_name, required_features
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 335, in entity_service_call
future.result() # pop exception if have
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 357, in _handle_service_platform_call
await getattr(entity, func)(data)
File "/usr/src/homeassistant/homeassistant/components/homeassistant/scene.py", line 244, in async_activate
context=self._context,
File "/usr/src/homeassistant/homeassistant/helpers/state.py", line 106, in async_reproduce_state
*(worker(domain, data) for domain, data in to_call.items())
File "/usr/src/homeassistant/homeassistant/helpers/state.py", line 100, in worker
hass, states_by_domain, context=context
File "/usr/src/homeassistant/homeassistant/components/light/reproduce_state.py", line 125, in async_reproduce_states
*(_async_reproduce_state(hass, state, context) for state in states)
File "/usr/src/homeassistant/homeassistant/components/light/reproduce_state.py", line 116, in _async_reproduce_state
DOMAIN, service, service_data, context=context, blocking=True
File "/usr/src/homeassistant/homeassistant/core.py", line 1226, in async_call
await asyncio.shield(self._execute_service(handler, service_call))
File "/usr/src/homeassistant/homeassistant/core.py", line 1251, in _execute_service
await handler.func(service_call)
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 201, in handle_service
self._platforms.values(), func, call, service_name, required_features
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 335, in entity_service_call
future.result() # pop exception if have
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 357, in _handle_service_platform_call
await getattr(entity, func)(
data)
File "/usr/src/homeassistant/homeassistant/components/hue/light.py", line 464, in async_turn_off
await self.bridge.async_request_call(self.light.set_state(command))
File "/usr/src/homeassistant/homeassistant/components/hue/bridge.py", line 103, in async_request_call
return await coro
File "/usr/local/lib/python3.7/site-packages/aiohue/lights.py", line 117, in set_state
json=data)
File "/usr/local/lib/python3.7/site-packages/aiohue/bridge.py", line 78, in request
) from None
aiohue.errors.RequestError: Error requesting data from x.x.x.x: [Errno 104] Connection reset by peer
2020-01-18 18:55:18 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 576, in async_request_call
await coro
File "/usr/src/homeassistant/homeassistant/components/hue/light.py", line 441, in async_turn_on
await self.bridge.async_request_call(self.light.set_state(
command))
File "/usr/src/homeassistant/homeassistant/components/hue/bridge.py", line 103, in async_request_call
return await coro
File "/usr/local/lib/python3.7/site-packages/aiohue/lights.py", line 117, in set_state
json=data)
File "/usr/local/lib/python3.7/site-packages/aiohue/bridge.py", line 78, in request
) from None
aiohue.errors.RequestError: Error requesting data from x.x.x.x: [Errno 104] Connection reset by peer
2020-01-18 18:55:18 ERROR (MainThread) [homeassistant.components.hue.light] Unable to reach bridge x.x.x.x (Error requesting data from x.x.x.x: [Errno 104] Connection reset by peer)

FWIW this is still happening on 0.104.2. Using hue groups isn't an option for my setup. One solution would be to retry the requests and/or rate-limit the requests. I suppose I could use scripts and only trigger a handful of bulb-changes between sleep/wait calls but that feels very hacky.

2020-02-01 15:39:35 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.1430006944] Error requesting data from 192.168.1.183: [Errno 104] Connection reset by peer
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/homeassistant/components/websocket_api/commands.py", line 129, in handle_call_service
    await hass.services.async_call(
  File "/usr/local/lib/python3.8/site-packages/homeassistant/core.py", line 1226, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/usr/local/lib/python3.8/site-packages/homeassistant/core.py", line 1251, in _execute_service
    await handler.func(service_call)
  File "/usr/local/lib/python3.8/site-packages/homeassistant/helpers/entity_component.py", line 200, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/local/lib/python3.8/site-packages/homeassistant/helpers/service.py", line 335, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/local/lib/python3.8/site-packages/homeassistant/helpers/service.py", line 357, in _handle_service_platform_call
    await getattr(entity, func)(**data)
  File "/usr/local/lib/python3.8/site-packages/homeassistant/components/homeassistant/scene.py", line 240, in async_activate
    await async_reproduce_state(
  File "/usr/local/lib/python3.8/site-packages/homeassistant/helpers/state.py", line 105, in async_reproduce_state
    await asyncio.gather(
  File "/usr/local/lib/python3.8/site-packages/homeassistant/helpers/state.py", line 99, in worker
    await platform.async_reproduce_states(  # type: ignore
  File "/usr/local/lib/python3.8/site-packages/homeassistant/components/light/reproduce_state.py", line 124, in async_reproduce_states
    await asyncio.gather(
  File "/usr/local/lib/python3.8/site-packages/homeassistant/components/light/reproduce_state.py", line 115, in _async_reproduce_state
    await hass.services.async_call(
  File "/usr/local/lib/python3.8/site-packages/homeassistant/core.py", line 1226, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/usr/local/lib/python3.8/site-packages/homeassistant/core.py", line 1251, in _execute_service
    await handler.func(service_call)
  File "/usr/local/lib/python3.8/site-packages/homeassistant/helpers/entity_component.py", line 200, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/local/lib/python3.8/site-packages/homeassistant/helpers/service.py", line 335, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/local/lib/python3.8/site-packages/homeassistant/helpers/service.py", line 357, in _handle_service_platform_call
    await getattr(entity, func)(**data)
  File "/usr/local/lib/python3.8/site-packages/homeassistant/components/hue/light.py", line 464, in async_turn_off
    await self.bridge.async_request_call(self.light.set_state(**command))
  File "/usr/local/lib/python3.8/site-packages/homeassistant/components/hue/bridge.py", line 103, in async_request_call
    return await coro
  File "/home/pi/repo/HomeAssistantConfig/deps/lib/python3.8/site-packages/aiohue/lights.py", line 116, in set_state
    await self._request('put', 'lights/{}/state'.format(self.id),
  File "/home/pi/repo/HomeAssistantConfig/deps/lib/python3.8/site-packages/aiohue/bridge.py", line 76, in request
    raise RequestError(
aiohue.errors.RequestError: Error requesting data from [redacted] [Errno 104] Connection reset by peer

@rtimmons I've exactly the same problem and I already described it in https://github.com/home-assistant/home-assistant/issues/13389#issuecomment-475384547. I had an open MR but it was closed recently w/o merging and fixing the issue.

I can try rebasing and working on it again, but s/o needs to merge it. Unfortunately I also have a problem catching the correct exceptions as the details (HTTP status code) are not returned in the exception. I already opened an issue but never got a response. If the exception would return a proper traceback with the ability to get the HTTP status code, the implementation would be much simpler. But apparently nobody's interested in that ;)

My last MR didn't fix everything, just the turn off & on actions, thus it was rejected. From a mathematical point of view I thought fixing at least some things is better than fixing nothing and ignoring the issue ;)

I'll see if I can rebase it to current dev and fix it again.

So I just had a look at the code. Apparently Bram Kragten already solved the problem in d91dd68b31d5. A different approach but it looks very clean, or at least it aims to solve the problem directly on the bridge module, which is nice! :)

I didn't try dev yet, but I'll do and see if the bridge problems are solved. I just checked if the commit is in the current release and it seems so:

g describe --contains d91dd68b31d5
0.103.0b0~160

g describe --all d91dd68b31d5
tags/0.101.3-642-gd91dd68b3

(Sorry was to lazy to check the history ^^).

@rtimmons Did you try dev or the current release?

Good to see somebody took a stab at this, but unfortunately it's still not quite right - I tried on 0.105.0b4 and got essentially the same stack-trace.

Limiting parallel requests is a nice heuristic to try to avoid browning out the Hue hub or working around volatile issues, but ultimately it is a stopgap. Many HTTP APIs are known flaky, and the de-facto solution is to retry (perhaps with exponential backoff)...

I'd be curious to try and apply your fix @domibarton to see if it works for me. If it works, then I'd be happy to help getting it upstreamed.

@rtimmons let's try to improve the changes on d91dd68b31d5642e17c9fffff2f161f673113482 a bit further. Limiting is nice, but it would also be nice if we can add some catch & retry directly on the bridge. What do you think?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Elmardus picture Elmardus  ·  3Comments

sibbl picture sibbl  ·  3Comments

arangates picture arangates  ·  3Comments

i-am-shodan picture i-am-shodan  ·  3Comments

neonandu picture neonandu  ·  3Comments