TP-Link/Kasa Bulbs and Plugs Control (Old, Unofficial Integration)

ok. gives me pointer to error. Will work more tomorrow.

No worries. I have heaps of time this weekend to test as needed. Thanks again.

Next version of the AUS version is now ready. When refresh and refresh stats are run, all six fields should be correct. Additionally, the numbers should match those in the Kasa App (I correct today’s total to match their calculation). Please reply back if it fails or has errors.

That did the trick :grinning:. All 6 fields are now reporting

Just thought I would run the Logs as well


Edit:
General question,
If the Refresh rate is not manually set in the app (5/10/15/30 minutes), what is the default refresh interval? Or if you don’t set it, does it not refresh on its own?

You are welcome.

Webcore: Every 5 minutes should be sufficient to run (you cam open preferences and select refresh rate down to 5 minutes). It really depends on what you are doing. The more finesse, the more refresh (and more processing resources). I can tell you how to change the code for one minute refresh (a one line change). Whenever you do a refresh, two events are fired related to power: power and engrToday

Which one does web core use? (I may have to change some code for webcore to recognize. Not hard, just need to know.)

Yeah, last night I set it for 5 minutes for a test and it worked fine. I figured it is connected to 240v (not battery) so it doesn’t really matter it if it fires that often. My rule in webcore uses the Power information.

Now, I am new to webcore (and any sort of coding for that matter), but based on the pistons I have cobbled together (which are mostly based on other people’s pistons), the other thing I had been thinking to do (instead of having the refresh rate set at 5 minutes, 24/7), was to have a rule that;

  • If Dryer door contact changes to open, then every 30 seconds for the next 10 minutes poll the Dryer. Edit - this assumes polling will report power usage/wattage
  • If Dryer power stays greater than 10W for 40 seconds, then set variable @isDryerRunning = true.
  • If @isDryerRunning = true, poll the Dryer ever 15 seconds.
  • If @DryerHasFinished (in The Dryer has Finished piston above) = true, set variable @isDryerRunning = false

Thoughts?

PS. Sorry if this is OT

This is interesting. I started coding last Feb (first SW since Fortran in University). I have the advantage of being a retired (69yo) Aerospace engineer working on intelligence platforms.

I see what you are trying to do. Is there a way in WebCore to call a command in a device? If so, I can expose a command that you can use to control power only polling (That would be a single cloud message to get watts or amps (your choice). the command would be powerPolling(units, frequency, duration). Units = minutes or seconds), frequency an integer of 1, 5, 10, 15). Duration is time in minutes before stopping unless told otherwise (i.e., 10 minutes). A second command would unschedule the first and create the new schedule.

There are practical limitations on frequency in SmartThings, usually 1, 5, 15, 30 minutes, and 1, 2, 3 hours. Although we could work-around these using another method, it is not recommended by the ST staff. Again, we can do what you want. It would look like this:
a. Dryer Door contact changes to OPEN. HS110Dryer.powerPolling(“minutes”, 1, 10) - every minute
Output: watts every minute for 10 minutes.
b. Stop Polling: HS110Dryer,powerPolling(“stop”, 0, 0)
c. Poll every 30 seconds: HS110Dryer.powerPolling(“seconds”, 30, 60) (not guaranteed to operate since I would schedule the next instance while executing the current. If the current fails, then the schedule sequence would stop).

Each poll would create the power event which is exposed in capability power meter. So WebCore should be able to read it. Then Web Core does the intelligence and sending of messages. I am game, let us get the details of what you want. Not hard at all.

Should we create a new topic over here somewhere, and then post back here once we have a solution? I didn’t want to hijack this topic.

I thought I was going to be home all day today, but the boss had other ideas. Anyway, before we left the house, I had come up with this, but it didn’t work. As I said, never done any programming, and just trying to cobble stuff together from what others have done.

For this;

Um
I don’t know :slight_smile:. I really don’t even know what I don’t know at this stage, but I am going to guess that you can. This is just one section I know I can get to. (sorry if that is super ignorant)


image image
image

If I were to select the Poll option (this way), it looks like that is as granular as it gets, I don’t think I can select anything more derived than that, unless the changes you make to expose a command generate a new location item in the list posted above. Sorry if that is convoluted.

Now, having said that, there is another section your change may populate an option I can select. For example, the Dry Door contact sensor option gives me these options,

and this for the Dryer (HS110)

So yes, I am keen to figure this out. Although I could quite easily use the 5 minute Refresh option that will make my rule/piston run, my curiosity has me wanting to figure this out. If you want to move this to another topic, feel free to do so, or let me know and I can do it and then clean up these last few posts.

  1. Let us stay here for discussions on this add-on. My plan would be to work with you to create and then include in this product. We will probably use the webcore group for some assistance.

  2. I plan to expose the capability “Power Meter”, which will expose the device as having an output “power”.

  3. Need to figure out is WebCore can use custom device commands. If so, then we are golden. Could you do this?

  4. Need to determine if WebCore can schedule/unschedule commands and at what frequency. If so, then I can make my command simply respond to a request. If not, then I have to customize my command to provide a schedule interface. Could you do this?

Next: Sometime today I will create a TEMPORARY poll command in the AUS version. It will update the power attribute, creating the power event so you can see the timing between the poll in web core and the subscribed event response. I will also start looking at WebCore (I hope my dusty brain cells can handle the new information).

An update to the AUS version is on GitHub now. How it supports your testing

a. Added exposed command “getPower” without parameters.
Command will update attribute power (on the last figure above) using

sendEvent(name: “power”, value: power)

power is in watts. A call from a smart app would look like this (I am not sure on how it would look in WebCore):

dryer.getPower()

b. TEMPORARILY change command “poll” (ffrom your first figure) to call getPower. Worst case, this will allow you to get the power value by causing a poll (although I think you can also use getPower.

I included the getPower in my product baseline and will test against simulated data today for working with data values. This will shake out the poll command as well as the parsing of the energy meter data.

Dave

  1. Copy that.
  1. I will jump on the webcore forum and see if can get the answers
  2. I will jump on the webcore forum and see if can get the answers

a. Looks the same as before

b. Also looks the same. I think

With your understanding and experience, it will take you about 2 seconds of looking at webcore to surpass my understanding of it.

I also did another log check of the updated DH;

I also changed the piston so it has Pole instead of Refresh in line 25, but left it as Refresh in line 43.

The good news is that it is partially working. I obviously have something wrong with the FOR Loop. Similarly to when I had it as Refresh as now with Poll, it only did the check 3 times. I don’t understand how to use the feature and set the conditions, but the intention was to have it do it 20 times. Here are the Dryer logs for that;

and the not sure if it is of any help, but the logs for the “@isDryerRunning check” piston;


I checked with the boss and I really will be home all day today, so whatever you needed me to check/do, shoot it on through.
Greg

Not sure how to do it yet, but in searching another user said this;
You can add a custom command to the device handler which webCoRE will see and can use.

I have posted a topic in the Developer’s section seeking help to these questions.

@anon36505037 also posted this;
Yes, webCoRE can schedule / unschedule commands
 at millisecond frequency.

Good. The device handler you loaded earlier today has a custom command exposed (i.e., isted as a command). the command is getPower. If you can hook to this command, then great. (it will not be at the top of the list you had in the first figure (those are for all devices). Will probably be somewhere below.

The data returned is the attribute power.

Since WebCoRE can schedule, then I believe that nothing else is required in the device handler (unless you need some other data). Please correct if I am wrong.

My current task is integrating this into a product baseline so it is available to all. That will come out this next week (hopefully).

On the device handler log, the one error you see is because the data for Last Month that is part of the statistics is null. I did not parse it properly, but it should not affect the results. I am fixing that also as a part of the baseline update.

Dave

@anon36505037, if you are happy to help out, can you tell me where in webcore I would gain access this;

It does not appear in the;
Add a new task
With

Dryer
Do

Please select a command section where I thought it would be available??

EDIT: Scratch this question, after updating I can now see getPower as an option.

Further to above,
the custom Command ‘custom setCurrentDate(
)’ appears, but ‘getPower’ doesn’t. I assume the setCurrentDate custom command is the one exposed in the DH. If that is the case, I am not sure why ‘getPower’ isn’t showing as a custom command as well?

you may need to do some sort of update in WebCore or in the Device Handler.

For the device handler, go to the phone app, details page and select the preferences page (the gear at the top right). Select “SAVE”. That will update the Device Handler. For the WebCore, I do not know!.

Dave

The details page is in the phone app. When you select a device from MyDevices, it brings up the details page (with all the associated tiles). Preferences are in the upper left corner.

My previous post was in the blind. The IDE and platform are dead in my region.

You may need to refresh webcore (have it look for devices again. When back on-line, I will double check that the getPower is indeed exposed (I have a smartapp i can use to check).

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

Success!!

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?