TPLink Devices constantly disconnect/reconnect, but only when I block them [SOLVED]

So I have about 20 TPLink smart plugs/switches. I have been blocking them from Internet access for a few years for the older devices and also have added new ones as I get them. Recently, my Pi-Hole suffered from a bad SDCard which took me a few days to replace. During this time, I believe all my devices received a FW update and now that Pi-Hole is back in place, most of these devices are continually disconnecting and reconnecting. If I turn the block off, they discontinue this behaviour. Once I turn off the block and it clears up, I can reenable it and all is good for about 24hrs, then it starts all over again.

I do not need remote access directly to these devices, as HA handles them fine, which I do have remote access to.

Any idea how to fix this? I don’t want these devices talking to the cloud at all, but it seems they will not function reliably unless they do.

This is what it looks like in the HA log whenever these devices disconnect/reconnect:

2023-09-30 21:53:16.797 ERROR (MainThread) [homeassistant.components.tplink.coordinator] Error fetching 192.168.254.226 data: Unable to connect to the device: 192.168.254.226:9999: 
2023-09-30 21:54:06.830 INFO (MainThread) [homeassistant.components.tplink.coordinator] Fetching 192.168.254.226 data recovered

Maybe I can redirect the DNS or something for these devices to a sandbox? I have been fighting with this for several days now. Ugh!!

EDIT: The Kasa app used to have a remote control switch for each device. This now only shows up on one single device I have.

I think I recall seeing somewhere that the newer firmware will continually check for internet access, and reboot if it isn’t available.

It’s too bad. The TPLink hardware was pretty decent for the price. I fear some day I’m going to be working on my router and inadvertently disable the blocking as you did.

I’d love to hear if anyone has found a solution to this problem.

Apparently TP-Link is not admitting to this. The URLs the devices are talking to are n-devs.tplinkcloud.com, n-use1-devs.tplinkcloud.com and use1-api-tplinkra.com. They also access time.nist.gov which should be fine, but I don’t use the built-in timers so still irrelevant.

Per some advice over on the DD-WRT forums (which is the firmware my routers run), it has been suggested to simply re-direct these requests to a different (even local) server. This can be done using the router’s built-in DNSMasq additional options. So I have added these to it.

address=/tplinkcloud.com/0.0.0.0
address=/tplinkra.com/0.0.0.0

The 0.0.0.0 can be any address you want to re-direct the requests to.
Currently testing this and I will post my results later.

In an attempt to better trouble shoot this issue, I am presenting a list of all my TPLink devices with both HW and FW versions. I have redacted the MAC addresses and Location data. This list was obtained using the Python program Kasa on Linux which is available here (should also work on Windows with Python3 installed):

== Garage Window Fan - HS103(US) ==
	Host: 10.1.0.224
	Device state: True
	== Generic information ==
	Time:         2023-10-02 12:21:55 (tz: {'index': 18, 'err_code': 0}
	Hardware:     2.1
	Software:     1.1.4 Build 210409 Rel.113427
	MAC (rssi):   REDACTED (-42)
	== Modules ==
	+ <Module Schedule (schedule) for 10.1.0.224>
	+ <Module Usage (schedule) for 10.1.0.224>
	+ <Module Antitheft (anti_theft) for 10.1.0.224>
	+ <Module Time (time) for 10.1.0.224>
	+ <Module Cloud (cnCloud) for 10.1.0.224>

== Garage Floor Lamp  - HS103(US) ==
	Host: 10.1.0.220
	Device state: True
	== Generic information ==
	Time:         2023-10-02 12:21:55 (tz: {'index': 18, 'err_code': 0}
	Hardware:     2.1
	Software:     1.1.4 Build 210409 Rel.113427
	MAC (rssi):   REDACTED (-37)
	== Modules ==
	+ <Module Schedule (schedule) for 10.1.0.220>
	+ <Module Usage (schedule) for 10.1.0.220>
	+ <Module Antitheft (anti_theft) for 10.1.0.220>
	+ <Module Time (time) for 10.1.0.220>
	+ <Module Cloud (cnCloud) for 10.1.0.220>

== Garage Guinness Neon - HS103(US) ==
	Host: 10.1.0.219
	Device state: False
	== Generic information ==
	Time:         2023-10-02 12:21:55 (tz: {'index': 18, 'err_code': 0}
	Hardware:     2.1
	Software:     1.1.4 Build 210409 Rel.113427
	MAC (rssi):   REDACTED (-47)
	== Modules ==
	+ <Module Schedule (schedule) for 10.1.0.219>
	+ <Module Usage (schedule) for 10.1.0.219>
	+ <Module Antitheft (anti_theft) for 10.1.0.219>
	+ <Module Time (time) for 10.1.0.219>
	+ <Module Cloud (cnCloud) for 10.1.0.219>

== Garage Side Light - HS200(US) ==
	Host: 10.1.0.225
	Device state: False
	== Generic information ==
	Time:         2023-10-02 12:21:56 (tz: {'index': 18, 'err_code': 0}
	Hardware:     5.0
	Software:     1.0.10 Build 230518 Rel.203102
	MAC (rssi):   REDACTED (-36)
	== Modules ==
	+ <Module Schedule (schedule) for 10.1.0.225>
	+ <Module Usage (schedule) for 10.1.0.225>
	+ <Module Antitheft (anti_theft) for 10.1.0.225>
	+ <Module Time (time) for 10.1.0.225>
	+ <Module Cloud (cnCloud) for 10.1.0.225>

== Spare 1 (garage) - HS103(US) ==
	Host: 10.1.0.218
	Device state: True
	== Generic information ==
	Time:         2023-10-02 12:21:55 (tz: {'index': 18, 'err_code': 0}
	Hardware:     2.1
	Software:     1.1.4 Build 210409 Rel.113427
	MAC (rssi):   REDACTED (-38)
	== Modules ==
	+ <Module Schedule (schedule) for 10.1.0.218>
	+ <Module Usage (schedule) for 10.1.0.218>
	+ <Module Antitheft (anti_theft) for 10.1.0.218>
	+ <Module Time (time) for 10.1.0.218>
	+ <Module Cloud (cnCloud) for 10.1.0.218>

== Garage Door Outside Lights - HS200(US) ==
	Host: 10.1.0.226
	Device state: False
	== Generic information ==
	Time:         2023-10-02 12:21:55 (tz: {'index': 18, 'err_code': 0}
	Hardware:     5.0
	Software:     1.0.10 Build 230518 Rel.203102
	MAC (rssi):   REDACTED (-43)
	== Modules ==
	+ <Module Schedule (schedule) for 10.1.0.226>
	+ <Module Usage (schedule) for 10.1.0.226>
	+ <Module Antitheft (anti_theft) for 10.1.0.226>
	+ <Module Time (time) for 10.1.0.226>
	+ <Module Cloud (cnCloud) for 10.1.0.226>

== Power Mon Asc - EP25(US) ==
	Host: 10.1.0.233
	Device state: True
	== Generic information ==
	Time:         2023-10-02 12:21:56 (tz: {'index': 18, 'err_code': 0}
	Hardware:     1.0
	Software:     1.0.10 Build 230423 Rel.134727
	MAC (rssi):   REDACTED (-36)

	== Current State ==
	<EmeterStatus power=0.0 voltage=122.264 current=0.0 total=0.484>

	== Modules ==
	+ <Module Schedule (schedule) for 10.1.0.233>
	+ <Module Usage (schedule) for 10.1.0.233>
	+ <Module Antitheft (anti_theft) for 10.1.0.233>
	+ <Module Time (time) for 10.1.0.233>
	+ <Module Cloud (cnCloud) for 10.1.0.233>
	+ <Module Emeter (emeter) for 10.1.0.233>

== Energy Monitor Sw1 - EP25(US) ==
	Host: 10.1.0.232
	Device state: False
	== Generic information ==
	Time:         2023-10-02 12:21:56 (tz: {'index': 18, 'err_code': 0}
	Hardware:     1.0
	Software:     1.0.10 Build 230423 Rel.134727
	MAC (rssi):   REDACTED (-38)

	== Current State ==
	<EmeterStatus power=0.0 voltage=122.296 current=0.0 total=0.0>

	== Modules ==
	+ <Module Schedule (schedule) for 10.1.0.232>
	+ <Module Usage (schedule) for 10.1.0.232>
	+ <Module Antitheft (anti_theft) for 10.1.0.232>
	+ <Module Time (time) for 10.1.0.232>
	+ <Module Cloud (cnCloud) for 10.1.0.232>
	+ <Module Emeter (emeter) for 10.1.0.232>

== Arbor Lights - HS105(US) ==
	Host: 10.1.0.215
	Device state: False
	== Generic information ==
	Time:         2023-10-02 12:21:56 (tz: {'index': 18, 'err_code': 0}
	Hardware:     1.0
	Software:     1.5.6 Build 191114 Rel.104204
	MAC (rssi):   REDACTED (-63)
	== Modules ==
	+ <Module Schedule (schedule) for 10.1.0.215>
	+ <Module Usage (schedule) for 10.1.0.215>
	+ <Module Antitheft (anti_theft) for 10.1.0.215>
	+ <Module Time (time) for 10.1.0.215>
	+ <Module Cloud (cnCloud) for 10.1.0.215>

== Garage Bookshelf Lamp - HS105(US) ==
	Host: 10.1.0.216
	Device state: True
	== Generic information ==
	Time:         2023-10-02 12:21:55 (tz: {'index': 18, 'err_code': 0}
	Hardware:     1.0
	Software:     1.5.6 Build 191114 Rel.104204
	MAC (rssi):   REDACTED (-32)
	== Modules ==
	+ <Module Schedule (schedule) for 10.1.0.216>
	+ <Module Usage (schedule) for 10.1.0.216>
	+ <Module Antitheft (anti_theft) for 10.1.0.216>
	+ <Module Time (time) for 10.1.0.216>
	+ <Module Cloud (cnCloud) for 10.1.0.216>

== TP-LINK_Smart Plug_3AA9 - EP40(US) ==
	Host: 10.1.0.229
	Device state: False
	== Plugs ==
	* Socket 'Front Porch Left' state: False since None
	* Socket 'Front Porch Right' state: False since None

	== Generic information ==
	Time:         2023-10-02 12:21:55 (tz: {'index': 18, 'err_code': 0}
	Hardware:     1.0
	Software:     1.0.3 Build 220803 Rel.172301
	MAC (rssi):   REDACTED (-53)
	== Modules ==
	+ <Module Antitheft (anti_theft) for 10.1.0.229>
	+ <Module Schedule (schedule) for 10.1.0.229>
	+ <Module Usage (schedule) for 10.1.0.229>
	+ <Module Time (time) for 10.1.0.229>
	- <Module Countdown (countdown) for 10.1.0.229>
	- <Module Emeter (emeter) for 10.1.0.229>

== Hallway 3 Way - KS230(US) ==
	Host: 10.1.0.227
	Device state: False
	== Generic information ==
	Time:         2023-10-02 12:21:56 (tz: {'index': 18, 'err_code': 0}
	Hardware:     1.0
	Software:     1.0.14 Build 220127 Rel.124555
	MAC (rssi):   REDACTED (-34)
	== Modules ==
	+ <Module Schedule (schedule) for 10.1.0.227>
	+ <Module Usage (schedule) for 10.1.0.227>
	+ <Module Antitheft (anti_theft) for 10.1.0.227>
	+ <Module Time (time) for 10.1.0.227>
	+ <Module Cloud (cnCloud) for 10.1.0.227>
	- <Module Motion (smartlife.iot.PIR) for 10.1.0.227>
	- <Module AmbientLight (smartlife.iot.LAS) for 10.1.0.227>

== TP-LINK_Smart Plug_325F - EP40(US) ==
	Host: 10.1.0.230
	Device state: False
	== Plugs ==
	* Socket 'Back Porch Left' state: False since None
	* Socket 'Back Porch Rt' state: False since None

	== Generic information ==
	Time:         2023-10-02 12:21:55 (tz: {'index': 18, 'err_code': 0}
	Hardware:     1.0
	Software:     1.0.3 Build 220803 Rel.172301
	MAC (rssi):   REDACTED (-62)
	== Modules ==
	+ <Module Antitheft (anti_theft) for 10.1.0.230>
	+ <Module Schedule (schedule) for 10.1.0.230>
	+ <Module Usage (schedule) for 10.1.0.230>
	+ <Module Time (time) for 10.1.0.230>
	- <Module Countdown (countdown) for 10.1.0.230>
	- <Module Emeter (emeter) for 10.1.0.230>

== Back Porch - HS220(US) ==
	Host: 10.1.0.228
	Device state: False
	== Generic information ==
	Time:         2023-10-02 12:21:56 (tz: {'index': 18, 'err_code': 0}
	Hardware:     3.0
	Software:     1.0.10 Build 230427 Rel.165239
	MAC (rssi):   REDACTED (-46)
	== Modules ==
	+ <Module Schedule (schedule) for 10.1.0.228>
	+ <Module Usage (schedule) for 10.1.0.228>
	+ <Module Antitheft (anti_theft) for 10.1.0.228>
	+ <Module Time (time) for 10.1.0.228>
	+ <Module Cloud (cnCloud) for 10.1.0.228>
	- <Module Motion (smartlife.iot.PIR) for 10.1.0.228>
	- <Module AmbientLight (smartlife.iot.LAS) for 10.1.0.228>

== Sun room - HS103(US) ==
	Host: 10.1.0.234
	Device state: False
	== Generic information ==
	Time:         2023-10-02 12:21:56 (tz: {'index': 18, 'err_code': 0}
	Hardware:     1.0
	Software:     1.5.7 Build 191114 Rel.105922
	MAC (rssi):   REDACTED (-59)
	== Modules ==
	+ <Module Schedule (schedule) for 10.1.0.234>
	+ <Module Usage (schedule) for 10.1.0.234>
	+ <Module Antitheft (anti_theft) for 10.1.0.234>
	+ <Module Time (time) for 10.1.0.234>
	+ <Module Cloud (cnCloud) for 10.1.0.234>

The Android Kasa App I am running is v3.3.501

Okay good news. After changing the above code from 0.0.0.0 to my internal web server IP, this seems to have fixed the issue. I can now see in Wireshark all my TPLink devices are being redirected from dev.tplinkcloud.com to this internal server, which replies with an ACK=1, and then these devices happily go back to sleep without rebooting or resetting dhcp (not exactly sure what they are doing, but the wall switches would flash their WiFi indicator every time this would happen).

Anyway, I still think it would be good thing for us to compare HW/FW version from the above post and try to figure out what FW versions actually creates this issue.

1 Like

That is good news about the fix - though it still seems odd to me that even devices you did not update started behaving this way as well.

As much as I’d love to provide the level of detail about my devices that you provided using that script, all my IOT devices are on a separate VLAN that does not have the ability to communicate with any of my other networks (security first! Can’t be having a botnet LOL), so I have no way of discovering them, and - no disrespect, but I’m not about to go modifying my firewall rules and a bunch of other stuff just to make that happen, so… Sorry!

But - for the devices I have that show online in the app, here’s the hardware version and FW version. I do have some HS103s, but they show offline in the app. Not sure why, but likely related to a power outage over the weekend that caused me all sorts of grief.

KS230 HW v1.0 FW v1.0.10
HS200 HW v5.0 FW v1.0.2
HS210 HW v3.0 FW v1.0.2
HS220 HW v3.0, FW v1.0.3

None of my devices are experiencing any issues with local control via HA at all - even those that show offline in the KASA app.

I’ll be sure to follow along to this thread in case any additional info becomes available. :slight_smile:

While I consider this fix somewhat of a kludge, at least it is working, until a better solution is at hand. When these devices disconnect, it is usually for around 1 minute, but it seems that once it starts, it keeps becoming more and more frequent.

I too have all my Smart Devices on a VLAN. My main Linux PC has dual NICS so one is configured on this VLAN so I can monitor and have access to them. In fact I have three VLANs. Guest, Media (for smart TVs, Alexa and Media players) and IoT. All people running a smart home should consider doing this for sure but with a large network it will require Managed Switches, unless completely wireless.

Thanks for your HW/FW list. Most appreciated!

EDIT: For what it’s worth, you can test if your devices are connecting to outside your LAN by turning off your WiFi on your mobile device, then run the Kasa app and see if any devices show up as being Online. If blocked correctly, NONE should be available for remote control.

I have a network for my personal wired devices, a network for my work system, a network for my wife’s work system, a network for our personal wireless devices, a network for my IP security cameras, a network for my IOT devices, and a guest network. Some have SSIDs associated with the VLAN, some do not. I have managed switches (Ubiquiti) and 6 APs.

I agree that everyone should segment their environments, but I learned long ago to stop trying to convince people. There’s a massive knowledge chasm that needs crossed. If people start trying to cross it and look like they’re going to fall, I’ll reach out and grab them - but I LONG ago gave up trying to grab people on the other side and pull them across. Doesn’t work. LOL

1 Like

I have found a much better solution. While working with the author of python-kasa (linked above), he gave me a command that will unbind the devices from the tplink acct therefore allowing me to remove blocks and redirects from my router. This works perfectly.

kasa --debug --host 192.168.*.* raw-command cnCloud unbind

The --debug flag is optional, but does return some good and interesting information.

5 Likes

BTW, this python-kasa command should really be included in Home Assistant releases. It’s too handy not to have.

Things have apparently changed in python-kasa. I get the following error:

No --type or --device-family and --encrypt-type defined, discovering…
WARNING:root:Deprecated, use ‘kasa command --module cnCloud unbind’
Got error: SmartDeviceException(“Error on cnCloud unbind: {‘err_code’: -24, ‘err_msg’: ‘no reply from server’}”)

I haven’t figured out the correct combination to make the suggested command work. I’m not sure where to insert the host ip. Also redirecting the dns entries as suggested earlier in the thread haven’t worked for me either

Any thoughts?

Edit: I tried:

kasa --host 192.168.3.9 command --module cnCloud unbind

And that returned the exact same error message as above:

SmartDeviceException(“Error on cnCloud unbind: {‘err_code’: -24, ‘err_msg’: ‘no reply from server’}”)

Maybe I’m doing something wrong on my end?

What OS are you trying this from? Also, I just tried it and it still worked for me. Your command structure is not the same as shown above.

kasa --host 192.168.1.220 raw-command cnCloud unbind

This worked.
If you would happen to get this error:

Got error: SmartDeviceException("Error on cnCloud unbind: {'err_code': -8, 'err_msg': 'not bind yet'}")

The device was not yet bound to the cloud.

I’m trying to do this from windows 10.

When I tired the commend like you listed it said it was deprecated and suggested what I used.

My switches have never connected to the internet. Should I let them do that first?

I would not do that. If they have never connected to the Internet, I would just leave well enough alone. Maybe the command is deprecated for the device type you are using? What is the device and what version of kasa are you using?
kasa --version
Mine is kasa, version 0.5.1

I have an HS220 and a couple HS200s. They are all 1.0.10

What is the version of the kasa python script? Mine is 0.5.1.
Just type “kasa --version” to retrieve it.

Oh, I see that v6.0 was released a few months ago:

Yeah, I have version 0.6.2.1

I will try to mess with the latest version over the weekend. It is quite different and supports the new Mater protocol and a few backported older devices that may have had their fw updated. I don’t want to break what I have working so I may have to jump though some hoops to test it without deleting my 0.5.1 version. All my computers are Linux (no Windows in the house) so this should be pretty straight forward, unlike on Windows.

1 Like