TP-Link Web Control

Controlling TP-Link Smart Plugs without the Kasa App

Posted by Lotek on Tuesday, 28th November 2017

The Problem

I've recently been buying up TP-Link Smart Plugs in the Black Friday sales, as they work well with Alexa and let me control a number of devices in the house at a price point that I can't actually match with an ESP8266 and a mains relay (that I'd trust without amperage restrictions).

Having set a few up, I'm finding control of the plugs is possible via Alexa and/or a smart phone running iOS/Android, but not the web. That doesn't really work for me, as my wife runs a windows phone, and I spend most of my time looking at an OSX macbook.

The Proposal

Given that the Kasa app sends HTTP based JSON requests to a web hosted API endpoint, its little matter to find out what these requests are supposed to say, and then trigger them from a webpage instead.

To access the remote API, the Kasa app generates a unique ID, then combines this with the registration information you supply at sign-up to request a secure token from TP-Link. Once you have the token, you can ask the API for smart plugs which are registered to your account, and get the availability, status and relay states back.

You can combine the token with POST requests to change the relay state remotely from anywhere in the world.

The Solution

I created a simple Angular client to generate a UUID, capture credentials, request a token, iterate the devices returned by the remote API, and allow you to control them via an attractive UI.

This project will form the basis of a future home automation ecosystem I'm developing.

For now, you can try out a hosted demo here.

Full source is available at my github account, or in this codepen