$15 Wifi Plug (Kankun)

All,
Been a ST user for a few weeks, and can finally contribute something to the community.

I found these Wifi Outlets on Amazon Kankun Smart Plug. If you keep an eye out, the price continually changes… I bought mine for ~$15 each. Now, from the factory the only way to communicate with these devices is via their smartphone app, however, people smarter than me realized they run openWRT and wrote up some documentation on how to join them to your Wifi network and install a web page that allows for simple control via HTTP.

Once I got them “hacked” I took the time to write a device type that allows them to work with ST. My device type code can be found here. Details on the “hack” can be found in the device type header.

Keep in mind, this is the first time I have written a device type, so there are probably ways that it can be improved (I need to figure out how to get it to update status periodically), but it gets the job done.

Enjoy,
Krys

5 Likes

allen00se,

Thanks so much for putting this device type together. I got two of these in the mail only a day or two after you posted this device. Although, I found a glitch. The “Off” & “On” work flawlessly on the outlet and toggling in SmartThings app but if I leave the KK plug screen in the SmartThings app & can’t remember if I had the KK outlet on or off, that’s too bad. I can’t get an accurate on/off status for either of my plugs using refresh. No matter what the status is, the app states off. I did a little trouble-shooting & it’s not malfunctioning plugs due to the fact that I can get either plug’s correct status with the browser based query of “http://plug.i.p.address/cgi-bin/json.cgi?get=state”. I absolutely do not know the groovy language (yet), or for that matter, any programming language, Any chance you’ve had this problem & if so, have you had a chance to modify the device handler so it would give correct outlet status?

Thanks, JD

Its should show you the status when you hit the refresh button, if not, then I need you to show me the logs when you hit the refresh to see what it is doing.

Hey guys. Once i add it to network and hack it(tested the on off with json on url), then I’ve added the device handler.
What shall I do after? Do I need to enter the respective ip adress (i got 2 of them on same network) in the groovy script?

Thaks for your directions.

Sorry I forgot to tag @allen00se @jdmcgee

This is pretty good on getting me down the road in the right direction. I have the json.cgi on the plug and I can use the web page to get=state and set on or off. However this is my first time trying to add anything to the smartthings dashboard and I’m stumped for now.
I add it as a device, save and publish, then try to run it and get some errors.
6fd1bfff-8576-4c43-9e2b-a0e0b6627922 6:05:20 PM: error java.lang.NullPointerException: Cannot invoke method tokenize() on null object @ line 120
6fd1bfff-8576-4c43-9e2b-a0e0b6627922 6:05:20 PM: debug IP:null Port:null
6fd1bfff-8576-4c43-9e2b-a0e0b6627922 6:05:20 PM: debug Executing 'on’
The offending bit below.
private String convertIPtoHex(ipAddress) {
String hex = ipAddress.tokenize( ‘.’ ).collect { String.format( ‘%02x’, it.toInteger() ) }.join()
return hex
}
I did set this to my local IP up in line 22 but that doesn’t seem to make a difference. When I look in the app it has the right IP listed but I just get the errors from above if I try to turn it off and on.
Any thoughts about what I am missing here?

Actually I have found my problem and done it a dozen time since.
So the IP is not put in the code but in the device preferences.
Make sure to change the permission of file in www/cgi-bin/json.cgi to 755 (execute to all group)

I leave line 22 as is?
"input(“ip”, “string”, title:“IP Address”, description: “10.1.1.185”, defaultValue: “10.1.1.185” ,required: true, displayDuringSetup: true)"
Then go into the app on my phone and set the IP there? Do I have that correct?
Checking the bit on the plug it looked like it polled the IP information and updated that on the plug itself. When I open a browser and go to the plug web page I see the json.cgi returning the right information and from the web page I can turn that plug on and off.
Thank you having a look and replying to this it is much appreciated.

Ok So if the switch can be triggered by url, then the link between the device in ST and the actual device is corrupt.
So I would delete the device and device handler and restart that part completely.

line 115 I entered the port number
String hexport = port.toString().format( ‘%04x’, “80”.toInteger() )
Then on line 120 I entered the IP address in for the value
String hex = “192.168.0.16”.tokenize( ‘.’ ).collect { String.format( ‘%02x’, it.toInteger() ) }.join()
The light now goes on and off, I also copied the code back from allen00se using git but that didn’t do it for me. I’m not sure where the actual problem is but it does work now. For some reason the values for port and ip always return as null, even though I thought they were defined at line 22 and 23. Are there a couple lines in there that I am missing where these values get defined?
Again thanks for the help, I may get a couple more of the Amcrest outlets from Amazon. This has been fun.

I actually never had to change anything in the lines.
only in the device properties (once created).
There is the ip and port field

Is this device in any way related to this product? or possibly use the same chipset?

Eco Plugs Wi-Fi Controlled outlet by KAB

Just found this post, it works with the Amcrest smart plug which is just another re-branded Kankun. The part I was missing was going under devices selecting the device and then edit preferences. I still get one error on line 78 where this tries to get the status but I can live with that for now.
Previously I was just going into the code and setting the IP address manually there which also worked, but that isn’t the intended way.
Thanks for the responses I got from Nicholas.
I have a JTD smart plug on the way, it looks to be another re-branded Kankun. I’ll update once I see what happens with this one.

My pleasure man. Happy to give back to the community. How much they cost? I’m looking for a cheaper (same hardware) than kankung.

The price fluctuates on Amazon from about twenty to thirty dollars.

The Eco Plug doesn’t seem to have the same capabilities. I got one at Home Depot on clearance for $7.44 but I’m still trying to figure out how to use it.

1 Like

I’m just starting to look into the Eco Plug as well. I picked up four of them on the Home Depot clearance.

This thread has some code that works with HomeBridge:
https://community.smartthings.com/t/eco-plugs-wi-fi-controlled-outlet-by-kab/34557

There is also some concern of the Eco Plugs sending your SSID and password in plaintext to a server the vendor owns.

I believe Kankun integration was lost today. Please help.

What do you mean lost?

It’s not working anymore.