TP-Link Switches going "Unavailable"

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.

I have checked my hardware revision and mine are both HW 4.1 FW 1.1.0 (correction from my previous post). Mine a UK versions just to prevent any confusion.

Both of these units are brand new, purchased from Amazon in the last month so I would be very surprised that these were old stock. I have checked the units and the serial number gives no clues to the production date but I still have the boxes and will look when I next go in to the loft.

Very strange. Mine are also UK units and all were purchased from Curry’s PC World (not usually a retailer I would use but on both occasions were on massive black Friday promo). I can’t remember off the top of my head but the order with 2 units was purchased 2017/2018 and the order with 4 units was definitely end of 2019. I am assuming that the the 4 units with same HW/Firmware were delivered in the 2019 order, but I can’t rule out it being 2 x HW 2.1’s and 2 x HW 4.1s… it seems unlikely though… that’s a hell of a jump in hardware revisions for a massive retailer with high turn over to be sending out in the same order.

Edit: forgot to mention that my 4.1s were also accessible via the Kasa app like yours were. It’s just HA that couldn’t communicate with them.

Edit 2: So just looking at HW versions that others have, I never see any mention of 3.1 or any 3.x version. So I am guessing that at the end of 2019 was the tick over of the 2.1 to 4.1 versions, and my original order of 2 x units back in 2017/2018 were indeed 2.1 and in 2019, the four units most likely consisted of 2 x 2.1 and 2 x 4.1. So they’ll still be under warranty, but I don’t think this will help as it seems to be a 3rd party integration issue. The Kasa app is fine.

Is anyone familiar with how to create a ruleset in an edgerouter 4 to block the updates… (GUI) never really went beyond the default firewall settings… :grimacing: they all have static ips… my first attempt ended up blocking internet to everything… I created a group with all the tplink devices… but with the rules in the rulesets in the groups… I feel lost and can’t seem to find a clear explanation when googling

Before doing any firmware updates, especially for UK or EU hardware, you might want to check this thread:

@CaptTom - thanks for the link. This is rather annoying but it explains why they no longer work with HA.

I will have to consider the options going forward as they were otherwise good units.