TP-Link Tapo P100

Thanks for reactivity :smile:

With a few editing (maybe wrong idk) on switch.py, I’m stiil having a last error on my HA log :

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 197, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/tapo_p100_control/switch.py", line 37, in setup_platform
    add_entities([P100Plug(p100)])
  File "/config/custom_components/tapo_p100_control/switch.py", line 44, in __init__
    self.is_on = False
AttributeError: can't set attribute

Currently searching how to fix it !

EDIT :

FIx !

Juste edit the

self.is_on

by

self._is_on

Another error now :

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 197, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/tapo_p100_control/switch.py", line 37, in setup_platform
    add_entities([P100Plug(p100)])
  File "/config/custom_components/tapo_p100_control/switch.py", line 45, in __init__
    self.update()
  File "/config/custom_components/tapo_p100_control/switch.py", line 77, in update
    self._is_on = data["device_on"]
TypeError: string indices must be integers

I already fix it on my last test in local environnement by convert the string in JSON, example :

from PyP100 import PyP100
import json

def isAllume() :
        p100 = PyP100.P100("192.168.x.x", "[email protected]", "password")

        p100.handshake()
        p100.login()

        capteur = p100.getDeviceInfo()
        newCapteur = json.loads(capteur)
        return(newCapteur["result"]["device_on"])

isAllume()

I think it might be an indentation issue. Looking at the github repo I can see that I have accidentally indented all the functions into is_on()

Edit:
I have now changed the github repo but I reckon that’s not the issue :frowning:

Edit 2:
I think I have fixed it now :slight_smile: there was a missing under score in __init__ The function should now read:

def __init__(self, p100):
        self._p100 = p100
        self._is_on = False
        self.update() 

It’s working !

List of the edits :

from homeassistant.components.switch import SwitchEntity
from homeassistant.const import CONF_IP_ADDRESS, CONF_EMAIL, CONF_PASSWORD
[ADD]from homeassistant.components.switch import PLATFORM_SCHEMA

# Validation of the user's configuration
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_IP_ADDRESS): cv.string,
    [EDIT]vol.Required(CONF_EMAIL): cv.string,
    vol.Required(CONF_PASSWORD): cv.string,
})

Then :

self._p100 = p100

        [EDIT]self._is_on = False

        self.update()

Then add :

import json

And edit :

def update(self):

        self._p100.handshake()

        self._p100.login()

        data = self._p100.getDeviceInfo()

        data = json.loads(data)

        self._is_on = data["result"]["device_on"]

I have now the entitie working :

2020-10-31 10_32_39-Window

When you flick it does the plug turn on and off?

Yup !

Link with with my Xiaomi button and this is working

2020-10-31 10_37_42-Window

Thank you it’s amazing ! I was searching a solution for months

1 Like

Do you have a github account that I can add you as a contributor to the readme as you helped massively to trouble shoot the intergration :slight_smile:

Oh of course thank you

After downlading the last commit, you have littles bugs in it :

Line 57 switch.py

return self.is_on

Instead of

return self._is_on

And multiples spaces instead of indentation, you should juste replace them by tabulation and it’s working perfectly

I will change that now

Thanks everybody for all your help on this. Thanks to @vbtrek for raising this question. I have released the first fully working version on github along with the installation instructions. Please continue the discussion at [Custom Component] Tapo P100 Plug Control and I will continue to update the intergration with new features (Starting with getting the name of the plug)

3 Likes

Thank you for all of your work everyone, Its great to see.

Do you think its likely for TP Link to change the way it works so this stops working?

Only reason I ask is because not being able to control the Tapo plugs other than with the app (plus smart Assistants) has been kept me from buying them but with this I might buy.

Good job @fishbigger. I got it working without much fuss. :slight_smile:

any idea guys ?

Logger: homeassistant.components.switch
Source: custom_components/tapo_p100_control/switch.py:79
Integration: Switch (documentation, issues)
First occurred: 7:51:03 PM (1 occurrences)
Last logged: 7:51:03 PM

Error while setting up tapo_p100_control platform for switch

Traceback (most recent call last): File “/usr/local/lib/python3.8/site-packages/PyP100/PyP100.py”, line 155, in login self.token = ast.literal_eval(decryptedResponse)[“result”][“token”] KeyError: ‘result’ During handling of the above exception, another exception occurred: Traceback (most recent call last): File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 197, in _async_setup_platform await asyncio.shield(task) File “/usr/local/lib/python3.8/concurrent/futures/thread.py”, line 57, in run result = self.fn(*self.args, **self.kwargs) File “/config/custom_components/tapo_p100_control/switch.py”, line 41, in setup_platform add_entities([P100Plug(p100)]) File “/config/custom_components/tapo_p100_control/switch.py”, line 49, in init self.update() File “/config/custom_components/tapo_p100_control/switch.py”, line 79, in update self._p100.login() File “/usr/local/lib/python3.8/site-packages/PyP100/PyP100.py”, line 159, in login raise Exception(f"Error Code: {errorCode}, {errorMessage}") Exception: Error Code: -1501, Invalid Request or Credentials

I’m getting the following configuration error:
Platform error switch.tapo_p100_control - Integration ‘tapo_p100_control’ not found.

Any idea’s please?

Have you restarted your Home Assistant after installing the custom integration?

Are you 100% your credentials are ok? From the error it seems that the crendentials don’t appear to be correct,
Exception: Error Code: -1501, Invalid Request or Credentials

I can’t restart Home Assistant with the config error, Checked and rechecked credentials. Error log

Log Details (ERROR)

Logger: homeassistant.components.hassio
Source: components/hassio/init.py:383
Integration: Hass.io (documentation, issues)
First occurred: 20:16:31 (1 occurrences)
Last logged: 20:16:31

Platform error switch.tapo_p100_control - Integration ‘tapo_p100_control’ not found.

Presuming you’ve copied the folder across successfully, it sounds like you need to comment out (put a # in front of) the Tapo config lines and, if you’ve not already, restart HA. It should then recognise the folder in Custom Components, and then you can add them back in and restart again.

Folder copied to config\custom_components. Commented out switch: section, restarted HA and reinstated switch: same issue. Also tried recreating new Tapo account with no joy.
Could it be a permissions issue? I don’t know how to check that

oops found a typo in folder name. Now have the following error:

Platform error switch.tapo_p100_control - No module named ‘PyP100’