[DEPRECATED] Kasa Plug, Switch, and Bulb integration

You can try deleting it. If you have a plug-switch (HS100, HS200, etc.) installed, it will not allow you to delete it.

1 Like

New version 6.1 available.

New Features:

  • added setPollInterval function back into plug/switch types
  • added Energy Monitor functions to bulbs
  • updated driver to include list of required drivers for new devices (in app)

See top-level post for details: [RELEASE] TP-Link/Kasa Plug, Switch, and Bulb integration

Installation and Upgrade. Installation and upgrade instructions are located at: HubitatActive/Documentation.pdf at master · DaveGut/HubitatActive · GitHub

2 Likes

I've found a few issues with the latest 6.1

  1. HPM can't find the latest version, and I have to manually import from url
  2. WhiteBulb didn't declare the command setPollInterval
  3. currently, these devices are the top CPU users (not really much, but it would be awesome if it could be further optimized).

Thanks

HPM: Were you doing an upgrade or initial installation? Was your previous installation cloud?
setPollInterval: not available for bulbs. Only plugs and switches.
Total Execution Time: Quick polling is causing this. Default is off and if you use, warnings are displayed. I can not make that function any faster. Recommendation is setPollInterval = off and refreshInterval = 30 minutes. Below are some of my devices set this way.

Note on CPU. It is not CPU. It is execution time; including, all time from starting a command (on/off/quickPoll/Refresh) to when the command exits. See a copy of my log below (I do not use quick poll).

image

Edit: With the new hybrid (LAN/Cloud) integration, I will be conducting some further experiments to determine best execution time setup (LAN or Cloud). I will split my 20 devices between cloud and LAN and see which is the faster method.

2 Likes

This is an upgrade. and I'm always using local.
in addition, after I updated all drivers and did HPM match again, but in the View Apps and Drivers
I can only see the app, not the drivers.

That is a HPM problem. Do not know why? Testing indicates no problem on my alternate hub but it happened to me on my main. (I tested and thought it was something I did).

For a rapid update, you can open the driver and select import. The function is set to load the latest version.

Dave

Thanks again for this app! Minor HPM documentation note: the KP115 uses the same device driver as the HS110 per your documentation. However, this wasn't apparent when running the install via HPM as the KP115 is not listed next to the HS110 in the driver load dialogue.

1 Like

Did you add as an actuator? I have the power strip and when this app saw the three plugs webcore doesn't see them as plugs. I could not add as plugs.

today i deleted HPM and installed it again and did match up.
it matched two versions of the Kasa app.

Cloud Kasa Plugs, Switches and Bulbs
Kasa Plugs, Switches and Bulbs

in addition, it still don't see the device drivers, so I force to install them again. and it did turn out to have two drivers with the exact same name.
I had to manually delete the duplicates.

Two versions. I will look at tomorrow. Not matching drivers - do not understand why and can not fix. I had same problem and had to fix with several steps (and it worked).

@djgutheinz I found a way to make it fast enough, we can afford to quick poll every device every 5 second.

Tested on HS200/HS210/HS105
currently, each of them takes 300ms per refresh if not doing quick poll. the most costly operation is to make the socket connection.
and it takes 80 ms to do a quick pool (no need to make connection each time).

among the 80ms, 70ms is used to schedule/unschedule the check for rawSocketTimeout.

There's probably no need to do the rawSocketTimeout check in every refresh.

so I removed it, and set all my device to run quick poll every 5 seconds.
and now it takes 10*12 = 120ms per minute with 12 refreshes, compared to 300ms for 1 refresh per minute.

we can check if the device is offline instead of using RunIn(3, rawSocketTimeout). for example, check in each refresh
if( now() - state.lastConnect > 5601000 ) market it offline.

Doing so does not affect your hub? Even with only 6 devices at 15 sec quick pulling would kill my hub within 2 hours.

Update: the new 6.1.0.2 "EM Plug" driver does not seem to be working for my KP115.

It appears that I successfully get a new token in the new app:

app:129 2021-02-15 08:38:05.746 pm info 6.1 starting Kasa Integration
app:129 2021-02-15 08:38:03.733 pm info TpLinkToken updated to <token REDACTED>
app:129 2021-02-15 08:38:03.418 pm info 6.1 getToken <email REDACTED>

Then when I hit a refresh on the KP115 that I updated to the new Kasa EM Plug driver, I get a bunch of "Token expired" warnings:

dev:65 2021-02-15 08:45:41.911 pm warn [EM Plug/6.1.0.2] Kasa Plug - Office Desk distResponse: Error = -20651 = Token expired
dev:65 2021-02-15 08:45:41.907 pm warn [EM Plug/6.1.0.2] Kasa Plug - Office Desk sendKasaCmd: Error returned from Kasa Cloud
dev:65 2021-02-15 08:45:41.670 pm debug [EM Plug/6.1.0.2] Kasa Plug - Office Desk sendKasaCmd: {"emeter":{"get_realtime":{}}}
dev:65 2021-02-15 08:45:41.666 pm debug [EM Plug/6.1.0.2] Kasa Plug - Office Desk getPower
dev:65 2021-02-15 08:45:41.661 pm warn [EM Plug/6.1.0.2] Kasa Plug - Office Desk distResponse: Error = -20651 = Token expired
dev:65 2021-02-15 08:45:41.655 pm warn[EM Plug/6.1.0.2] Kasa Plug - Office Desk sendKasaCmd: Error returned from Kasa Cloud
dev:65 2021-02-15 08:45:41.337 pm debug [EM Plug/6.1.0.2] Kasa Plug - Office Desk sendKasaCmd: {"system":{"get_sysinfo":{}}}
dev:65 2021-02-15 08:45:41.334 pm debug [EM Plug/6.1.0.2] Kasa Plug - Office Desk refresh

Preferences for the device are set to Use Kasa Cloud for device control = ON

Note: I am running both the old and new 6.1 app in parallel as well as the old and new drivers as I test updating one at a time. I wanted to make sure the new app/driver work with the KP115 before abandoning the old code and I'm running 4 of these devices. So let me know if that's an issue.

Any ideas on config changes I should make?

Good idea. I am working same area. Problem is the HS200 (and reportedly HS100). These do not maintain the socket beyond a single message. Other devices do this. That is why the if statement to determine if a connect is required.

The way the code currently works, a connect will be sent if a) the last connect was more than 35 seconds ago, or b) the device is a HS100, HS200. Therefore the 80 ms time should apply except for the HS100/200. As far as the rawSocketTimeout, this is for overall assurance and can probably be removed. The response will reset the state.lastConnect.

PS - aside from connectivity, there are other reasons for a failure

  • Multiplugs - can be created by command B arriving before command A is processed. The device will simply ignore command B.
  • All devices. The local app and cloud poll the devices every 5 seconds. There is a chance of the same scenario as above. (If you unbind the device from the cloud and force a stop on the TP-Link app on your phone, then this will reduce significantly.)

Therefore the rawSocketTimeout was created to assure message delivery and response. It is probably not going away; however, for refresh I may be able to not cause the command to execute - saving a lot of processing.

Just my thoughts. I will look into the last item for the next release.

Says token is expired (can also mean the data did not get updated). Since I have no power, I can not access my hub - so from memory:

  • Open the Integration App
  • Update the Token
  • Run the Add Device / Update Device data
  • exit out of the app
  • Check the data section of your device. A value of token should be populated (not blank).
  • Test the device.

The token should update automatically every three days. This is an initial installation issue where the token is not always updated. I may change to always get the token from the app.

1 Like

so from the last few posts I see here am I to understand that I CAN have quick poll on and I will expect faster responses? Local or cloud interface?

I hope you get power back soon!

Going through the steps, it does fail to update the device via the app so I change the driver manually from the old Kasa Cloud EM Plug (which still works) to the new Kasa EM Plug. Then I get the token expired errors previously mentioned.
When trying to Update Device via the app, I get:

app:129 2021-02-16 08:44:01.134 pm warn6.1 Failed to install device.
Device: REDACTED_12_DIGIT_ID={feature=energyMonitor, ip=192.168.REDACTED, appServerUrl=https://use1-wap.tplinkcloud.com, plugNo=null, alias=Office Desk, model=KP115, type=Kasa EM Plug, deviceId=REDACTED_ID_MATCHING_ID_IN_DATA_SECTION_OF_APP, dni=REDACTED, plugId=null}
Driver: Dev Kasa EM Plug

Note that after manually updating to the new Kasa EM Plug driver, I don't have a token parameter in the Data section of the device, just:

I did just notice though that the device is pointing to the OLD v1 app but the NEW v6.1 driver. I'm guessing therein lies the problem. Is there any way to point it at the new v6 app while still running the v1 app on other drivers?

The app and the driver must be consistent. Give me a day or two to fix HPM (need some time with power.

1 Like

The cloud interface is limited to a sixty minute polling (due to banging on the cloud). The local can do fast polling - BUT use judiciously - mostly for when you need to automate follow-on actions via Rule Machine.

Dave

Any idea why HPM might be telling me that there's an update available? I can't see a version newer than 6.1.0 (which I already have installed)
image

image

Trying to install this "update" results in a failure.

1 Like