SmartThings Community

[Release] New TP-Link/Kasa Plug, Switch, and Bulb Integration

dth_lighting
dth_pocketsocket

(Dave Gutheinz) #63

Sometimes. The ST phone interface is sometimes not readily responsive to changes. Sometimes it is fine. I do not know why - but it is sort of normal with the cloud interface.

Design note: The interface is designed as a state machine. When a command is selected, it is sent to the device and then (automatically) a status is received. The status is then updated based on the returned device status.


#64

Hi Dave,
Thanks for reply in other thread. You were correct having two services installed was a bad idea. Not sure why since I put two bulbs on one and the plugs and switches on the other, but dupes popped up.

Here’s my question before I blow everything away and start over. Done correctly should any Kasa device show up twice, managed by Kasa app and by Smarthings? This is in the Alexa app, not on my ST apps on phone/iPad.


(Shaun) #65

Hi Dave,
First of all, fantastic work for keeping this integration up to date.
It may be a long shot but do you or anyone else know of a way to save the current energy use of a (HS110) energy monitoring plug to a variable in WebCoRE? I’ve tried but I don’t seem to be able to get the reading out of smartthings, I only get a $getPower saving as the variable. I wish to set it so that when a device is using under a certain amount of power (Microwave for instance) for a certain amount of minutes, it turns off.
Thanks very much for any input.


(Dave Gutheinz) #66

I code using Capability Power Meter with Attribute Power. This information is automatically updated at each refresh cycle (which you can set in Preferences). The external command (not part of Capability Power Meter) is getPower(). You should be able to access that from WebCore (I do not use WebCore).


(Shaun) #67

Okay, with the help of a friend I have figured out how to store the GetPower() stat as a variable.

Thank you very much.

For anyone wanting to know in WebCore, use this:
Set variable {@PC_Power(Variable Name)} = “My PC’s(Your Devices)” power;
Use variables to loop it.

That saves the variable as this:
@PC_Power = 144.66; (in watts)
Run a refresh on the device in the command every x minutes to update the variable.


(Esmugala) #68

I found a bug/issue in this version that wasn’t in the last version. If you happen to have any devices in your Kasa account that aren’t online, you won’t be able to add any devices to smart things via the app. The app shows:

10:53:28 PM: error groovy.lang.MissingPropertyException: No such property: system for class: org.codehaus.groovy.runtime.GStringImpl
Possible solutions: bytes @line 609 (doCall)

10:53:28 PM: error Error in sendDeviceCmd: [error_code:-20571, msg:Device is offline]

After either removing those devices or making sure they are connected, everything else works correctly.


(Dave Gutheinz) #69

Updates to 3.5.03 Device Handlers and SmartApp

12-12-2018 - SmartApp. Fixed SmartApp handling of HS107 and HS300. After installed, if user unplugs (or device is off-line) the device and subsequently tries to add a device, the SmartApp crashed. Fix will not add the offending device to the currentDevices Array. Impact: User may not be able to remove the device using the SmartApp under certain circumstances. Manual removal via classic Phone App or the IDE My Devices page will work.

12-12-2018 - Device Handlers. Maintenance updates to correct some errors in SmartApp to Device Handler comms.

Update Recommendation: If you do not have any issue, update is purely optional. If you encounter problems, update and retest before reporting.


(Dave Gutheinz) #70

Fixed in update 3.5.03. Thanks for the information! Read my note for implications of fix.

If this does not fix your problem, please inform me. I tested with plugs, lights, and multi-plugs off-line, so I think it is solid.

Dave


#71

Firstly, thanks for your device handlers and manager, it’s working great for me.

I have one minor annoying problem, I keep on getting a prompt to update the app although I have and it’s on your latest version 3.5.03. I notice in the change log information there is a reference to 3.6.0, any thoughts? thanks.


(Dave Gutheinz) #72

Ignore for now. It does not impact operations. I will update when I get some time.

Dave


#73

Good to hear it’s not affecting functionality, but it is affect nagging levels from the wife due to repetitive notifications on her phone :slight_smile: … I’ll look to disable for now.

Thanks.


(Dave Gutheinz) #74

I should be corrected for now. However, I will be disabling notification function. If you do not update, there is usually NO impact, so why notify?

Dave


(Northern) #75

Hi @Gutheinz I’ve installed the cloud-based version and it doesn’t seem to be refreshing automatically – the smart app control slider for this won’t stay in the on position.

The effect is that when my HS105 is turned manually or by the Kasa app, it won’t register on SmartThings until I manually refresh the device.

Not sure where I’m going wrong here! I’ve tried setting the refresh rate to 1 minute within my SmartThings Classic app, as well as even smaller increments (i.e. 0.5 and 0.1) in my IDE.


(Dave Gutheinz) #76

Bottom line. Testing indicates that refresh and refresh interval setting are both working. Other than that, there is nothing I can do. There is a recurring problem with the SmartThings Cloud to SmartThings classic phone app where updates are very slow (I think dropped) going from cloud to app. Test to see if this is your condition: When encountered, go to the details page for the device then back to the devices pages (or vica-versa). DO NOT PRESS REFRESH. If this clears the issue up, the problem is definitely in the Cloud to phone app interface.

What I tested
Conditions: Kasa Account installation, Classic phone app. IDE Logging for instrumentation.

Test:

  1. On the phone app, select the device. Then select the Details page.
  2. Turn the device off using the phone app.
    Observation A: Tile turnes green with “Waiting”, then greay with “OFF”.
    Observation B: The IDE logs the device status is OFF.
  3. Go to the Recently tab on the Phone App.
    Observation: last entry is off.
  4. In Kasa App, turn the device on:
    Observation A: within one minute, the Recently tab adds a new line indicating on.
    Observation B: The IDE logs the device status to on.

(Northern) #77

Thanks for responding so quickly!

Steps 1-3 work perfectly – exactly as you described.

Step 4 is where the breakdown occurs. Neither the IDE nor the SmartThings Classic phone app don’t seem to be recording any activity that doesn’t originate with them.

It’s now been more than 10 minutes, and neither has registered nor logged the on command from the Kasa app even though the refresh rate is set to 1 minute.


(Dave Gutheinz) #78

When did you install the device. In the Device Handler, copy below the lines beginning the below (or similar) with
========= History ============================================
and ending with
metadata {

This will tell me the version.

Service Manager. Same thing, beginning with the below (or similar)
====== Application History ================================
and ending with
definition (


(Northern) #79

Lol I installed the handler and the smart app this morning!

I’ll go get what you requested momentarily! :smiley:


(Northern) #80

Here’s the handler:

========= History ============================================
2018-10-23 Update to Version 3.5:
a. Compatibility with new SmartThings app.
b. Update capabilities per latest ST definitions
1. deleted capability polling (depreciated)
2. deleted capability sensor (depreciated)
3. update program to accommodate other items
c. Various changes for updated Service Manager
With great appreciation to Anthony Ramirez for
his assistance as well as leading the development
of the new Service Manager.
12.07.18 3.5.03. Corrected refresh rate update issue.
======== DO NOT EDIT LINES BELOW ===*/
// ===== Device Type Identifier =====
def deviceType() { return “Plug” }
// def deviceType() { return “Switch” }
// def deviceType() { return “Dimming Switch” }
// ====== Device Namespace =====
def devNamespace() { return “davegut” }
// def devNamespace() { return “ramiran2” }
// ====== Other System Values =====
def ocfValue() { return (deviceType() == “Plug”) ? “oic.d.smartplug” : “oic.d.switch” }
def vidValue() { return (deviceType() == “Dimming Switch”) ? “generic-dimmer” : “generic-switch” }
def deviceIcon() { return (deviceType() == “Plug”) ? “st.Appliances.appliances17” : “st.Home.home30” }
def devVer() { return “3.5.03” }
// ======================================================================================================================

metadata {

Here’s the app:

/*
TP-Link SmartThings Manager and TP-Link Cloud Connect, 2018 Version 3.5
Copyright 2018 Dave Gutheinz, Anthony Ramirez

Licensed under the Apache License, Version 2.0 (the “License”); you
may not use this file except in compliance with the License. You may
obtain a copy of the License at:
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the License for the specific language governing
permissions and limitations under the License.
Discalimer: This Service Manager and the associated Device
Handlers are in no way sanctioned or supported by TP-Link. All
development is based upon open-source data on the TP-Link Kasa Devices;
primarily various users on GitHub.com.
===== CHANGES =====
12-03-18 3.5.02. Update to fix login problems and finalize
multi-plug integration.
12.12.18 3.5.03. Fixed error causing crash when installed multi-
plug is offline and user attempts to add a device.
*/
// ===== Developer Namespace =====
def appNamespace() { return “davegut” }
// def appNamespace() { return “ramiran2” }
// ====== Application Information =====
def appLabel() { return “TP-Link SmartThings Manager” }
def appVersion() { return “3.5.03” }
def appVerDate() { return “12-12-2018” }
def appAuthor() { return “Dave Gutheinz, Anthony Ramirez” }
// ===========================================================

definition (


(Northern) #81

Interesting – I just sent a command via Action Tiles, and that triggered some kind of catch-up, where all of the events that SmartThings hadn’t registered were logged all at the same time as the Action Tiles command.

What seems really odd is that the backlog of events are logged as occurring after the Action Tiles command I just sent, instead of before the Action Tiles command.


(Dave Gutheinz) #82

Thanks for catching the error. Found and corrected in the repository. Steps for you:

  1. Replace file content, then save, publish.
  2. Go to app and options.
  3. Reselect the refresh rate property and save. This will cause the refresh to schedule properly.

Most time spent updating the 8 device handlers. Basically, a preferences update was:
a. As planned, unschedule the refresh interval activity.
b. Not properly restarting same - causing it to go away.

Dave
logs below:
83bf7027-13b1-4b18-b70c-fa74e17d33fb 5:02:11 PM: info HS105 Power Right: Power: on

[83bf7027-13b1-4b18-b70c-fa74e17d33fb](https://graph-na02-useast1.api.smartthings.com/ide/logs#83bf7027-13b1-4b18-b70c-fa74e17d33fb) 5:02:08 PM: info HS105 Power Right Refresh Scheduled for every 10 minutes

[83bf7027-13b1-4b18-b70c-fa74e17d33fb](https://graph-na02-useast1.api.smartthings.com/ide/logs#83bf7027-13b1-4b18-b70c-fa74e17d33fb) 5:02:08 PM: info Updating Power Right...

[83bf7027-13b1-4b18-b70c-fa74e17d33fb](https://graph-na02-useast1.api.smartthings.com/ide/logs#83bf7027-13b1-4b18-b70c-fa74e17d33fb) 5:01:34 PM: info HS105 Power Right: Power: on

[83bf7027-13b1-4b18-b70c-fa74e17d33fb](https://graph-na02-useast1.api.smartthings.com/ide/logs#83bf7027-13b1-4b18-b70c-fa74e17d33fb) 5:00:37 PM: info HS105 Power Right: Power: on

[83bf7027-13b1-4b18-b70c-fa74e17d33fb](https://graph-na02-useast1.api.smartthings.com/ide/logs#83bf7027-13b1-4b18-b70c-fa74e17d33fb) 4:59:24 PM: info HS105 Power Right: Power: on

[83bf7027-13b1-4b18-b70c-fa74e17d33fb](https://graph-na02-useast1.api.smartthings.com/ide/logs#83bf7027-13b1-4b18-b70c-fa74e17d33fb) 4:58:22 PM: info HS105 Power Right: Power: on

[83bf7027-13b1-4b18-b70c-fa74e17d33fb](https://graph-na02-useast1.api.smartthings.com/ide/logs#83bf7027-13b1-4b18-b70c-fa74e17d33fb) 4:57:23 PM: info HS105 Power Right: Power: on

[83bf7027-13b1-4b18-b70c-fa74e17d33fb](https://graph-na02-useast1.api.smartthings.com/ide/logs#83bf7027-13b1-4b18-b70c-fa74e17d33fb) 4:56:23 PM: info HS105 Power Right: Power: on

[83bf7027-13b1-4b18-b70c-fa74e17d33fb](https://graph-na02-useast1.api.smartthings.com/ide/logs#83bf7027-13b1-4b18-b70c-fa74e17d33fb) 4:55:26 PM: info HS105 Power Right: Power: on

[83bf7027-13b1-4b18-b70c-fa74e17d33fb](https://graph-na02-useast1.api.smartthings.com/ide/logs#83bf7027-13b1-4b18-b70c-fa74e17d33fb) 4:54:23 PM: info HS105 Power Right: Power: on

[83bf7027-13b1-4b18-b70c-fa74e17d33fb](https://graph-na02-useast1.api.smartthings.com/ide/logs#83bf7027-13b1-4b18-b70c-fa74e17d33fb) 4:53:24 PM: info HS105 Power Right: Power: on

[83bf7027-13b1-4b18-b70c-fa74e17d33fb](https://graph-na02-useast1.api.smartthings.com/ide/logs#83bf7027-13b1-4b18-b70c-fa74e17d33fb) 4:51:22 PM: info HS105 Power Right: Power: on

[83bf7027-13b1-4b18-b70c-fa74e17d33fb](https://graph-na02-useast1.api.smartthings.com/ide/logs#83bf7027-13b1-4b18-b70c-fa74e17d33fb) 4:50:22 PM: info HS105 Power Right: Power: on

[83bf7027-13b1-4b18-b70c-fa74e17d33fb](https://graph-na02-useast1.api.smartthings.com/ide/logs#83bf7027-13b1-4b18-b70c-fa74e17d33fb) 4:49:25 PM: info HS105 Power Right: Power: on

[83bf7027-13b1-4b18-b70c-fa74e17d33fb](https://graph-na02-useast1.api.smartthings.com/ide/logs#83bf7027-13b1-4b18-b70c-fa74e17d33fb) 4:48:25 PM: info HS105 Power Right: Power: on

[83bf7027-13b1-4b18-b70c-fa74e17d33fb](https://graph-na02-useast1.api.smartthings.com/ide/logs#83bf7027-13b1-4b18-b70c-fa74e17d33fb) 4:47:24 PM: info HS105 Power Right: Power: on

[83bf7027-13b1-4b18-b70c-fa74e17d33fb](https://graph-na02-useast1.api.smartthings.com/ide/logs#83bf7027-13b1-4b18-b70c-fa74e17d33fb) 4:46:24 PM: info HS105 Power Right: Power: on

[83bf7027-13b1-4b18-b70c-fa74e17d33fb](https://graph-na02-useast1.api.smartthings.com/ide/logs#83bf7027-13b1-4b18-b70c-fa74e17d33fb) 4:45:35 PM: info HS105 Power Right: Power: off

[83bf7027-13b1-4b18-b70c-fa74e17d33fb](https://graph-na02-useast1.api.smartthings.com/ide/logs#83bf7027-13b1-4b18-b70c-fa74e17d33fb) 4:45:26 PM: info HS105 Power Right Refresh Scheduled for every minute