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
71.53k stars 29.91k forks source link

TP-Link Kasa KL400 light strips become unavailable when trying to set color #90636

Closed eengert closed 10 months ago

eengert commented 1 year ago

The problem

I installed a bunch of Kasa switches, plugs and light strips about 4 weeks ago. Up until a few days ago, I was integrating them into Homekit via Homebridge. Earlier last week I made the decision to migrate to HA. Everything has gone fairly smoothly except for the two light strips. They actually work fine to just turn them on/off (from HA or HK or Kasa app). But they’ve been intermittently going offline (unavailable). I finally figured out that it’s happening whenever I try to change the color. This started immediately after integrating them into HA. Doesn’t matter whether I change the color in HA or HK or Kasa, they will become unavailable in HA within ~30 seconds. They remain unavailable for ~60-90 seconds and then usually come back online. Didn’t have any problems with them when I was using Homebridge.

I’m running HA in Hyper-V on a mini PC, Win11 Pro. I’m using the TPLink and Homekit integrations to bridge the Kasa devices to Homekit.

I don’t think this is a networking issue. I have strong Wifi throughout the house, but certainly in the kitchen where the light strips are. I did assign an IP reservation for each, but it hasn’t made any difference.

What version of Home Assistant Core has the issue?

core-2023.3.6

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

tplink

Link to integration documentation on our website

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

Diagnostics information

config_entry-tplink-5a4a0d6441f3a32fdf6c68a73ac14fd1.json.txt home-assistant_2023-04-01T12-19-10.990Z.log

Example YAML snippet

No response

Anything in the logs that might be useful for us?

When the problem occurs, I see two entries in the log...

First:
Logger: homeassistant.components.tplink.coordinator
Source: helpers/update_coordinator.py:215
Integration: TP-Link Kasa Smart (documentation, issues)
First occurred: March 29, 2023 at 1:36:51 PM (5 occurrences)
Last logged: March 31, 2023 at 9:55:04 PM

Error fetching 192.168.0.110 data: Unable to query the device 192.168.0.110:
Error fetching 192.168.0.130 data: Unable to query the device 192.168.0.130:

Then:
Logger: homeassistant.core
Source: components/tplink/light.py:210
First occurred: March 31, 2023 at 9:55:04 PM (3 occurrences)
Last logged: March 31, 2023 at 9:55:07 PM

Error executing service: <ServiceCall light.turn_on (c:01GWX8CBNEXP7GM7KWBJZ2QFNK): entity_id=['light.under_cabinet_lights_right'], params=hs_color=(217.0, 10.0)>
Error executing service: <ServiceCall light.turn_on (c:01GWX8CG61D9FARQ6QHT8P8CC3): entity_id=['light.under_cabinet_lights_right'], params=hs_color=(0.0, 0.0)>
Error executing service: <ServiceCall light.turn_on (c:01GWX8CK1A45JG9YPJEEAKW159): entity_id=['light.under_cabinet_lights_right'], params=hs_color=(217.0, 10.0)>
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/kasa/protocol.py", line 112, in close
    await writer.wait_closed()
  File "/usr/local/lib/python3.10/asyncio/streams.py", line 343, in wait_closed
    await self._protocol._get_close_waiter(self)
  File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 862, in _read_ready__data_received
    data = self._sock.recv(self.max_size)
ConnectionResetError: [Errno 104] Connection reset by peer

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/kasa/smartdevice.py", line 251, in _query_helper
    response = await self.protocol.query(request=request)
  File "/usr/local/lib/python3.10/site-packages/kasa/protocol.py", line 73, in query
    return await self._query(request, retry_count, timeout)
  File "/usr/local/lib/python3.10/site-packages/kasa/protocol.py", line 163, in _query
    raise SmartDeviceException(
kasa.exceptions.SmartDeviceException: Unable to query the device 192.168.0.130: [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/core.py", line 1826, in catch_exceptions
    await coro_or_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1845, 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 686, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 961, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 726, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 572, in async_handle_light_on_service
    await light.async_turn_on(**filter_turn_on_params(light, params))
  File "/usr/src/homeassistant/homeassistant/components/tplink/entity.py", line 26, in _async_wrap
    await func(self, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/components/tplink/light.py", line 342, in async_turn_on
    await self._async_set_hsv(kwargs[ATTR_HS_COLOR], brightness, transition)
  File "/usr/src/homeassistant/homeassistant/components/tplink/light.py", line 210, in _async_set_hsv
    await self.device.set_hsv(hue, sat, brightness, transition=transition)
  File "/usr/local/lib/python3.10/site-packages/kasa/smartdevice.py", line 77, in wrapped
    return await f(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/kasa/smartbulb.py", line 391, in set_hsv
    return await self.set_light_state(light_state, transition=transition)
  File "/usr/local/lib/python3.10/site-packages/kasa/smartbulb.py", line 322, in set_light_state
    light_state = await self._query_helper(
  File "/usr/local/lib/python3.10/site-packages/kasa/smartdevice.py", line 253, in _query_helper
    raise SmartDeviceException(f"Communication error on {target}:{cmd}") from ex
kasa.exceptions.SmartDeviceException: Communication error on smartlife.iot.lightStrip:set_light_state

Additional information

Just to be clear, this happens every single time I change the color of either light strip. And it never happens if those light strips are not enabled in the HA TPLink integration.

home-assistant[bot] commented 1 year ago

Hey there @rytilahti, @thegardenmonkey, mind taking a look at this issue as it has been labeled with an integration (tplink) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `tplink` 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 tplink` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


tplink documentation tplink source (message by IssueLinks)

rytilahti commented 1 year ago

The device is closing the connection for some reason ([Errno 104] Connection reset by peer), but it's hard to say why or to offer any help.

You could try enabling the debug logging for kasa in your homeassistant logger configuration to see if something obvious is visible in the communication. Alternatively, feel free to try python-kasa directly to see if changing the color settings work outside homeassistant:

ChristopheKoeck commented 1 year ago

I have the same problem, but not only when you try to change the color, sometimes the become unavailable when you turn them on/off. Is there anything we can do to help get this resolved?

jdseaside commented 1 year ago

Also having this problem, but it isn't just home assistant. Trying to do anything other than on/off with a 3rd party app seems to overwhelm the hardware.

rytilahti commented 1 year ago

Please test if the upcoming 2023.7.4 release improves the situation and report back, thanks!

zackbennis commented 1 year ago

Please test if the upcoming 2023.7.4 release improves the situation and report back, thanks!

I'm on 2023.8 and still experiencing this issue.

phillipsbrad12 commented 1 year ago

I resolved this issue BEFORE the latest release by removing the KL400 device from both Home Assistant and removing it from the Kasa mobile app, then re-adding it to the Kasa mobile app, then re-adding it to Home Assistant. If you have a custom ID for it in Home Assistant, you will need to make a note of it before deleting it, as to not disrupt any automations when you re-add it to Home Assistant.

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