mihai-dinculescu / tapo

Unofficial Tapo API Client. Works with TP-Link Tapo smart devices. Tested with light bulbs (L510, L520, L530, L610, L630), light strips (L900, L920, L930), plugs (P100, P105, P110, P115, P300), hubs (H100), switches (S200B) and sensors (KE100, T100, T110, T300, T310, T315).
MIT License
339 stars 35 forks source link

Question: Tapo P115 Energy Data #117

Closed tuvok81 closed 10 months ago

tuvok81 commented 10 months ago

Hello Guys, my first question is .. is this possible to read with the python script the Energy data from the device? When yes.. where i get the Username and Passwort... in the App i can not find them thanks

mihai-dinculescu commented 10 months ago

Yes, it is possible, and this example shows you how. The username and password are the e-mail and password you use to log into the TP-Link mobile app.

tuvok81 commented 10 months ago

AH ok thank you but i think i have a other fail ..

python tapo_p110.py Traceback (most recent call last): File "/home/websdr/Downloads/tapo_p110.py", line 61, in <module> asyncio.run(main()) File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete return future.result() File "/home/websdr/Downloads/tapo_p110.py", line 15, in main client = ApiClient(tapo_username, tapo_password) TypeError: argument 'tapo_username': 'NoneType' object cannot be converted to 'PyString'

mihai-dinculescu commented 10 months ago

It looks like it's complaining that the tapo_username variable is empty.

The example is trying to read it from an environment variable. Have you set the environment variables? The README has a section on that.

tuvok81 commented 10 months ago

I'm not that good at programming things... I'll see if I can find something

thanks

tuvok81 commented 10 months ago

hm i dont no .. iam to stupid for this manual ..

mihai-dinculescu commented 10 months ago

On Linux/Mac you can give values to environment variables like this

export TAPO_USERNAME=your-tapo-@email.com
export TAPO_PASSWORD=your-tapo-password
export IP_ADDRESS=192.168.1.XXX

On Windows you can do it with

set TAPO_USERNAME=your-tapo-@email.com
set TAPO_PASSWORD=your-tapo-password
set IP_ADDRESS=192.168.1.XXX
tuvok81 commented 10 months ago

OK .. i have add the username and password and Ip here

    tapo_username = os.getenv("@gmx.de")
    tapo_password = os.getenv("**")
    ip_address = os.getenv("192.168.168.21")

and where i add the export lines? at the top of the script? i use Linux Ubunut .. and SORRY for the many stupid questions..

tuvok81 commented 10 months ago

OK i have see my poetry make some things ..

pipx upgrade poetry poetry is already at latest version 1.6.1 (location: /root/.local/pipx/venvs/poetry)

poetry install

The lock file is not compatible with the current version of Poetry. Upgrade Poetry to be able to read the lock file or, alternatively, regenerate the lock file with the poetry lock command.

no idea

tuvok81 commented 10 months ago

Puhh.. i have no idea .. what i do here ..

Compiling tokio-macros v2.1.0 Compiling num_cpus v1.16.0 Compiling base16ct v0.2.0 Compiling base64 v0.21.4 Compiling lazy_static v1.4.0 Compiling tapo v0.7.4 (/home/websdr/Downloads/tapo/tapo) Compiling tokio v1.33.0 Compiling pretty_env_logger v0.5.0 Finished dev [unoptimized + debuginfo] target(s) in 2m 07s Running target/debug/examples/tapo_p110 Error: NotPresent websdr@wmk:~/Downloads/tapo$ cargo run --example tapo_p110 Finished dev [unoptimized + debuginfo] target(s) in 0.21s Running target/debug/examples/tapo_p110 Error: NotPresent

pwoerndle commented 10 months ago

Looks like the environment variables are still not read properly.

Try the following:

  1. Change the variable definitions in examples/tapo_p110 back to the original version:
    let tapo_username = env::var("TAPO_USERNAME")?;
    let tapo_password = env::var("TAPO_PASSWORD")?;
    let ip_address = env::var("IP_ADDRESS")?;
  2. Before executing cargo run --example tapo_p110 execute the following commands @mihai-dinculescu suggested above on your Linux shell using your own credentials and the IP of your device:
    
    export TAPO_USERNAME=your-tapo-@email.com
    export TAPO_PASSWORD=your-tapo-password
    export IP_ADDRESS=192.168.1.XXX

cargo run --example tapo_p110

tuvok81 commented 10 months ago

AHH thanks it run!! but .... the cargo run have disable the plug .. and the maschine goes offline where is on the plug hmm

2023-10-15T11:22:11.527Z INFO tapo_p110 > Energy data (hourly): EnergyDataResult { local_time: 2023-10-15T13:22:10, data: [13, 14, 13, 14, 13, 14, 13, 14, 14, 13, 14, 13, 16, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], start_timestamp: 1697328000, end_timestamp: 1697414399, interval: 60 } 2023-10-15T11:22:11.572Z INFO tapo_p110 > Energy data (daily): EnergyDataResult { local_time: 2023-10-15T13:22:10, data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 191, 486, 186, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], start_timestamp: 1696118400, end_timestamp: 1696118400, interval: 1440 }

tuvok81 commented 10 months ago

OK the last step is the poetry Problem @pwoerndle can you help here?

poetry shell
Spawning shell within /home/websdr/.cache/pypoetry/virtualenvs/tapo-Vr2UzEfI-py3.10
websdr@wmk:~/Downloads/tapo/tapo-py$ . /home/websdr/.cache/pypoetry/virtualenvs/tapo-Vr2UzEfI-py3.10/bin/activate
(tapo-Vr2UzEfI-py3.10) websdr@wmk:~/Downloads/tapo/tapo-py$ export TAPO_USERNAME=*gmx.de
(tapo-Vr2UzEfI-py3.10) websdr@wmk:~/Downloads/tapo/tapo-py$ export TAPO_PASSWORD=*
(tapo-Vr2UzEfI-py3.10) websdr@wmk:~/Downloads/tapo/tapo-py$ export IP_ADDRESS=192.168.10.5
(tapo-Vr2UzEfI-py3.10) websdr@wmk:~/Downloads/tapo/tapo-py$ python examples/tapo_p110.py
Traceback (most recent call last):
  File "/home/websdr/Downloads/tapo/tapo-py/examples/tapo_p110.py", line 7, in <module>
    from tapo import ApiClient, EnergyDataInterval
ModuleNotFoundError: No module named 'tapo'
pwoerndle commented 10 months ago

I'm not super familiar with the python build, but did you run poetry install before running poetry shell?

If your just interested in trying out and you don't need to build from source, you could also just use pip to install the tapo module and then run the example.

pip install tapo

export TAPO_USERNAME=your-tapo-@email.com
export TAPO_PASSWORD=your-tapo-password
export IP_ADDRESS=192.168.1.XXX

python examples/tapo_p110.py
tuvok81 commented 10 months ago

i haved do pip install tapo and poetry install .. before i run .. i have not copy this from the shell sorry