almottier / tapop100 Goto Github PK
View Code? Open in Web Editor NEWThis project forked from fishbigger/tapop100
A module for controlling the TP-Link Tapo P100 Plugs
License: MIT License
This project forked from fishbigger/tapop100
A module for controlling the TP-Link Tapo P100 Plugs
License: MIT License
Is there a reason why the function getDeviceList
is removed? I think it could be handy to have to auto detect TAPO P100 devices.
Is it possible to use the getEnergyUsage() method with an L530 bulb?
Error: {'error_code': -1002}
Traceback (most recent call last):
return self.request("get_energy_usage")
return self.protocol._request(method, params)
raise Exception(f"Error code: {data['error_code']}")
Exception: Error code: -1002
Thanks for the answer
This is a question rather than an issue.
The question is: Is it possible to control Tapo devices with wget / curl?
I'm asking because I want to control them from an openwrt router and I suspect it's difficult to get python up and running there. More difficult than wget / curl anyway.
Is it because of encryption?
With this code I tried to use the Tapo P100 / P110
from PyP100 import PyP100
p100 = PyP100.P100("192.168.178.xx", "[email protected]", "password") # creates a P100 plug object
p100.getDeviceInfo() # Returns dict with all the device info of the connected plug
I got this error message:
Failed to initialize protocol AuthProtocol
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.9/site-packages/PyP100/PyP100.py", line 35, in _initialize
protocol.Initialize()
File "/home/pi/.local/lib/python3.9/site-packages/PyP100/auth_protocol.py", li ne 110, in Initialize
raise Exception("Failed to authenticate")
Exception: Failed to authenticate
Error: {'error_code': 1003}
Failed to initialize protocol OldProtocol
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.9/site-packages/PyP100/PyP100.py", line 35, in _initialize
protocol.Initialize()
File "/home/pi/.local/lib/python3.9/site-packages/PyP100/auth_protocol.py", li ne 244, in Initialize
result = self._request_raw("handshake", {"key": public_key})
File "/home/pi/.local/lib/python3.9/site-packages/PyP100/auth_protocol.py", li ne 173, in _request_raw
raise Exception(f"Error code: {data['error_code']}")
Exception: Error code: 1003
Traceback (most recent call last):
File "/home/pi/solar/p100.py", line 10, in
p100.getDeviceInfo() # Returns dict with all the device info of the connect ed plug
File "/home/pi/.local/lib/python3.9/site-packages/PyP100/PyP100.py", line 58, in getDeviceInfo
return self.request("get_device_info")
File "/home/pi/.local/lib/python3.9/site-packages/PyP100/PyP100.py", line 46, in request
self._initialize()
File "/home/pi/.local/lib/python3.9/site-packages/PyP100/PyP100.py", line 42, in _initialize
raise Exception("Failed to initialize protocol")
Exception: Failed to initialize protocol
I use raspian os, python 3.9 and the actual firmware from Tapo.
I have no ideas what I have to change.
Thanks for your help.
Tapo P110
HW version = 1.0
FW version 1.3.0
Works fine when the plug first paired, however when the device is power cycled I get a -1003 error when calling getEnergyUsage().
Once the Tapo plug is unpaired with the app, then repaired, PyP100 works fine, but will stop working once the plug is power cycled.
Has anyone else experienced this issue, or can replicate it
Traceback (most recent call last):
File "Z:\appdata\pythonscripts\power-tapo\energyloggingTapo1.py", line 116, in <module>
main()
File "Z:\appdata\pythonscripts\power-tapo\energyloggingTapo1.py", line 56, in main
raw_data = tapo_param.getEnergyUsage()
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "Z:\appdata\pythonscripts\power-tapo\PyP100.py", line 106, in getEnergyUsage
return self.request("get_energy_usage")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "Z:\appdata\pythonscripts\power-tapo\PyP100.py", line 44, in request
return self.protocol._request(method, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "Z:\appdata\pythonscripts\power-tapo\auth_protocol.py", line 65, in _request
raise Exception(f"Error code: {data['error_code']}")
Exception: Error code: -1003
I've tried clearing the "pycache" directory, but it doesn't seem to help.
preferred_protocol argument was not set, however I have tried both. The above error, appears to be from the "new" protocol.
Hello
I have updated tapo python module to this one, unfortunately I am still getting odd error.
I am using correct parameters:
device = PyP110.P110(device_ip, tapo_username, tapo_password,preferred_protocol="new")
TAPO P110 FW: 1.3.0
Error:
Failed to initialize protocol AuthProtocol
Traceback (most recent call last):
File "/home/**/.local/lib/python3.9/site-packages/PyP100/PyP100.py", line 32, in _initialize
protocol.Initialize()
File "/home/**/.local/lib/python3.9/site-packages/PyP100/auth_protocol.py", line 110, in Initialize
raise Exception("Failed to authenticate")
Exception: Failed to authenticate
ERROR:
Failed to initialize protocol
pip list:
pkcs7 0.1.2
pycryptodome 3.19.0
PyP100 0.1.4
requests 2.31.0
Hi, I am currently using P110 plug with software version 1.3.0 with the new protocol.
I get the error Failed to initialize protocol AuthProtocol
.
I've seen in readme that the new authentication method is currently compatible with the P100 version 1.2.1 and I am wondering if that is the latest version that is tested to be compatible?
Before the software update, the connection with my plug worked fine.
Do you have any suggestions to make it compatible with the 1.3.0 version? or maybe reason for my issue could be different?
Does TapoP100 support the Tapo P115 smart plug?
After the breaking update Tapo released, I can't control my L520 light bulbs locally... I'm trying to use this library but got the following error.
Devices: Tapo L520 HW 1.0 and 1.2 FW 1.1.0.
Are these devices supported?
from PyP100 import PyL530
l530 = PyL530.L530("xxx", "yyy", "zzz")
l530.turnOn()
(.venv) o@o-MacBook-Pro tapo-library-test % cd /Users/o/Documents/prj/python/tapo-library-test ; /us
r/bin/env /Users/o/Documents/prj/python/tapo-library-test/.venv/bin/python /Users/o/.vscode/extensions/ms-py
thon.python-2023.18.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher 52792 -- /Users/o/Documents/prj
/python/tapo-library-test/tapo_test.py
Failed to initialize protocol AuthProtocol
Traceback (most recent call last):
File "/Users/o/Documents/prj/python/tapo-library-test/.venv/lib/python3.9/site-packages/PyP100/PyP100.py", line 32, in _initialize
protocol.Initialize()
File "/Users/o/Documents/prj/python/tapo-library-test/.venv/lib/python3.9/site-packages/PyP100/auth_protocol.py", line 110, in Initialize
raise Exception("Failed to authenticate")
Exception: Failed to authenticate
Error: {'error_code': 1003}
Failed to initialize protocol OldProtocol
Traceback (most recent call last):
File "/Users/o/Documents/prj/python/tapo-library-test/.venv/lib/python3.9/site-packages/PyP100/PyP100.py", line 32, in _initialize
protocol.Initialize()
File "/Users/o/Documents/prj/python/tapo-library-test/.venv/lib/python3.9/site-packages/PyP100/auth_protocol.py", line 244, in Initialize
result = self._request_raw("handshake", {"key": public_key})
File "/Users/o/Documents/prj/python/tapo-library-test/.venv/lib/python3.9/site-packages/PyP100/auth_protocol.py", line 173, in _request_raw
raise Exception(f"Error code: {data['error_code']}")
Exception: Error code: 1003
Error: {'error_code': -1003}
Traceback (most recent call last):
File "d:\Python\Training\Practice\tapo110.py", line 8, in
p110.getEnergyUsage()
File "D:\Anaconda\Lib\site-packages\PyP100\PyP100.py", line 109, in getEnergyUsage
return self.request("get_energy_usage")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Anaconda\Lib\site-packages\PyP100\PyP100.py", line 47, in request
return self.protocol._request(method, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Anaconda\Lib\site-packages\PyP100\auth_protocol.py", line 65, in _request
raise Exception(f"Error code: {data['error_code']}")
Exception: Error code: -1003
Hi Everyone,
Do you know if there is a full energy information that is not erased each day/month .
For example, like today_energy and month_energy, is it possible to get total_energy (since the begining ?)
Here is what i get from getEnergyUsage()
{'today_runtime': 60, 'month_runtime': 60, 'today_energy': 33, 'month_energy': 33, 'local_time': '2024-01-03 16:10:02', 'electricity_charge': [0, 0, 0], 'current_power': 22567}
int the tapo android app, i have 3 energy value (kWh), day, month, year.
Mickaël
Are there any specific reasons not to implement turnOnWithDelay
and turnOffWithDelay
in PyP100.py
?
Firstly thanks for your fork! Looks like most people are able to use their updated devices. I'm however still getting a 1003 error.
This is my traceback:
Failed to initialize protocol AuthProtocol Traceback (most recent call last): File "/home/pi/.local/lib/python3.9/site-packages/PyP100/PyP100.py", line 32, in _initialize protocol.Initialize() File "/home/pi/.local/lib/python3.9/site-packages/PyP100/auth_protocol.py", line 110, in Initialize raise Exception("Failed to authenticate") Exception: Failed to authenticate Error: {'error_code': 1003} Failed to initialize protocol OldProtocol Traceback (most recent call last): File "/home/pi/.local/lib/python3.9/site-packages/PyP100/PyP100.py", line 32, in _initialize protocol.Initialize() File "/home/pi/.local/lib/python3.9/site-packages/PyP100/auth_protocol.py", line 244, in Initialize result = self._request_raw("handshake", {"key": public_key}) File "/home/pi/.local/lib/python3.9/site-packages/PyP100/auth_protocol.py", line 173, in _request_raw raise Exception(f"Error code: {data['error_code']}") Exception: Error code: 1003 Traceback (most recent call last): File "/home/pi/test.py", line 9, in <module> p100.turnOn() #Turns the connected plug on File "/home/pi/.local/lib/python3.9/site-packages/PyP100/PyP100.py", line 89, in turnOn return self.set_status(True) File "/home/pi/.local/lib/python3.9/site-packages/PyP100/PyP100.py", line 86, in set_status return self._set_device_info({"device_on": status}) File "/home/pi/.local/lib/python3.9/site-packages/PyP100/PyP100.py", line 61, in _set_device_info return self.request("set_device_info", params) File "/home/pi/.local/lib/python3.9/site-packages/PyP100/PyP100.py", line 43, in request self._initialize() File "/home/pi/.local/lib/python3.9/site-packages/PyP100/PyP100.py", line 39, in _initialize raise Exception("Failed to initialize protocol") Exception: Failed to initialize protocol
I have the library that you forked, do I need to uninstall that one in order to install this one ?
Just looking at trying to get this working with some plugs running older firmware
Running
p110 = PyP110.P110(ip, user, passw, preferred_protocol="old")
Leads to a set of exceptions being thrown
Traceback (most recent call last):
File "/home/ben/.local/lib/python3.10/site-packages/PyP100/PyP100.py", line 32, in _initialize
protocol.Initialize()
File "/home/ben/.local/lib/python3.10/site-packages/PyP100/auth_protocol.py", line 244, in Initialize
result = self._request_raw("handshake", {"key": public_key})
File "/home/ben/.local/lib/python3.10/site-packages/PyP100/auth_protocol.py", line 165, in _request_raw
resp = self.session.post(url, json=payload, timeout=0.5)
File "/home/ben/.local/lib/python3.10/site-packages/requests/sessions.py", line 637, in post
return self.request("POST", url, data=data, json=json, **kwargs)
File "/home/ben/.local/lib/python3.10/site-packages/requests/sessions.py", line 589, in request
resp = self.send(prep, **send_kwargs)
File "/home/ben/.local/lib/python3.10/site-packages/requests/sessions.py", line 703, in send
r = adapter.send(request, **kwargs)
File "/home/ben/.local/lib/python3.10/site-packages/requests/adapters.py", line 507, in send
raise ConnectTimeout(e, request=request)
requests.exceptions.ConnectTimeout: HTTPConnectionPool(host='192.168.3.152', port=80): Max retries exceeded with url: /app (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x7fd032a0d720>, 'Connection to 192.168.3.152 timed out. (connect timeout=0.5)'))
Traceback (most recent call last):
File "/home/ben/Documents/src.old/tplink_smartplug_to_influxdb/./app/collect.py", line 249, in <module>
main()
File "/home/ben/Documents/src.old/tplink_smartplug_to_influxdb/./app/collect.py", line 75, in main
do_work(config, influxes)
File "/home/ben/Documents/src.old/tplink_smartplug_to_influxdb/./app/collect.py", line 115, in do_work
now_usage_w, today_usage = poll_tapo(tapo['ip'], config["tapo"]["user"], config["tapo"]["passw"])
File "/home/ben/Documents/src.old/tplink_smartplug_to_influxdb/./app/collect.py", line 193, in poll_tapo
p110.handshake() #Creates the cookies required for further methods
File "/home/ben/.local/lib/python3.10/site-packages/PyP100/PyP100.py", line 48, in handshake
self._initialize()
File "/home/ben/.local/lib/python3.10/site-packages/PyP100/PyP100.py", line 39, in _initialize
raise Exception("Failed to initialize protocol")
Exception: Failed to initialize protocol
That half-second timeout is hardcoded here.
I've edited ~/.local/lib/python3.10/site-packages/PyP100/auth_protocol.py
to bump the timeout up to a second and no longer get that exception.
Might be worth extending the timeout a little (or making it configurable)
I'm still having problems getting the code to work with my TP100 plugs. I've tried numerous ones and none of them work.
This is the following output to one of them a build firmware of 1.4.18 using the preferred_protocol="old"
Error: {'error_code': -1501}
Failed to initialize protocol OldProtocol
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.9/site-packages/PyP100/PyP100.py", line 32, in _initialize
protocol.Initialize()
File "/home/pi/.local/lib/python3.9/site-packages/PyP100/auth_protocol.py", line 258, in Initialize
result = self._request(
File "/home/pi/.local/lib/python3.9/site-packages/PyP100/auth_protocol.py", line 203, in _request
raise Exception(f"Error code: {data['error_code']}")
Exception: Error code: -1501
Traceback (most recent call last):
File "/home/pi/scripts/tapo/tapo.py", line 5, in
p100.turnOn() # Turns the connected plug on
File "/home/pi/.local/lib/python3.9/site-packages/PyP100/PyP100.py", line 89, in turnOn
return self.set_status(True)
File "/home/pi/.local/lib/python3.9/site-packages/PyP100/PyP100.py", line 86, in set_status
return self._set_device_info({"device_on": status})
File "/home/pi/.local/lib/python3.9/site-packages/PyP100/PyP100.py", line 61, in _set_device_info
return self.request("set_device_info", params)
File "/home/pi/.local/lib/python3.9/site-packages/PyP100/PyP100.py", line 43, in request
self._initialize()
File "/home/pi/.local/lib/python3.9/site-packages/PyP100/PyP100.py", line 39, in _initialize
raise Exception("Failed to initialize protocol")
Exception: Failed to initialize protocol
Hi,
I'm using Domoticz to manage many automation in my house.
I'm using many kind of different device and some of them are TP-Link brand (SmartPlug P100/P110, LightBulb L510/L610).
To control TP-Link device, I have few Domoticz plugin base on the PyP100 library.
Like many people, few weeks ago some device stop working properly when they are drive by Domoticz due to firmware upgrade (authentication vulnerability). Specially the P100 SmartPlug.
I've remove the initial PyP100 library of Fishbigger to install the PyP100 fork of Almottier.
This made my P100 plug working again but now I have some strange issue with P110/L510 and L610 device.
They all work fine for a certain time but after a random time, they stop working and I have to reboot the Domoticz server to make it run again.
The log file show error related to authentication.
Trying to identify where the problem is, I made a small python script.
import time
from PyP100 import PyP100, PyP110
p100 = PyP100.P100("192.168.1.25", "[email protected]", "mypassword")
print("Turn on")
p100.turnOn()
time.sleep(3)
print("Turn off")
p100.turnOff()
time.sleep(3)
print("get device info")
pluginfo = p100.getDeviceInfo()
print(pluginfo)
This script should turn on the plug, wait 3 second, turn off the plug, wait another 3 second and then display the device information.
When I run it, I have something strange.
Run : python3 test-p110.py
Turn on
Failed to initialize protocol AuthProtocol
Traceback (most recent call last):
File "/usr/local/lib/python3.9/dist-packages/PyP100/PyP100.py", line 23, in _initialize
protocol.Initialize()
File "/usr/local/lib/python3.9/dist-packages/PyP100/auth_protocol.py", line 109, in Initialize
raise Exception("Failed to authenticate")
Exception: Failed to authenticate
Turn off
get device info
{'device_id': '802810AB1BF7E1B4A384DBE43E7345EB30B42D13', 'fw_ver': '1.2.3 Build 230425 Rel.142542', 'hw_ver': '1.0', 'type': 'SMART.TAPOPLUG', 'model': 'P110', 'mac': '30-DE-4B-B7-3D-45', 'hw_id': '2FB30EF5BF220C44026401D373C6B55B', 'fw_id': '00000000000000000000000000000000', 'oem_id': '18BDC6C774AF8407B3EF899EACFCECF5', 'ip': '192.168.1.25', 'time_diff': 60, 'ssid': 'REJfER3t', 'rssi': -38, 'signal_level': 3, 'auto_off_status': 'off', 'auto_off_remain_time': 0, 'latitude': 493857, 'longitude': 30042, 'lang': 'fr_FR', 'avatar': 'plug', 'region': 'Europe/Paris', 'specs': '', 'nickname': 'R3VpcmxhbmRlIFNhbG9u', 'has_set_location_info': True, 'device_on': False, 'on_time': 0, 'default_states': {'type': 'last_states', 'state': {}}, 'overheated': False, 'power_protection_status': 'normal'}
The strange thing in this is the plug really turn on and off when I execute this script, even with the authentication failure message.
In Domoticz (I'm not sure but I guess), the authentication failure message stop the plugin script before the p100.turnOn() or p100.turnOff() command is execute. So the plug is not turn on or off.
Regards.
Hi, when i try run the commands for the L530 bulb ('from PyP100 import PyL530'), I get the error as seen below:
└─$ python3
Python 3.11.8 (main, Feb 7 2024, 21:52:08) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
from PyP100 import PyL530
Traceback (most recent call last):
File "", line 1, in
File "/home/zeenat/.local/lib/python3.11/site-packages/PyP100/PyL530.py", line 1, in
from PyP100 import PyP100
File "/home/zeenat/.local/lib/python3.11/site-packages/PyP100/PyP100.py", line 9, in
from Crypto.Cipher import AES, PKCS1_OAEP, PKCS1_v1_5
File "/home/zeenat/.local/lib/python3.11/site-packages/Crypto/Cipher/init.py", line 33, in
from Crypto.Cipher._mode_ccm import _create_ccm_cipher
File "/home/zeenat/.local/lib/python3.11/site-packages/Crypto/Cipher/_mode_ccm.py", line 47, in
from Crypto.Hash import BLAKE2s
ImportError: cannot import name 'BLAKE2s' from 'Crypto.Hash' (/home/zeenat/.local/lib/python3.11/site-packages/Crypto/Hash/init.py)
I have ran the command 'pip install PyP100'
is there any help for this?
Hi, I tried running the your code with my username, password and IP.
Device Type: Tapo P100
Hardware version: 2.0
Firmware Version: 1.2.1
I am getting below response:
Traceback (most recent call last):
File "C:\Users\xviewla\OneDrive - Konecranes Plc\Desktop\CodeBase\TapoP100-main\power_control.py", line 7, in
p100.handshake() # Creates the cookies required for further methods
^^^^^^^^^^^^^^^^
File "C:\Users\xviewla\OneDrive - Konecranes Plc\Desktop\CodeBase\TapoP100-main\PyP100\PyP100.py", line 136, in handshake
encryptedKey = r.json()["result"]["key"]
~~~~~~~~^^^^^^^^^^
KeyError: 'result'
Session: <bound method Response.json of <Response [200]>>
Session: {'error_code': 1003}
Process finished with exit code 1
I have a Tapo P105 with following information:
Hardware Version: 1.0.0
Firmware Version: 1.4.1
I can execute .getDeviceInfo() and .get_status(), but if I try to execute .turnOn(), I get
Exception: Error Code: -1012
How do I solve this?
Hello, I wrote a script that control a lamp color based on the decibel levels measured by a microphone. I'm using it to help customers of a winery out of my windows to control the loudness of their voices. The script runs automatically every night in a raspberry pi. To deal disconnections and reconnections I added to the script a function that goes like this
connection=False
def connect_lamp():
try:
global l530sec
l530sec = PyL530.L530("xxx.xxx.xxx", "me@mymail", "mypassowrd")
l530sec.handshake() #Creates the cookies required for further methods
l530sec.login() #Sends credentials to the plug and creates AES Key and IV for further methods
global connection
connection=True
except Exception as e:
#print(e)
connection=False
return
while connection==False:
connect_lamp()
This function work perfectly if the lamp is offline when the script is started, but if the connection is lost afterwards it give the 403 Client Error: Forbidden for etc..
I can share the entire script here or on my github, any suggestion will be greatly appreciated, having this script running properly is of vital importance!!
Thank you very much
Federico
Thanks for solving the problem
Just a small add to your comments
Be carefull if you combine devices with the old protocol and the new one.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.