[Custom Component] Tapo P100 Plug Control

Have a look at the end of the topic, the py-kasa integration is about to be updated, there seems to be a similar protocol for those plugs as well. App/handshake1 and handshake2 endpoints for the handshake. It is called KLAP protocol.

After a Black Friday spree on cheap P100s, I decided to beef up my rubbish password on the account. The integration failed with ‘Possibly Invalid Credentials’ again. Eek. So I repeated the new account, reset everything, re-add everything method. Aaaaaaand can’t get them back.

@fishbigger - you’ve done some sterling work on getting this integration moving quickly. But there is clearly something a little rum about how TP-Link are validating credentials here. Combined with the rather shifty stuff going on with the Kasa range (ie cutting off local access), I wondered if you’re still actively looking at how this is achieved, and potentially looking at an official API route… (as @GSzabados mentions above)?

*Nothing to do with the now 15 plugs sat here blinking at me, you understand…

An update: after all sorts of juggling, I went back to the account that worked, changed the password back to the terrible one, and… it all works again as if nothing changed. If I change the password again, it breaks. Obviously something very specific going on about whether it likes the credentials or not.

1 Like

Just wanted to add that reducing my password length from 10 to 8 characters fixed the credentials issue for me. It included numbers too.

1 Like

Interesting. I’ve just managed to get (yet another) new account working. And I also took the password down to 8 characters from 10…

This might be a newbie HA question but why are my Tapo devices showing up as entities rather than devices? Is there any way I can achieve that?

In case it’s useful in diagnosing the ‘invalid credentials’ problem, I moved from a Docker HA Core environment to a Virtual Machine HA Supervised environment (with a different IP) and the Tapo devices worked first time.

So I have one P100 v1.0 and P100 v1.2 … I am right now looking for the external API from Tapo and they are completed different requests. It’s super strange that with a new product they are already creating a completely new way of doing the requests

This is how you make requests with 1.2:

{
   "method":"passthrough",
   "params":{
      "deviceId":"8022827EE8EEE2D2ABE0580FC80C105CAAAAAAAA",
      "requestData":{
         "method":"multipleRequest",
         "params":{
            "requests":[
               {
                  "method":"get_device_running_info",
                  "terminalUUID":"98-3B-16-96-48-AA",
                  "requestTimeMils":1606006249234
               }
            ]
         },
         "requestTimeMils":0
      }
   }
}

And the response is:

{
    "error_code": 0,
    "result": {
        "responseData": {
            "result": {
                "responses": [
                    {
                        "result": {
                            "rssi": -44,
                            "time_usage_today": 7,
                            "latitude": 311112,
                            "ip": "192.168.1.9",
                            "device_on": true,
                            "avatar": "house",
                            "time_usage_past30": 12608,
                            "has_set_location_info": true,
                            "time_usage_past7": 8646,
                            "signal_level": 3,
                            "on_time": 453,
                            "overheated": false,
                            "nickname": "UGx1ZyAy",
                            "location": "bedroom",
                            "fw_ver": "1.2.1 Build 20200616 Rel. 31218",
                            "longitude": -91116
                        },
                        "method": "get_device_running_info",
                        "error_code": 0
                    }
                ]
            },
            "error_code": 0
        }
    }
}

Oh. Facepalm emoji. How annoying. But that’s great that you’re looking!

The multipleRequest method is used by the Tapo cameras as well, but they do use another simple way as well. Try this new method on the old plug and the old method on the new plug. You will might see that they both work.

The integration works great for a few days. After it I start to get, without being able to control the switches m

  • Updating tapo_p100_control switch took longer than the scheduled update interval 0:00:30

A fix is to reinstall HA. Any ideas?

Successfully installed and running on my Home Assistant server that runs on my Synology control for two plugs.
Initial attempt failed with the PyP100 error, simply copying tapo_p100_control folder into the custom_components folder and restarting the server before adding the lines to configuration.yaml solved it.
Now how do I create an automation? The Tapo plugs do not show up as devices when trying to create an action.

I’m doomed. I bought a P105 assuming that it will work since I saw a TP-Link documentation a long time ago. Now P100 is still a work in progress. I tried it and failed. It says that the credentials are wrong.

How do you sniff the data sent by the plugs?

Still getting the

Error Code: -1501, Invalid Request or Credentials

But I was able to login via the cloud api using postman and see all my devices registered via the cloud.
The thing that hinders me and got me stumped is in the login() function.
I reviewed the code and saw that this part depends on the encryption that was used by the app. I am not sure if the current PyP100 is aligned with the current Tapo App or I’m doing something wrong.

But I think it’s safe to assume that the encryption step of the app does not need to know the type of the device nor the model. I want to reverse engineer the app but I’m still hoping someone here still has the answer.

My Tapo app is currently 2.2.36

I have Home Assistant on Pi Zero, when installing the Tapo integration I get the error Platform error switch.tapo_p100_control - No module named ‘PyP100’, I see that running pip3 install PyP100 would fix this but as this is a pre install image I cant install python. Could anone advise on this.

Thanks in advance Richard.

I had this issue. Initial attempt failed with the PyP100 error. Deleted the installation and the deleted the lines from my yams file, restart. Then began again, simply copying tapo_p100_control folder into the custom_components folder and restarting the server before adding the lines to configuration.yaml solved it.

1 Like

I will give this a try. Thanks. Will post my result. :slight_smile:

Thank you! I had the same problem as @Richard_Erbe, running hassio on Rpi3B and that fixed it. Looks like order matters. For error no module found - PyP100, I copies files from repo Github PyP100, to the same folder as custom component: image

EDIT: @fishbigger thank you for all of your amazing work!

I’m just gonna close out my issue here. I managed to make my Tapo P105 Plug just by using an 8 character password with 1 number.

ex.
tplinkz1

Edit:
Just tested this component on Tapo L510E Bulb, and it works as a light entity as well.

switch:
  - platform: tapo_p100_control
    ip_address: 192.168.1.20
    email: [email protected]
    password: tplinkz1
light:
  - platform: switch
    name: Dirty Kitchen Bulb
    entity_id: switch.dkbulb

Note that dkbulb is the actual name of the bulb from the Tapo app.

Conclusion:
This component supports Tapo P105 and Tapo L510E

Latest Version now on pypi install using

pip3 install pyP100==0.0.10

It now has a setBrightness function created by Sonic74 on github which I will now work on implementing into ha

1 Like

The documentation for creating lights in ha is less obvious than creating switches so I’m going to tackle adding the lights at a later date :slight_smile:

1 Like