TPLink Data really randomly flaky

That’s great news. Sounds like you have the tooling to log the packets and detect the cause.

The protocol / API is something like this:

  • Sense sends the following UDP broadcast command to port 9999 on all the Kasa devices on the local subnet:
    {"emeter":{"get_realtime":{}}}

  • HS110s receiving that message will send a message back to the requesting IP address of the following form (with a little encryption in between)
    {"emeter":{"get_realtime":{"current":0.028915,"voltage":120.798141, "power":0.527563,"total":18.045000,"err_code":0}}}}

  • HS300s respond with the same data, with current and voltage reversed and in different units
    {"emeter":{"get_realtime":{"voltage_mv":121917,"current_ma":177, "power_mw":16194,"total_wh":90051,"err_code":0}}}}

  • KP115/125s respond in the same units as the HS300, but with current and voltage reversed. Note that the response below is for a situation where the KP115 is turned off via the Kasa/Sense On/Off switch. So there’s no specific data returned that tells that the smartplug is turned off - it just says 0 power. The On/Off is a separate command/status part of the protocol.
    {"emeter":{"get_realtime":{"current_ma":0,"voltage_mv":122525, "power_mw":0,"total_wh":107,"err_code":0}}}}

There’s also a WireShark detector that decodes the entire TP-Link command and debug protocol.

Full TP-Link command set here:

ps: the links give the sources of some of this info.

2 Likes