Open anzgar01 opened 1 year ago
Hi, sorry but I just don't get it :-( What do I need to do to switch on and off a P100? I tried to copy the example into a python script and changed user, password and IP. I do get information from the device, but how on earth do I switch it on or off? Thanks a lot!!
Did you find answer to this?
Well, I did get it to work after a hundred tried, resetting passwords etc I have no clue as to why it is working now, but I sure as hell won't change anything :-) Sorry I can't tell you what did the trick in the end
I mean, I can also query information of the p100 device with the example code, but I dont know how to turn p100 on or off. Propably need to use PlugDevice class..?
Edit. I managed to get it to work using that PlugDevice class.
For those of you wondering what on earth the above means:
#!/usr/bin/python3
import asyncio
import os
from plugp100.api.plug_device import PlugDevice
from plugp100.api.tapo_client import TapoClient
from plugp100.common.credentials import AuthCredential
async def main():
# create generic tapo api
username = os.getenv("USERNAME", "XXXXXXXXXXXX")
password = os.getenv("PASSWORD", "XXXXXXXXXXXX")
credentials = AuthCredential(username, password)
client = TapoClient(credentials, "192.168.1.X")
await client.initialize()
print(await client.get_device_info())
plug = PlugDevice(client)
print(await plug.off())
if __name__ == "__main__":
loop = asyncio.new_event_loop()
loop.run_until_complete(main())
loop.run_until_complete(asyncio.sleep(0.1))
loop.close()
Turns off my P105 plug :)
Obviously you need to replace the X as appropraite
It took me a while, especially since the repository was updated and the module PlugDevice is not in plugp100/api anymore. Here is how to switch the plug on and off (commented). This works fine for P115
import asyncio
from plugp100.common.credentials import AuthCredential
from plugp100.new.device_factory import connect, DeviceConnectConfiguration
import nest_asyncio
nest_asyncio.apply()
async def example_connect_by_guessing(credentials: AuthCredential, host: str):
device_configuration = DeviceConnectConfiguration(
host=host,
credentials=credentials
)
device = await connect(device_configuration)
await device.update()
await device.turn_on() # Turning device on
# await device.turn_off() # Turning device off
async def main():
credentials = AuthCredential("<TAPO_USERNAME>", "<TAPO_PASSWORD>")
await example_connect_by_guessing(credentials, "<PLUG_IP>")
if name == "main":
loop = asyncio.new_event_loop()
loop.run_until_complete(main())
loop.run_until_complete(asyncio.sleep(0.1))
loop.close()
Hi, sorry but I just don't get it :-( What do I need to do to switch on and off a P100? I tried to copy the example into a python script and changed user, password and IP. I do get information from the device, but how on earth do I switch it on or off? Thanks a lot!!