TP-Link Kasa on an internal WiFi network

If you’re trying to configure a TP-Link device on a Wifi without internet access, here’s how.

Download the Kasa app to your phone. Go through the wizard normally, and when you get to network selection, tell the device to connect to your “internal” network. The device light will go blue to tell you it connected, but the app will say it failed (because the device can’t phone home to TP Link’s server). This is fine. You’re done with the TP Link app.

Now, use whatever utility you have to find the device’s IP Address. Mine showed up as HS-103. Note the IP address.

Now, in the Paper UI, (and with “TP-Link Smart Home Binding” installed) attempt to manually add the device. You provide your desired name and the IP address, and just put some random string in the “Device ID” field. Save this, and after a few moments, the device will show “offline” with an error that the DeviceID you entered doesn’t match the device’s id of “correct-id-of-the-device”. Just copy this correct ID back into the configuration and voila, it should connect. You’re good to go create your items (in my case, just a switch).

Background:

I don’t like devices “phoning home” when I don’t need to use their cloud service. I have one SSID on my network for IOT that can connect on the LAN but is blocked from the internet, and another that can ONLY connect to the internet.

Since the KASA device is IP, I wanted to put it in the IOT-Internal-Only group and stop it from connecting to TP Link servers. I know that means it can’t be used from the app, and that’s fine by me because I want OpenHab to “own” it. So I bootstrapped it with the Kasa app, and connected it to OpenHAB as described above.

1 Like

I would think this step could be simpler by just using discovery in PaperUI. Then it just find the ip address and will also set the id directly. And even if you would add it manually leave the id field blank and it will be set by the binding to the correct value.

My kasa app does not let me do this, I have no internet on my wifi network and I cannot connect to my switch (hs-200) for anything.

@Racerflea: Bear in mind that without internet access, the Kasa app will report an error after you tell the device to connect to your network. You can ignore that … Kasa is throwing an error because it couldn’t connect to it’s cloud server. If you gave it the correct wifi credentials, the device should be on your network, despite the error. If your router has a web UI that lists clients, you should see it there, or you could use something like Advanced IP Scanner to look for it. I added an HS103 and a KP400 using this method, no sweat.

@hilbrand: Ahhhh, better. I’ll try that when I add the next one. Thanks!

@hilbrand I just tried it using discovery, but it didn’t work. Not surprising, since it is on a separate VLAN from the OH server. Not really an issue to add it manually, though. Thanks!

Just curious what you all use for refresh rate in the paper UI ?, does 1 sec mean it is updating the device every second as this seems excessive ?

My Kasas are set to one second, only because I never thought to monkey with the default value. There’s no discernable impact on my WiFi network, and I have about 10-15 of them in play. I assume Hilbrand had a reason for making that the default.

Only the switches are on 1 second, to get fast feedback if someone uses the switch.

2 Likes

You can easily configure your TP-LINK Kasa wifi connection using the NODE-based tplink-smarthome-api (GitHub - plasticrake/tplink-smarthome-api: TP-Link Smarthome WiFi API) cli and a computer with wifi. This is tested with EU HS100 and HS110 and E27 LB110 and LB120. To configure the devices, proceed as follows:

  1. Short reset the device so it sets into connection mode (3 power on cycles for the bulbs and pressing the cog button till wifi LED turns to orange). Then, the device will create a open wifi AP named “TP-LINK_Smart Plug/Bulb_[MAC_5_6]”.
  2. Connect the computer wifi to that AP. If using Windows 10, it will think twice before connecting to that wifi.
  3. Using the terminal issue the following command, replacing SSID and password second fields with the correct values. The IP must be 192.168.0.1 and I had to escape all the quotation marks to make it work:
    tplink-smarthome-api send -u -D 192.168.0.1 "{\"netif\":{\"set_stainfo\": {\"ssid\":\"SSID\",\"password\":\"password\",\"key_type\":3}}}}"
  4. The device will start connecting to the new network and if it is successful, the wifi LED will turn into green (for plugs) or fade out and in (for bulbs).

This works like a charm and saves me plenty of time when any of the bulbs reset due to too fast power on and off cycles.

1 Like

That technique has apparently been blocked. It results in an error: ‘netif’ not supported module.

Which device are you using? Maybe a HS100/110 UK plug HW 4.1? If so, the rear port was disabled due to a FW update (1.1.1). I have just tried a HS100 EU HW 3.1 and worked fine, but it was blocked from internet long time ago and never updated. More info at https://github.com/plasticrake/homebridge-tplink-smarthome/issues/154

Tip, I only blocked TCP connections from my devices but not UDP, so DNS and NTP keep working to be able to use the builtin scheduler.

You are correct: I should have been more specific. This was a just-purchased KL135. The app says the bulb firmware version is 1.0.6.

The original technique of using the app to get it connected worked, mostly. The “device Id” tip is priceless. I tried everything from the isolated network, but the Kasa app refused to function. I did the following:

  • Hook phone up to nominal 5GHz WiFi network with internet connection (where the bulb cannot connect).
  • Fire up the app - letting it snoop on whatever it wants (e.g. location information).
  • Put the bulb in find-me mode (on/off three times).
  • The app found it and asked me to connect my phone to the right WiFi network.
  • Switch phone to the isolated 2GHz network.
  • It hooked up.
  • The app, amazingly, has the MAC address under Device Info.
  • Cross-referenced that with the DHCP leases (openHAB Pi machine is also the WAP and DHCP server).
  • Manually added the Thing using the “use any id” technique, above.
  • The error message does contain the correct Id.
  • Entered that and all was happy.

One more thing: The Pi does not let anything cross from WiFi to wired (no iptables rules at all). I’m just starting this adventure and I haven’t needed it, yet. However, I ran that command from a Windows 10 machine. The response was from the bulb, not the script itself, so UDP was flowing.

This device is not compatible with this API. I don’t know if there is any support for TP-Link newest devices neither a way to communicate with them without using their cloud.

I’m not surprised - the joys of proprietary protocols. Thanks for checking/confirming.

Note that the openHAB TP-Link binding works with it just fine - once you managed to get the Thing created.

The TP-Link binding communicates directly with Kasas, so you just have to use the Kasa app to add them to your network. If your router allows you to modify settings, you can then deny them Internet access and they’ll work just fine on your local network.