TP-Link Switches going "Unavailable"

Just adding my 2 cents here.
I have 15 TP-Link switches in my house (HS200 and HS220). The switches where going unavailable many times a day. Even the one next the router (an old Asus RT-N66U) would be unavailable even though it was more stable than the one at the other end of the house which loses signal more frequently.

I just got a new router (Orbi AX6000) 2 days ago and since the last 2 days not a single switch became unavailable.

The switches are using the TP-Link integration and none of them are using static ip.

Since they are behind drywall and in a metal enclosure maybe they have difficulties getting a good signal.
Just hope the new router helps and it stays like this.

@rcblackwell likewise triggering the switch from the lovelace user interface is “instantaneous”.
I don’t know if the “turn ON” automation to switch a light on happens at 6:00:00 PM or 6:00:30 PM, but I know for sure that the triggering of one event in the TP-Link integration with another, takes “forever” (e.g. approaching 30 seconds :wink:

YetAnotherDave

I managed to build a Linux Debian 10.6 server and copy the configuration files from the NAS to the new HA server over the weekend. Sad to say, performance of the Automation (Kasa Switches) is exactly the same. The routine takes about 25 seconds to execute. I’d say the issue is not related to the QNAP NAS, or in your case the RPi. It seems to be related to HA or more likely the TP-Link integration. Monitoring switch position from Lovelace I see the first switch takes about 25 seconds to report back its new position. As soon as the status of the switch changes the second switch operates. It seems status reporting is delayed thus causing a delay in the Automation.

Thoughts?

@rcblackwell your conclusion is sound. I too lean towards the delay being contained in the TP-Link integration.

Thanks for running the Debian test; it reinforces the suspicions. I don’t have the skills to examine any related source code in GitHub.

Aside from operating independently of the TP-Link severs, my favorite feature with HA is to be able to turn on lights with an “offset” from sundown as it gets dark inside, sooner than it gets dark outside. I have not made any special accommodation for cloudy days (yet).

Same here.

Another thing I discovered is that dimmer switches (HS220) are not discovered by the integration. There was a need to add their ip addresses manually in the configuration.yaml file.

Is anyone watching this thread familiar with this integration and willing to look into these issues?

Regards

For the time being to fix the unavailable tplink issues, you need to run the modified tplink component as a custom component (or overwrite the HA version). These changes will fix the issue but we have been having trouble getting them approved.

TheGardenMonkey’s latest changes/pull request: https://github.com/home-assistant/core/pull/39762

My pull request which is based off TheGardenMonkey’s fix: https://github.com/home-assistant/core/pull/35460

2 Likes

@MarkHofmann11 Thanks for the github links.

Do you have any insight on the “status reporting delay” when one switch action is used to trigger another? (referenced above by @rcblackwell)

I had a similar problem with a new HS210 switch - where the status of the switch lagged. Switch would turn on instantly, but the toggle would switch back to off and then back on again due to lag in status.

I fixed that one by making the following changes to switch.py in the tplink component in HA.

    def turn_on(self, **kwargs):
        """Turn the switch on."""
        self.smartplug.turn_on()
        self.update_state()

    def turn_off(self, **kwargs):
        """Turn the switch off."""
        self.smartplug.turn_off()
        self.update_state()

Add the “self.update_state()” to both the def statements like shown above. I really am trying to get all these fixes in place and into HA.

I can zip up my entire modified tplink component if that makes things easier. I’m using it with the latest HA version 115 and no issues at all. We realize these are work-arounds, but at least they work until we have the re-written integration using the latest python-kasa library.

Thanks!!! I’ll do my best to find the switch.py file. :grinning:

I just uploaded my current modified tplink component files, here: https://github.com/home-assistant/core/issues/35137#issuecomment-705819808 That is what I am using right now with no problems.

1 Like

I downloaded TPlink.zip to my WIndows system. Unzipped it and then copy the TPlink folder to /config/custom_components on my RPi4… (SMB) then restarted hassio/server management . I didn’t see anything in the the log to show that I was running anything “different”, so I went to Supervisor -> System and rebooted… still not sure what to look for in the log…

No operational change… (all TP-link devices available) still experience a 15 - 25 second lag from the time I press an HS200 switch to the time the switch status changes in the lovelace UI.

  1. should the folder in custom_components be TPlink or tplink ?
  2. did your changes address the switch status reporting “lag”?
  3. should I be posting these questions on the github site?

Your help is very much appreciated!!

All of my TP-Link devices are on a separate wireless VLAN from my RPi4/HA server. Because of this I do not expect the TP-link integration to discover my devices. I set discovery: false, and explicitly list all of my TP-link device IP addresses.

@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