Feature Request: Plugin for TP-Link

is there anyway we can get a plugin for TP-Link/Kasa devices? i know homebridge and Hoobs support this but would really like this feature.

Hey sweetgman, welcome to nymea!

You are thinking about the Power Sockets, right? A quick search on google gave me this:

https://www.softscheck.com/en/reverse-engineering-tp-link-hs110/#TP-Link%20Smart%20Home%20Protocol

Seems the protocol is not openly documented, but already has been reverse engineered by some people. That means it should be possible rather easily to create a plugin for it. At this point I don’t have any of those. I’ve added it to my list of things to be added: https://www.amazon.de/hz/wishlist/ls/2AEDRSIZHFJYX?ref_=wl_share

Hey,

I’ve managed to get hold on such a device and created a plugin:

I’ve tested it with the HS-110(EU) but in theory it should work with all Kasa smart plugs, provided they have a reasonably new firmware on it. Apparently there has been a protocol change in one of the firmware updates. I could probably add backwards compatibility if needed but I don’t have access to an old firmware any more as mine came with the latest preinstalled already.

Supported features are controlling power, as well as energy monitoring.



It is currently being built in the experimental repository and will be included in the next nymea release.

This is now released

Tested this with TP-Link HS200 switches, HW version 3.0, Firmware 1.1.3. Did NOT find any devices. I suspect that the MAC manufacturer prefix might be different between the switches and plugs. The MAC prefix on the HS200s is 98:DA:C4. In searching at https://maclookup.app/search?mac=98%3ADA%3AC4, it does turn up as a valid TP-Link MA-L (OUI).

Could this prefix be added to the search routine for the TP-Link plugin?

Hello laroadrash,

Hmm, so, the discovery does not use anything of the MAC address. Instead it sends a broadcast to the network on port 9999 which TP-Link devices should answer… So I believe it is discovered just fine, but currently the TP-Link plugin only supports power sockets and not the light switches.

Thing is, the HS-200 is not available in Europe (at least I could not find one that wasn’t imported from US or India for > 100€) but if you are willing to provide me logs and help testing, I believe it should be possible for me to add support for the switch as well.

For a first start, please go to System Settings -> Developer tools and enable developer mode. Then click the button to open the Debug interface. From there, move to the “Logs” tab and scroll down to enable “logging for tplink”. Then start live logging, do a discovery for Tp-Link and send me the content of the live log.

LG V20, in Developer Options, I see a choice for ‘Select debug app’, but none found. Is there a recommended debug app?

Hmm, not sure where you see this. What I meant is in nymea:app, top menu, system settings, developer options. It should look like this:

Duh! Getting old means ‘little bit of sleep’… I’m awake now, might even get on site tomorrow!

Sorry for the delay! FINALLY got a chance to get by and figure out the debug side… Here’s what the log posts when searching for TP-Link Kasa devices:

W | Tplink: Unhandled device type: “”
W | Tplink: Unhandled device type: “”
W | Tplink: Unhandled device type: “”
W | Tplink: Unhandled device type: “”

We currently have 4 of the TP-Link Kasa switches on this network, so I expect that’s where the 4 entries come from.

If needed, I might be able to procure a switch and send it your way.

Thanks for the info.

Odd, I hoped to get more info in here but it seems the switch data structures are quite different from the sockets.

I have now added much more debug output to the code. Would it be possible for you to update to the testing channel (in the app go to system settings -> system update -> Configure on the upper right corner), then restart once and try the same again? The logs should help me more then.

Sending me a device would probably be a bit less effort for you to get me logs and test it, but we can sure give it a shot with the improved log output first - as you prefer. From what I found on the internet it shouldn’t be too hard to get it working once I have those details from the logs.

Thanks for your willingness to help, I’ll get by the facility in the next few days and will forward the logs. In the mean time, I have a few needed spots for the smart plugs, and will see how these work. Thanks again!

W | Tplink: Unhandled device type:
{
“system”: {
“get_sysinfo”: {
“active_mode”: “none”,
“alias”: “4”,
“dev_name”: “Smart Wi-Fi Light Switch”,
“deviceId”: “8006F35E82A0E2C2CF2D6C5380F9C7C51BBF653F”,
“err_code”: 0,
“feature”: “TIM”,
“hwId”: “F30CA3404523AE331168A102F897B7F0”,
“hw_ver”: “3.0”,
“icon_hash”: “”,
“latitude_i”: 326225,
“led_off”: 0,
“longitude_i”: -932656,
“mac”: “98:DA:C4:61:26:56”,
“mic_type”: “IOT.SMARTPLUGSWITCH”,
“model”: “HS200(US)”,
“next_action”: {
“type”: -1
},
“oemId”: “59F15C39F35FEBCF7E5A84FF7620AFA1”,
“on_time”: 0,
“relay_state”: 0,
“rssi”: -53,
“status”: “new”,
“sw_ver”: “1.1.3 Build 191205 Rel.103557”,
“updating”: 0
}
}
}

W | Tplink: Unhandled device type:
{
“system”: {
“get_sysinfo”: {
“active_mode”: “none”,
“alias”: “3”,
“dev_name”: “Smart Wi-Fi Light Switch”,
“deviceId”: “8006B544537798C9F107B1FF78F41BF01BBFE3A9”,
“err_code”: 0,
“feature”: “TIM”,
“hwId”: “F30CA3404523AE331168A102F897B7F0”,
“hw_ver”: “3.0”,
“icon_hash”: “”,
“latitude_i”: 326225,
“led_off”: 0,
“longitude_i”: -932656,
“mac”: “98:DA:C4:61:2F:96”,
“mic_type”: “IOT.SMARTPLUGSWITCH”,
“model”: “HS200(US)”,
“next_action”: {
“type”: -1
},
“oemId”: “59F15C39F35FEBCF7E5A84FF7620AFA1”,
“on_time”: 0,
“relay_state”: 0,
“rssi”: -49,
“status”: “new”,
“sw_ver”: “1.1.3 Build 191205 Rel.103557”,
“updating”: 0
}
}
}

W | Tplink: Unhandled device type:
{
“system”: {
“get_sysinfo”: {
“active_mode”: “none”,
“alias”: “1”,
“dev_name”: “Smart Wi-Fi Light Switch”,
“deviceId”: “8006F7ACD229F1B9E1C313392AACB8661BC0F1AA”,
“err_code”: 0,
“feature”: “TIM”,
“hwId”: “F30CA3404523AE331168A102F897B7F0”,
“hw_ver”: “3.0”,
“icon_hash”: “”,
“latitude_i”: 326225,
“led_off”: 0,
“longitude_i”: -932656,
“mac”: “98:DA:C4:61:3B:02”,
“mic_type”: “IOT.SMARTPLUGSWITCH”,
“model”: “HS200(US)”,
“next_action”: {
“type”: -1
},
“oemId”: “59F15C39F35FEBCF7E5A84FF7620AFA1”,
“on_time”: 587,
“relay_state”: 1,
“rssi”: -44,
“status”: “new”,
“sw_ver”: “1.1.3 Build 191205 Rel.103557”,
“updating”: 0
}
}
}

W | Tplink: Unhandled device type:
{
“system”: {
“get_sysinfo”: {
“active_mode”: “none”,
“alias”: “2”,
“dev_name”: “Smart Wi-Fi Light Switch”,
“deviceId”: “800695BE3B459A72DE93735D5A2ACE121BC009BF”,
“err_code”: 0,
“feature”: “TIM”,
“hwId”: “F30CA3404523AE331168A102F897B7F0”,
“hw_ver”: “3.0”,
“icon_hash”: “”,
“latitude_i”: 326225,
“led_off”: 0,
“longitude_i”: -932656,
“mac”: “98:DA:C4:61:3A:14”,
“mic_type”: “IOT.SMARTPLUGSWITCH”,
“model”: “HS200(US)”,
“next_action”: {
“type”: -1
},
“oemId”: “59F15C39F35FEBCF7E5A84FF7620AFA1”,
“on_time”: 587,
“relay_state”: 1,
“rssi”: -69,
“status”: “new”,
“sw_ver”: “1.1.3 Build 191205 Rel.103557”,
“updating”: 0
}
}
}

W | DebugServer: Debug report expired.

Also have a gz of debug info.

Attempted to add KASA HS103 smart plugs, no joy. Will provide the debug log on those in the next couple of days also. One would hate to think that they have different commands for every single different product!!!

Thanks for the logs. I’ve looked into this now and I believe the main reason why it failed is a protocol change in the latest firmware (my device has firmware 1.5.4 while yours seem to be on 1.1.3. However, I’ve changed the code now so that it should work with either version.

Along with that, it also helped me to understand the protocol differences between devices with energy monitoring and the ones without. I have implemented more proper support for the devices similar enough to ours. That should now enable proper support for

  • HS100 (Plug)
  • HS103 (Plug)
  • HS105 (Plug)
  • HS110 (Plug with energy monitoring)
  • HS200 (Light switch)
  • KP100 (Plug)

Now, I am confident it should work for the discovery at least. I would expect that the actual controlling should work too, but as I can’t test devices other than the HS110 myself, I’d still need you to test it by updating nymea to the latest “testing” version and reporting back before I can release this to stable. If something goes wrong, please send me the logs again.

Hello @laroadrash,

If possible, please let me know how things now work for you. Ideally we’d catch any errors in the testing repo before releasing to stable. The release of 0.19 is getting closer now, there won’t be big changes any more, only fixes if you’d report something.

And @sweetgman, if you’re still around, please let me know which tplink devices you have and if they are working for you now.

Thanks a lot!

I should be up there tomorrow morning, will (hopefully) have a chance to check then.

Success! I can switch them all on and off now.

1 Like

Nice! Thank you for your support in sending logs and testing things.

This has now been released to stable with 0.19