Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't get it to work #84

Open
anzgar01 opened this issue Mar 9, 2023 · 5 comments
Open

can't get it to work #84

anzgar01 opened this issue Mar 9, 2023 · 5 comments

Comments

@anzgar01
Copy link

anzgar01 commented Mar 9, 2023

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!!

@manuhakala98
Copy link

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?

@anzgar01
Copy link
Author

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

@manuhakala98
Copy link

manuhakala98 commented Sep 28, 2023

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.

@MattF42
Copy link

MattF42 commented Oct 9, 2023

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

@anasgasser
Copy link

anasgasser commented Apr 17, 2024

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants