Add TP-Link Kasa smart switches to Home Assistant (and fix "Failed to connect")
I have three Kasa HS200 wall switches running the lights in my shop. Adding them to Home Assistant should take two minutes, and for one of them it did. The other two failed with "Failed to connect" before they finally went in. Here's the whole setup, what's going on behind those errors, and how to tie the switches to a presence sensor so the shop lights take care of themselves.
The short version: turn on Third-Party Compatibility in the Kasa app first, give each switch a fixed IP address on your router, then add them with the built-in TP-Link Smart Home integration. Control runs over your own network, not the cloud.
- Cost
- $0 if you already have Kasa switches
- Time
- 10–20 minutes
- Difficulty
- Beginner
- Skills
- Using the Kasa app and Home Assistant settings
What you need
- Kasa switches, plugs or bulbs already set up in the Kasa app and working. Mine are HS200 single-pole switches; the same steps work for Kasa plugs, dimmers and power strips, and for TP-Link's Tapo devices.
- Home Assistant on the same network as the switches, at least while you add them.
- The email and password for your TP-Link (Kasa) account. Newer Kasa firmware asks for them during setup.
Step 1: turn on Third-Party Compatibility
TP-Link added a setting that decides whether apps other than its own can control your devices. It's off by default, and with it off, Home Assistant may find a switch but never get control of it.
In the Kasa app, go to Me → Settings → Third-Party Compatibility and turn it on. (In the Tapo app it's under Me → Third-Party Services.) TP-Link shows a warning that this lowers security a little, because a third-party app gets to talk to the devices. That's the trade for local control in Home Assistant.
Step 2: give each switch a fixed IP address
Home Assistant finds Kasa devices by their IP address. If your router hands a switch a different address after a power cut, Home Assistant loses track of it until it rediscovers it. Set a DHCP reservation for each switch in your router so it always gets the same address. The Kasa app shows each switch's MAC address under its device info, and Home Assistant shows both after setup.
I reserved an address for each of my three switches, so a power cut or a router restart doesn't break anything in Home Assistant.
Step 3: add them in Home Assistant
- Go to Settings → Devices & services. Home Assistant often lists Kasa devices under Discovered already; if so, click Add on each one.
- If they're not listed, click Add Integration and pick TP-Link Smart Home.
- Leave the Host box empty and submit. Home Assistant scans your network and lists every Kasa device it finds. Mine found all three HS200s.
- Pick a switch. If it asks for a username and password, enter your TP-Link account email and password, the same ones you use in the Kasa app.
- Choose an area, and repeat for the next switch. Home Assistant usually remembers the sign-in, so you won't have to type it again.
The account sign-in doesn't mean control goes through the cloud. Newer Kasa firmware encrypts its local connection, and the account details are what Home Assistant uses to set up that connection. After that, it talks to the switch directly over your network.
When it says "Failed to connect"
This is what happened to two of my three switches. Home Assistant could see them on the network and list them, but adding them failed straight away, and it never got as far as asking for my sign-in. So it wasn't a wrong password. It just couldn't open a connection to the switch.
The things that cause this, in the order I'd check them:
- Third-Party Compatibility is off. Check step 1 again.
- The switch has locked up. Kasa devices sometimes stop accepting local connections until they restart. A plug can just be unplugged. A wall switch like the HS200 has to be power-cycled at the breaker: off for about ten seconds, then back on.
- It's offline. Make sure the switch still responds in the Kasa app right now.
- Try again a little later. My two failed switches both connected on the next attempt, a short while after the first try, with nothing else changed in Home Assistant. If yours fail once, it's worth one more go before you start resetting things.
- Add it by IP address. If discovery keeps finding a switch but setup fails, start the integration again and type the switch's IP address into the Host box.
- Last resort: factory reset. Reset the switch, set it up again in the Kasa app with Third-Party Compatibility on, then add it to Home Assistant.
What you get
Each HS200 shows up as a switch with the name you gave it in the Kasa app, such as switch.shop_lights_1. Each one also gets a second switch ending in _led, which turns the small status light on the switch itself on or off. That's handy in a bedroom, where the glow can be annoying at night. Kasa plugs with energy monitoring, such as the KP115 and the HS110, also add power and energy sensors.
_led entity turns on and off. The small strip under the rocker is where the reset button is.Make them follow a presence sensor
This is the reason I wanted them in Home Assistant. My shop already has an ESP32 and LD2410 presence sensor switching outlets on when someone's there and off when the room's been empty for a while. The Kasa switches can do the same with the lights:
alias: "Shop lights follow presence"
mode: restart
triggers:
- trigger: state
entity_id: binary_sensor.shop_pres_sensor_presence
to: "on"
id: arrived
- trigger: state
entity_id: binary_sensor.shop_pres_sensor_presence
to: "off"
for: "00:10:00"
id: left
actions:
- choose:
- conditions:
- condition: trigger
id: arrived
sequence:
- action: switch.turn_on
target:
entity_id:
- switch.shop_lights_1
- switch.shop_lights_2
- conditions:
- condition: trigger
id: left
sequence:
- action: switch.turn_off
target:
entity_id:
- switch.shop_lights_1
- switch.shop_lights_2
- switch.shop_can_lights
Swap in your own entity IDs. The ten-minute wait before turning off means the lights don't go out while you're standing still at the bench. A good mmWave sensor sees you even when you're still, but the wait gives it some margin. You can still use the wall switches by hand any time, and Home Assistant sees those changes straight away.
Putting them on a separate IoT network
I later moved all three switches onto a separate network for smart-home gadgets, with firewall rules that stop those devices from reaching my computers. Home Assistant kept controlling them, because the firewall allows connections that Home Assistant starts. Two things to know if you do the same:
- Discovery won't cross networks. Home Assistant finds Kasa devices with a broadcast, which stays on one network. Add switches before you move them, or add them by IP address afterwards.
- Reserve their IP addresses on the new network too. I did, and all three switches have kept working without any changes in Home Assistant.
Kasa or ESPHome?
Kasa switches are a good choice when you want a normal-looking wall switch that just works, set up in minutes. The catch is that you depend on TP-Link's firmware and its Third-Party Compatibility setting staying the way it is. If you'd rather own the whole thing, an ESP32 running ESPHome gives you control with no account at all, like the garage door and sprinkler builds on this site. I use both: Kasa for the light switches, and ESPHome for anything custom.
Frequently asked questions
Do Kasa switches work with Home Assistant?
Yes, through the built-in TP-Link Smart Home integration. Turn on Third-Party Compatibility in the Kasa app first, because it's off by default.
Why does Home Assistant ask for my TP-Link account password?
Newer Kasa firmware encrypts its local connection, and Home Assistant uses your account details to set that up. Control then runs over your own network.
Why does adding a Kasa switch say Failed to connect?
Usually Third-Party Compatibility is off, the switch has locked up and needs a power cycle, or it's offline. A second attempt a little later often works.
Can I still use the Kasa app and the wall switch?
Yes. Home Assistant works alongside the Kasa app and the switch's own button, and sees changes made either way.
Troubleshooting
| Symptom | Likely cause and fix |
|---|---|
| Failed to connect when adding a switch | Turn on Third-Party Compatibility in the Kasa app (Me, Settings), make sure the switch works in the app, then try again. If it still fails, power-cycle the switch at the breaker or add it by IP address. |
| Invalid authentication | Use the same email and password as the Kasa app, typed exactly. If it keeps failing, add the switch by IP address instead of from discovery. |
| A switch goes unavailable after a power cut | Its IP address changed. Reserve a fixed address for it on your router. |
| Discovery finds nothing | Home Assistant and the switches are on different networks or VLANs. Add them by IP address. |
| The status light on the switch is annoying | Turn off the switch's _led entity in Home Assistant. |