SmartThings Community

TP-Link/Kasa Bulbs and Plugs Control


(Saxnix) #447

Yep, the app was offline for me for a bit too, along with webcore, but they appear to be working now.


So with that being an option now, I changed line 20 from Poll, to getPower(…)

Should I also change line 38 from Refresh to getPower?

(Dave Gutheinz) #448

Yes, definitely. Refresh does a lot more and if you do not need it, do not waste the Bandwidth.


(Saxnix) #449

I had to pause the piston as it was reporting info every 4 seconds and it was filling up the webcore memory. I will make the change now.

(Saxnix) #450

Changed Refresh to getPower.

(Dave Gutheinz) #451

You have to be careful when writting code or pistons. If you get in a loop, then you can eat up a lot of resources.

Lesson learned the hard way in this rabbit hole.

Congrats, you are now entrapped.

(Saxnix) #452

With getPower working, how should the rest of the Piston be changed - specifically the For Loop at line 20?

Currently, if the For Loop is working correctly, it will cycle through 20 times over 10 minutes.

a. is there a better way to do this?
b. Should the if condition starting at line 35 be moved into the else condition at line 32/33? The idea would be that if condition 36 is met, stop For Loop and continue with the remainder of the piston. (Still trying to figure out if that is how the else function works)

As a refresher, the point of the piston is;

  • If Dryer door contact changes to open, then every 30 seconds for the next 10 minutes get Current Power of the Dryer.
  • If Dryer power stays greater than 10W for 40 seconds, then set variable @isDryerRunning = true.
  • If @isDryerRunning = true, get Dryer power every 15 seconds.
  • If @DryerHasFinished (in another piston) = true, set variable @isDryerRunning = false

EDIT 1. I just realised that when I wrote the line numbers above for reference, I was looking in the edit pane, not the saved version (which removes surplus lines). I think the narative still holds true though.

EDIT 2. I just replaced the piston image above to reflect how it looks in the editing mode.

(Dave Gutheinz) #453

Do not do webcore, however, depends on the data you get from the dryer:

  1. does the dryer contact indicated closed also? Then do not start polling until it changes to closed.

  2. 15 second poll frequency is kind of high. Once a minute is probably OK. Hint: If you have a permanent press cycle, then it will have a cool down period of several minutes. This will give you time to respond. In that case, you will look for a drop in power consumption (electric dryer?).

What data is available over the interface for the Dryer. More ideas may come about.


(Saxnix) #454
  1. Yes, the dryer door is a typical contact sensor with open/close reporting
  2. Yes, electric dryer. At the end of the cycle when it senses the clothes are dry, it enters a crease-free cycle where every ?? minutes it tumbles and sends warm air to try to keep the creases out. Eventually, this turns off (after about 30 minutes I think).

Basically, for the drying I have 2 pistons, and this one will make it 3.



#3, This one we have been working on, will be a precursor to #1.

(Dave Gutheinz) #455

You are on the right track. Keep me informed.

I will be updating the baseline in a week. You DO NOT HAVE TO UPDATE unless you add a bunch of new devices that are not covered by the current baseline.


(Saxnix) #456

Thanks for all of your help and work on this Dave. I will move the question about finer points of the piston over to the webcore forum and will report back here when I have the final solution sorted out.

I do definitely recommend you look into webcore - it is such a powerful addition to ST.

Thanks again

(James Scholes) #457

Sorry, yes. Mine’s working fine. It looks like you got to the bottom of it. Thanks for all your work.


I just want to say thank you very much!

(Brew) #459

Anyone else having TP-link cloud connecting issues? “error connecting to cloud” in Service manager

(jeubanks) #460

Nope. I’m local for my TP-Link plugs.

(Dave Gutheinz) #461

The message you received had more detail and that is needed to discern the problem. The most likely cause is your E-Mail or password are incorrect.


  1. Using your KASA app,
    a. Verify you are logged in and that your username matches that in the Service Manager.
    b. Verify you can control your bulb.

  2. In the Service Manager - verify your username. Re-enter your password (making sure it matches that used in the Kasa App. (If you are not certain, reset your password in the Kasa App.)

  3. Provide the complete error message. It should read something like:

    Error communicating with cloud:
    {Some error message here with data as to why the error}

Below are some error messages I encountered during testing with causes below (these are also in the documentation):

> [error_code:-20104, msg:Parameter doesn't exist]
> cause:  improper format of message
> error_code:-20105, msg:Parameter has different type with value]
> cause:  bogus device id, device not on list
> cause:  device is turned off or not on local wifi
> [error_code:-20571, msg:Device is offline]
> [error_code:-20580, msg:Account is not binded to the device]
> cause:  device is 'local only'
> [error_code:-20600, msg:Account not found]
> cause:  invalid username
> [error_code:-20615, msg:Password format error]
> cause:  password to short or wrong format
> [error_code:-20651, msg:Token expired]
> cause:  incorrect (expired) token
> [error_code:-20601, msg:Password incorrect]
> valid username, bad password

(Dave Gutheinz) #462

Finally, if you go to the IDE and select “My Locations”. Select the “smartapps” on the second line.

This will display a list of Smart Applications (and Service Managers). in the “Other” group, select the “TP-Link (unofficial) Connect”.

This will display the “TP-Link (unofficial) Connect” page. On that page is a parameter “currentError”, which is the latest error in the system.

In the upper-Right of the page is a “List Events”. Selecting that will list all events, including generated error events.

(Brew) #463

Thanks Dave for the troubleshooting ideas. Last night, the funny thing is, in the Kasa app I could control the light switch, but in ST it listed as “comm error”. ST said the device was offline. This morning I logged out then in of Kasa, and the light switch says it’s off line. The switch works manually, so I’m thinking that the “smarts” of the switch are duff. It’s only been installed for a couple of months.

I have another new switch, so I’m going to swap it, and see if it comes back to life.

Thanks for the help


Hi. I got everything installed fine (TP-Link Cloud Connect and (Cloud) TP-Link EnergyMonitor Plug). The issue is when it reports usage it’s off. For instance my Dehumidifier is showing current usage of 224756 W vs 225 W that’s showing in Kasa. Daily usage is off by the same factor. 30 Day totals aren’t the same either.

8:59:14 PM: info HS110(US) Refrigerator: Updated Usage Today to 2372
8:59:11 PM: info HS110(US) Refrigerator: Updated CurrentPower to 224756.33
8:59:09 PM: info HS110(US) Refrigerator: Power: on
8:54:21 PM: info HS110(US) Refrigerator: Power: on

Edit: I noticed that Usage Today is in WatttHrs not kWh and that’s why it’s reporting the number it is. But current usage is still off by a factor of 1000.

Update: I updated line 225 to the following:
powerConsumption = Math.round(100000*powerConsumption/1000) / 100

I divided powerConsumption by 1000 as part of the equation to get to the right number for current power

I also updated line 247 to get kWh to the tenth for Total Daily Consumption:
wattHrToday = Math.round(10*wattHrToday) / 10

(Dave Gutheinz) #465

I will run against my simulator in HS110(US) mode. There are two HS110 firmware sets out there (US and AU), and for some reason, your bulb used the AU version (or there is yet another set).

(Dave Gutheinz) #466

Found error and fixed on the on-line versions. Thanks for the catch.