TP-Link Switches going "Unavailable"

@YetAnotherDave I was going to try this out but I see you already have, without success. Thank you for taking the leap. Did you remove the TP-LINK integration prior to configuring manually?

Regards
Robert

Under the “custom_components” directory, you need to make a “tplink” directory - and then unzip the contents of the archive into that location. When you restart HA, you should see a message about it using the custom component.

The other option is to backup your current HA tplink data, and use the files in the archive. For Windows, this is the location on my system:

D:\homeassistant\Lib\site-packages\homeassistant\components\tplink

@markhofmann11 thanks!
I’ve got it running as a custom_component (changed the directory name from TPlink to tplink)

2020-10-09 11:14:26 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for tplink which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.

All is fine… but it does not address the 25 second lag from when I press an HS200 to also trigger an HS100 (this automation works instantaneously when I switch the HS200 via the lovelace UI)… I’ll open this as a separate thread.

doh! good call… I had not deleted the TP-LINK integration prior to configuring manually…

try 2: deleted and renamed TPlink -> tplink

@YetAnotherDave, Pleased to hear you managed install of the custom integration. I’ll follow you over to the new thread so I can follow along/contribute to the switch delay issue.

The good news is the tplink changes have been approved for merging into the dev HA version a few days ago. Hoping the fixes/modifications are included on the next release of HA.

4 Likes

@YetAnotherDave, thank you for your part in making this happen.

Much appreciated

I’m just an old hacker stumbling around in the fog. The thanks go to @MarkHofmann11 and GardenMonkey(on github) doing the real work. It’s always good to see what the kids are cooking up :wink:

1 Like

@MarkHofmann11, thank you for your part in making this happen.

1 Like

Great! I’ve been having a ton of my switches and dimmers go unavailable all of the sudden. Hopefully this merge fixes that.

Great news, when is the release due ? Still having a nightmare with mine

Any pointers :

2020-10-24 19:35:04 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for tplink which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.
2020-10-24 19:35:13 ERROR (MainThread) [homeassistant.components.switch] Error while setting up tplink platform for switch
Traceback (most recent call last):
File “/usr/local/lib/python3.8/site-packages/pyHS100/smartdevice.py”, line 115, in _query_helper
response = self.protocol.query(
File “/usr/local/lib/python3.8/site-packages/pyHS100/protocol.py”, line 47, in query
sock = socket.create_connection((host, port), timeout)
File “/usr/local/lib/python3.8/socket.py”, line 808, in create_connection
raise err
File “/usr/local/lib/python3.8/socket.py”, line 796, in create_connection
sock.connect(sa)
OSError: [Errno 113] Host is unreachable

Solved it. Router issue, now resolved after 2 hours on the router

Home Assistant release 0.117 dropped last night, I did the upgrade and the fix seems to have solved my issue completely so far (at least all day today since I upgraded at 1:30am EST). Thanks so much, this is amazing!

A few of my TP-Link switches went unavailable this morning but recovered quite quickly and I only knew by looking at the entity history, I never had anything fail and never got stuck with anything unavailable. Like others, before this upgrade my TP-Link switches were unavailable for hours throughout the day and never came back until I restarted HA or reloaded the TP-Link integration and then restarted HA…even then when any became unavailable only a restart would fix it temporarily so this fix has been great for me so far. Fingers crossed :crossed_fingers:t2:.

1 Like

Mark Hofmann, you are the man. THANK YOU!

Well, I spoke too soon. My TP-Link light switches seem alright now but noticing “unavailable” on 2 of my 4 TP-Link smart bulbs and my only TP-Link smart plug…I guess maybe it’s time to try a static IP and specifying it in my configuration?

My switches and lights have been fine for quite a while now.
They are still on dhcp, but have reservations on my Virgin Media router, so always get the same ip address.
If/when they do go unavailable, they normally show as local on the Kasa app as well.

Thanks go to TheGardenMonkey - I was just doing what I could to get this pushed past the finish line. We finally had (2) major fixes pushed through - which should address the main issues. There is still one outstanding issue that I’m working with TheGardenMonkey to get pushed out on the next version.

On a side note, I agree - run all tplink devices with static reservations. You don’t want them changing IPs if you can help it - they work much better with statics.

1 Like

Hi All,

I am relatively new to Home Assistant however with the comments in the thread I managed to get my three Kasa (2 x HS100 and 1 KP303) devices to connect without issue until this week.

I have been using the custom zip from MarkHofmann11, with static IP entries and no discovery. All of this was working until Tuesday night (lasted about 1 month). In the logs I saw that each of the switches (HS100) became unavailable and then the strip also dropped off. Nothing I did would restore the devices or entities.

At a similar time I had performed a number of updates on components however I am now not sure if I had 0.117.6 before or after the issue. However removing the custom integration gave me a blank box with no devices (i did not look at the logs).

Today I have deleted and reapplied the custom zip. After reloading I watched as it created the pycache and I get the following error in the logs

Logger: homeassistant.components.switch
Source: custom_components/tplink/switch.py:36
Integration: Switch (documentation, issues)
First occurred: 6:47:09 PM (1 occurrences)
Last logged: 6:47:09 PM

Error while setting up tplink platform for switch
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/pyHS100/smartdevice.py", line 115, in _query_helper
    response = self.protocol.query(
  File "/usr/local/lib/python3.8/site-packages/pyHS100/protocol.py", line 47, in query
    sock = socket.create_connection((host, port), timeout)
  File "/usr/local/lib/python3.8/socket.py", line 808, in create_connection
    raise err
  File "/usr/local/lib/python3.8/socket.py", line 796, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

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

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 197, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/tplink/switch.py", line 36, in async_setup_entry
    await hass.async_add_executor_job(device.get_sysinfo)
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.8/site-packages/pyHS100/smartdevice.py", line 196, in get_sysinfo
    return self._query_helper("system", "get_sysinfo")
  File "/usr/local/lib/python3.8/site-packages/pyHS100/smartdevice.py", line 120, in _query_helper
    raise SmartDeviceException('Communication error') from ex
pyHS100.smartdevice.SmartDeviceException: Communication error

None of the devices will connect.

However I have now manually copied the code from the dev information on the https://github.com/home-assistant/core/tree/dev/homeassistant/components/tplink

In this situation my KP303 works perfectly however I still get the errors from my two HS100 units which are using firmware 1.01

Logger: custom_components.tplink.common
Source: custom_components/tplink/common.py:150
Integration: TP-Link Kasa Smart (documentation)
First occurred: 6:54:02 PM (2 occurrences)
Last logged: 6:54:02 PM

Unable to communicate with device 10.0.3.15: Communication error
Unable to communicate with device 10.0.3.17: Communication error

All units have continued to be accessible via the Kasa app at all times and I can ping both devices.

So there seems to be something specifically wrong with the communication in relation to HS100 devices.

Any thoughts or more information i can provide?

I don’t know if this is of any help, but I have noticed a correlation:

I too was having intermittent issues with some of my HS100’s (I have 6 total), I read through some of this thread and have changed to manual discovery (they already had static IPs). Since moving to manual discovery, there is a clear split: 4 units are now rock solid. 2 units are still a PITA. I looked at the hardware/firmware revisions and:

  1. HW 4.1 FW 1.1.0
  2. HW 4.1 FW 1.1.0
  3. HW 2.1 FW 1.5.10
  4. HW 2.1 FW 1.5.10
  5. HW 2.1 FW 1.5.10
  6. HW 2.1 FW 1.5.10

First, what I found confusing was the HW Revision, 2.1 and 4.1. This is because the 2 units that are 4.1, were purhcased SEVERAL YEARS BEFORE the others. My first thought was that the 4 units with the 2.1 hardware revision must have been older stock, but they were all purchased from the same reputable retailer. I doubt this is the case.

So for me, at least, it looks like the manual discovery has provided enough stability for the 4 newer(?) units, but those 2 older(?) ones are looking like they might get Freecycled and replaced with Tradfri Zigbee units (which are solid by the way - I just wish they had a button!). If the hardware revisions are indeed correct, I am unsure why TP-Link have chosen to number their hardware revisions in this manner. If they incorrect (chronologically/logically speaking), and 4.1 is indeed older than 2.1 then this points to a clear issue with some of the older units (and the mental state of TP-Link engineers). In any case, I am sure I won’t be buying any more of these. It’s become a bit of a joke in our house, and Wife Approval Factor has waned significantly!

Hopefully this helps someone else who’s got a few of these and is only experiencing sporadic issues with some units.