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

TP-Link/Kasa integration frequent problem with connection or updating #93312

Closed dolfs closed 7 months ago

dolfs commented 1 year ago

The problem

I see two kinds of errors with Kasa integration frequently in my logs:

Both errors happen on more than one Kasa smart socket/plug, happen frequently. The example above both represent the same plug (it is a plug on a HS300, but I also see it with KP1125 devices etc.). Whenever I see this and check with a network utility the devices are listed as on-line, respond to ping, and show as "everything fine" in the KASA app.

Overall functionality seems largely unaffected, but the logs are being swamped with these messages.

What version of Home Assistant Core has the issue?

2023.5.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

TP-Link/KASA

Link to integration documentation on our website

No response

Diagnostics information

config_entry-tplink-cb4a0b8013ed0f6cb9971a2397e05853.json.txt

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

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
  • Unable to connect to the device: 192.168.10.164

This just indicates that the connection is broken for a reason or another, but does not give any other hints why that may be happening.

Are you seeing any other error message after that in the logs? You could try to enable debug logging to get more information, if nothing else is not shown.

jasonalsing commented 1 year ago

I'm having similar issue, I have 2 HS103 plugs (2-pack same box) and one in my office shows "unavailable" every few minutes for about 10 seconds. Now my WiFi isn't "Great" in the office but according to the AP this plug is at -70dbm so should be fine (my house isn't that big) and non-Kasa devices seem to work solid in far worse conditions.

However to note, the second plug as a test I plugged into in my "game room" which is 20 ft from the AP (-46dbm) and it seems to stay connected 100% at least for the last 24 hrs or so,

Logger: homeassistant.components.tplink.coordinator Source: helpers/update_coordinator.py:229 Integration: TP-Link Kasa Smart (documentation, issues) First occurred: July 8, 2023 at 4:30:21 PM (1360 occurrences) Last logged: 9:20:02 PM

Error fetching 192.168.66.236 data: Unable to query the device 192.168.66.236: Error fetching 192.168.66.236 data: Unable to connect to the device: 192.168.66.236: Error fetching 192.168.66.236 data: Unable to connect to the device: 192.168.66.236: [Errno 113] Connect call failed ('192.168.66.236', 9999)

rytilahti commented 1 year ago

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

bdraco commented 1 year ago
Updating state for sensor.plug_6_current_consumption (<class 'homeassistant.components.tplink.sensor.SmartPlugSensor'>) took 0.705 seconds

That duration indicates you might have something blocking your event loop.

Can you try putting asyncio in debug mode? https://docs.python.org/3/library/asyncio-dev.html#debug-mode

You can also do this by enabling debugpy: in configuration.yaml

Than look for any asyncio messages in the raw log (download in the UI)

bdraco commented 1 year ago

It looks like the timeout is only 5s https://github.com/python-kasa/python-kasa/blob/064e3fe560789c0eb832002b4513124f114e1075/kasa/protocol.py#L76C43-L76C58

https://github.com/python-kasa/python-kasa/blob/064e3fe560789c0eb832002b4513124f114e1075/kasa/protocol.py#L37

With esphome we found it could take up to ~25 seconds to establish a connection with poor wifi which is why we bumped the timeout to 30s https://github.com/esphome/aioesphomeapi/blob/3bb2c085e618e4bb1e4be72105ba00bc99f560d0/aioesphomeapi/connection.py#L72

bdraco commented 1 year ago

It probably makes sense to have a connect timeout of 30s and half of that for a read/write round trip to deal with poor Wi-Fi connections

bdraco commented 1 year ago

https://github.com/python-kasa/python-kasa/pull/494

jasonalsing commented 1 year ago

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

does not seem to be helping in my case (2023.8.1)

Vendivar commented 10 months ago

I am also having this same problem

ctml91 commented 8 months ago

Same problem. I'm not noticing any issues, just clutters the logs.

Logger: homeassistant.components.tplink.coordinator
Source: helpers/update_coordinator.py:322
Integration: TP-Link Kasa Smart ([documentation](https://www.home-assistant.io/integrations/tplink), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+tplink%22))
First occurred: 5:57:22 PM (3 occurrences)
Last logged: 6:15:51 PM

Error fetching 192.168.2.25 data: Unable to query the device 192.168.2.25:9999:
Error fetching 192.168.2.23 data: Unable to query the device 192.168.2.23:9999
wjb178 commented 8 months ago

I was also getting hundreds of the "Unable to connect to the device" log messages for a while. Many of the devices were also going unavailable for 1 second in the logbook. Occasionally the unavailable lights would cause an error in an automation.

It seems letting Tplink update the firmware on all the devices has corrected the problem for me. It's been 24 hours and I have no log messages and none of the devices have gone unavailable since.

I had always blocked the devices from internet access afraid of Tplink firmware updates blocking local access. I decided to take a chance and let all the devices update to the new firmware.

For reference I have 27 Tplink devices. Mix of HS200 switches, HS220 dimmers, KL125 bulbs and KP125 outlets. They connect to 2 tplink EAP245 wifi access points. Omada controller log shows no disconnects for any of the devices. All wifi signals are greater than 75 percent.

jhemak commented 7 months ago

Same as others:

2024-02-01 22:29:45.293 ERROR (MainThread) [homeassistant.components.tplink.coordinator] Error fetching 192.168.3.136 data: Unable to connect to the device: 192.168.3.136:9999: [Errno 113] Connect call failed ('192.168.3.136', 9999) 2024-02-02 01:59:00.301 ERROR (MainThread) [homeassistant.components.tplink.coordinator] Error fetching 192.168.3.136 data: Unable to connect to the device: 192.168.3.136:9999: [Errno 111] Connect call failed ('192.168.3.136', 9999) 2024-02-02 02:01:42.147 ERROR (MainThread) [homeassistant.components.tplink.coordinator] Error fetching 192.168.3.125 data: Unable to connect to the device: 192.168.3.125:9999: [Errno 111] Connect call failed ('192.168.3.125', 9999) 2024-02-02 02:11:58.541 ERROR (MainThread) [homeassistant.components.tplink.coordinator] Error fetching 192.168.3.136 data: Unable to connect to the device: 192.168.3.136:9999: [Errno 113] Connect call failed ('192.168.3.136', 9999)

DevSecNinja commented 7 months ago

Same as others with my HS110's (EU). Has been going on for quite a while so I'm not sure with what Home Assistant release the issue first started. The TP-Links are blocked from internet access on my firewall considering their actions of the past, so the firmware is probably old (Firmware: 1.5.6 Build 191125 Rel.083657).

In the logs I'm seeing two variants though:

ERROR (MainThread) [homeassistant.components.tplink.coordinator] Error fetching <ip> data: Unable to query the device <ip>:9999: 
ERROR (MainThread) [homeassistant.components.tplink.coordinator] Error fetching <ip> data: Unable to connect to the device: <ip>:9999: 
sdb9696 commented 7 months ago

These issues should be fixed in the latest HA release 2024.02.

sdb9696 commented 7 months ago

@home-assistant close