TP-Link Tapo P100

Try creating a new account with a simple password and email.

For now, we need to create a custom integration. It should not take long.

Ah oke. thanks for the quick reply. I have a plug in my socket for a while and then i thought let me check if it is supported in hassio and I found this post. Nice work guys. Much appreciated.

Ok so I’m now on my 3rd email account :slight_smile: still the same result.
I’m starting to wonder if this is an issue with my Linux VM on some kind of encoding, or if my plugs do have some sort of issue. I’ve already remove all the integrations I had with other services (GoogleHome) @K4CZP3R could you post a small set of instructions on how to build the Java-POC? I’ve just tried with maven (correct me I’m still a noob with Java) I’m not being able to build it.
Thanks again for all the dedication and help!

1 Like

What python version are you using? I’m using Python 3.8.5.

1 Like

@K4CZP3R Will you create the custom integration? I don’t have any experience with that and don’t know how to do it.

I’m currently working on building an intergration :slight_smile: it might take some time but I hope it will be out soon

1 Like

Do you have a Github repo where I can see how it is done? :slight_smile:

Not yet I’m still working on simplifying down the python code into a pip module :slight_smile: Hopefully by this evening :slight_smile:

4 Likes

From my research a -1501 error code can also mean your credentials are incorrectly encoded. If it is this it would be a problem with the code not your request :slight_smile:. @K4CZP3R have you had a look at this?

1 Like

At begin encoding was not properly implemented but after fixing it I can login. I can test other passwords though

Ok :slight_smile: Just checking as this is one of the stumbling blocks I’m trying to get over at the moment. Does this look right for encoding the data?

def encryptCredentials(self, email, password):
		#Password Encoding
		self.encodedPassword = helpers.mime_encoder(password.encode("utf-8"))

		#Email Encoding
		self.encodedEmail = hashlib.sha1(email.encode("utf-8")).digest()
		self.encodedEmail = helpers.mime_encoder(self.encodedEmail)

You are missing some formatting present in the android app when formatting email digest. https://github.com/K4CZP3R/tapo-p100-python/blob/21e4bf9b61c08a3eb215293198968f82cd80ab2d/encryption.py#L52

2 Likes

Hi, New problem I have managed to send the turn on and off command. I am getting new response codes though. -1003 for turning off and 1002 when turning on. @K4CZP3R do you know what these error codes mean? If I can fix this I should be able to get a pip package out tonight or tomorrow morning!

-1003 means ERR_JSON_DECODE_FAIL and 1002 is ERR_TRANSPORT_NOT_AVAILABLE

Edit: I have changed my password and now I’m getting the same error as @pnmoliveira so I’m working on a fix (java impl works fine, python does not)

1 Like

Ok I’ve fixed the error code -1003 but I’m still getting the error code 1002. Any ideas on how to fix this?

Show me your request body

Payload = {
			"method": "set_device_state",
			"params":{
				"device_on": True,
			},
			"requestTimeMils": int(round(time.time() * 1000))
		}

		headers = {
			"Cookie": self.cookie
		}

your payload needs to be inside “securePassthrough”

{
   "method":"securePassthrough",
   "params":{
      "request":"<Your Payload (encrypted)>"
   }
}

Yeh It is. Here is the full method:

	def turnOn(self):
		URL = f"http://192.168.0.157/app?token={self.token}"
		Payload = {
			"method": "set_device_state",
			"params":{
				"device_on": True,
			},
			"requestTimeMils": int(round(time.time() * 1000))
		}

		headers = {
			"Cookie": self.cookie
		}

		EncryptedPayload = self.tpLinkCipher.encrypt(json.dumps(Payload))

		SecurePassthroughPayload = {
			"method":"securePassthrough",
			"params":{
				"request": EncryptedPayload
			}
		}

		r = requests.post(URL, json=SecurePassthroughPayload, headers=headers)

		decryptedResponse = self.tpLinkCipher.decrypt(r.json()["result"]["response"])

		print (decryptedResponse)