TP-Link/Kasa Bulbs and Plugs Control

dth_wallswitch
dth_smartbulb
dth_lighting
dth_pocketsocket
dth_outlet

(Edgardo Barreto) #548

I am getting Dashlines and no data when updated the device handler to the Energy Monitoring


(Dave Gutheinz) #549

What device? If it is not a HS110, then the Energy Monitor functions are not available and the dashlines are the expected results.


#550

Ah, I should have read this before updating the app… :frowning:


(Edgardo Barreto) #551

LB130, ok thanks!


#552

Thanks for writing the TP-Link integration code. Works great.

Just for your information, the only two snags I ran into: 1. Following links and accidentally attempting to copy and paste your original code (versus the “version 2” code. The files had “delete” in the heading…should have been my first hint. And 2. The new Samsung SmartThings app (formerly Connect) did not have an obvious way to add custom apps. So I just used the original app. Neither were real issues, ultimately.


(Dave Gutheinz) #553

Thanks.

As far as new app, it is not “official” yet for custom apps, so if you could do anything, that was good.


(Robert Carlson) #554

Thank you for all your hard work. I’m hoping you can help me. I have an LB110. I have followed the instructions and read this whole thread. Yes, all of them.

First, I installed the non emon handler and then the smart app. Then, I upgraded to the emon. Everything works (sort of). It seems a little slow, at least compared to the kasa app. Is that normal? I mean, when I turn it on or off it takes ten seconds or so to switch. Just curious.

The real issue is I can’t get any monitoring stats. I was logging it yesterday when I installed it. It was an error about setcurrentdate or some date error. I shut things down and figured I’d mess with it later. Now, I’m back in there and can’t reproduce the error. It seemed like that error was generated by using the app and pressing refresh or saving it after clicking into the cog.

The second issue is, it doesn’t seem to refresh the status of the current state of the icon consistently. For example, if I know the light is on and I haven’t been in the smart things app for a while, then open and look, and the icon says it’s off.

Again, sorry for my lack of logs, but does any of this help or should I go back and reinstall and try to replicate the error. Thanks in advance for your help.


(Dave Gutheinz) #555

Sorry for the delay in responding. First to the problem:

Quick fix:

  1. go to the IDE and turn on logging.
  2. Turn the bulb on and off.
  3. Select the bulb from the logging page.
  4. Press Clear (right side of page) to clear the log.
  5. From the phone app, select the bulb, go to the details page (with all the tiles)>
  6. Select the preferences (gear at top right corner).
  7. Select Save (you do not have to do anything, just save).
    You will get a log that looks something like the below (My LB120). Any errors, warnings, or debugs should be noted.
>  8e0e0f07-fe5e-474d-beb0-8d282f5ff929 6:39:28 AM: info LB120(US) Den Left: Update 7 and 30 day energy consumption statistics
> 8e0e0f07-fe5e-474d-beb0-8d282f5ff929 6:39:26 AM: info LB120(US) Den Left: Updated Usage Today to 2
> 8e0e0f07-fe5e-474d-beb0-8d282f5ff929 6:39:20 AM: info LB120(US) Den Left: Updated CurrentPower to 7.8
> 8e0e0f07-fe5e-474d-beb0-8d282f5ff929 6:39:17 AM: info LB120(US) Den Left: Power: on / Brightness: 70% / Mode: normal / Color Temp: 6500K / Hue: 0 / Saturation: 0
> 8e0e0f07-fe5e-474d-beb0-8d282f5ff929 6:39:15 AM: info Refresh Scheduled for every 15 minutes

If this fixes the display problem - great. Tell me or mark this post as fixing the problem (checkmark at bottom).

If quick fix fails.
If not, I need some information:

a. The logs for the above,
b. The firmware version of your bulb (from the Kasa App)
c. The “Name” of the bulb (go to the IDE My Devices and select the device)
d. The “Type” from the same page.
e. Copy and paste the “Current States” from the same page.

Response to latency.
This SmartThings integration has been designed for efficiency of code and is usually very fast. The main factors that affect this latency is the SmartThings Cloud, Kasa Cloud and your own internet connection. The only thing you can check is your internet connection using an app (android, IOS) like SpeedTest.

This being said, when you are on your home wifi, Kasa will be very quick. It has a local control mode that does not go to the Kasa Cloud when you are home. It goes directly to the bulb.

Normally you would not notice the difference - but the slowdowns mentioned earlier could impact this performance.


(Robert Carlson) #556

Thanks again for your help and quick reply. So, after going into the smartthings app, selecting the gear and saving. Here is the log I received:


(Dave Gutheinz) #557

Perplexed. Code works here (I just instrumented the code and got the expected return - to verify the setCurrentData is running.

a. Where are you located (country?)

b. Open the Device Handler in the IDE and copy lines 514 through 529 and paste here. I want to make sure that there was not some error in the file you copied.

Have hope. I have an alternative means of obtaining this - but want to fix this as a preference.


(Robert Carlson) #558

I live in the USA (Utah).

Here is the code that I have.

Math.round(100wkAvgEnergy)/100
monTotEnergy = Math.round(100
monTotEnergy)/100
wkTotEnergy = Math.round(100*wkTotEnergy)/100
}
sendEvent(name: “monthTotalE”, value: monTotEnergy)
sendEvent(name: “monthAvgE”, value: monAvgEnergy)
sendEvent(name: “weekTotalE”, value: wkTotEnergy)
sendEvent(name: “weekAvgE”, value: wkAvgEnergy)
}

// ===== Obtain Week and Month Data =====
def setCurrentDate() {
def df = new java.text.SimpleDateFormat(“ddMMyyyy”)
df.setTimeZone(location.timeZone)
def curDay = df.format(new Date())
def dayOne = df.format(new Date()-30)
def wkStart = df.format(new Date()-7)
state.dayToday = curDay.substring(0,2).toInteger()
state.monthToday = curDay.substring(2,4).toInteger()
state.yearToday = curDay.substring(4,8).toInteger()
state.dayStart = dayOne.substring(0,2).toInteger()
state.monthStart = dayOne.substring(2,4).toInteger()
state.yearStart = dayOne.substring(4,8).toInteger()
state.weekStart = wkStart.substring(0,2).toInteger()
}


(Dave Gutheinz) #559

I will have to use another method. The code you have pasted properly;, so who knows. I will grab time from the device itself and parse that to determine date.

Dave


(Robert Carlson) #560

Again thanks for your help. This has been a great implementation.


(Dave Gutheinz) #561

I need you to do a test of the code changes. Go to the device handler in the IDE and replace the code below (the method “setCurrentDate”):

def setCurrentDate() {
	def df = new java.text.SimpleDateFormat("ddMMyyyy")
	df.setTimeZone(location.timeZone)
	def curDay = df.format(new Date())
	def dayOne = df.format(new Date()-30)
	def wkStart = df.format(new Date()-7)
	state.dayToday = curDay.substring(0,2).toInteger()
	state.monthToday = curDay.substring(2,4).toInteger()
	state.yearToday = curDay.substring(4,8).toInteger()
	state.dayStart = dayOne.substring(0,2).toInteger()
	state.monthStart = dayOne.substring(2,4).toInteger()
	state.yearStart = dayOne.substring(4,8).toInteger()
	state.weekStart = wkStart.substring(0,2).toInteger()
}

With the UPDATE BELOW (two methods: “setCurrentDate” and “currentDateResponse”)

def setCurrentDate() {
	sendCmdtoServer('{"smartlife.iot.common.timesetting":{"get_time":null}}', "deviceCommand", "currentDateResponse")
}

def currentDateResponse(cmdResponse) {
	def currDate =  cmdResponse["smartlife.iot.common.timesetting"]["get_time"]
	state.dayToday = currDate.mday.toInteger()
	state.monthToday = currDate.month.toInteger()
	state.yearToday = currDate.year.toInteger()
	def dateToday = Date.parse("yyyy-MM-dd", "${currDate.year}-${currDate.month}-${currDate.mday}")
	def monStartDate = dateToday - 30
	def wkStartDate = dateToday - 7
	state.dayStart = monStartDate[Calendar.DAY_OF_MONTH].toInteger()
	state.monthStart = monStartDate[Calendar.MONTH].toInteger() + 1
	state.yearStart = monStartDate[Calendar.YEAR].toInteger()
	state.weekStart = wkStartDate[Calendar.DAY_OF_MONTH].toInteger()
}

Tell me if it works or not. I will then update the baseline.


(Robert Carlson) #562

That fixed it. Thank you so much for your time and efforts! I’d love to contribute to your efforts if there is a way. I really appreciate it.


(Dave Gutheinz) #563

Robert,

Thanks for the very kind thought. If you wish to contribute, make a donation to your favorite charity.

I am a retiree (70 yo) who is just learning to program; so I am really just having fun.

Dave Gutheinz


(chrisym) #564

Hey @Gutheinz - a huge thank you for your amazing integration - TP Link switches connected to ST is such a convenient (and economical) way of controlling all sorts of stuff. I do have a question, however:

What I would like to be able to do is have some switches run in a virtual location which doesn’t actually have a Smartthings hub - i.e. I have created a ‘location’ in the developer portal, but there’s no hub attached to that.

I’ve installed your smartapp and the device handlers, but when I go into the ST app, switch to my new (virtual) location, add the smart app and try to do the initial install, I get the following error in the IDE live log: error java.lang.NullPointerException: Cannot get property ‘id’ on null object @line 227 (getToken)

Looking at the code at this line, it does seem to be referencing a hub at the location… so I am guessing, I might be out of luck and your code will only work if there is a Smartthings hub at the location I want the TP link integration to work with… I’m posting here on the offchance you (or anyone) has a tweak for running the code at a location without a smartthings hub?

Thanks again for all your help. :slight_smile:


(Dave Gutheinz) #565

Chrisym,

Sorry, This integration requires a hub at the location to actually work.

In honesty, there may be a way to do it (take some minor changes); however, it would violate the SmartThings business model and add work to their server without the benefit of having a hub sold for the location; therefore, I am reticent to explore.


(Dave Gutheinz) #566

An update to the Energy Monitor device handlers has been implemented and uploaded to GitHub. It fixes an issue where some users (not all) get an error in the setCurrentDate method used in obtaining the energy monitor data.

Recommendation: If you are not getting the error, do not change.


(Dave Gutheinz) #567

NEW DEVICE. Added the device handler and updated the Service Manager to accommodate the new HS220 Dimming Switch.