fishbigger / TapoP100

A module for controlling the TP-Link Tapo P100 Plugs
MIT License
566 stars 138 forks source link

Help sought for JSON payload formatting to use on Streamdeck API plugin #94

Open stylemessiah opened 1 year ago

stylemessiah commented 1 year ago

Theres a plugin that allows to use GET/POST/PUT API commands and see the result on the Stream Deck, as it only allows js and compiled .exe plugins.

Im lookign for the ability to turn on/off via a Streamdeck button and also display 2 simple current stats, hours on, current Kwh, and current watts on a Streamdeck button

Any guide of a payload format for would greatly appreciated - specifically unsure how to deal with the encryption

While i have things working with this python method, it cant display the output on Streamdeck....which would be handy.....

Im just looking for some guidance, im okay with having a fiddle, but its out of my confort zone.

I did start thinking runnign a local webserver via python that polls the plugs and creates an endpoint i could access via the Streamdeck API Ninja plugin might be a way to go, but if i could just use a POST call it seems a lot easier and less faff

As a complete newbie to Python last week, i did manage this by myself, so up for a tinker...have to love not having to declare the end of a loop, just indent and lines in it....nice

import json
import datetime
import base64

plugips = ["10.0.0.64", "10.0.0.65"]
username = "xxxxxxxxx@gmail.com"
password = "xxxxxxx"

for x in plugips:
    from PyP100 import PyP110
    p110 = PyP110.P110(x, username, password)
    p110.handshake()
    p110.login()
    returnedData = p110.getDeviceInfo()
    nickname = base64.b64decode(returnedData['result']['nickname'])
    nicknameDecoded = nickname.decode("utf-8")
    print ("Plug Name:", nicknameDecoded)
    print ("Device IP:", returnedData['result']['ip'])
    print ("Device On:", returnedData['result']['device_on'])
    print ("Device Model:", returnedData['result']['model'])
    print ("Firmware Ver:", returnedData['result']['fw_ver'])
    print ("Device ID:", returnedData['result']['device_id'])
    print ("MAC:", returnedData['result']['mac'])
    print ("Device On Time:", (datetime.timedelta(seconds=(returnedData['result']['on_time']))))
    print ("Device Overheated:", returnedData['result']['overheated'])
    print ("Power Protection:", returnedData['result']['power_protection_status'])
    print ("RSSI:", returnedData['result']['rssi'])
    print ("Signal Level:", returnedData['result']['signal_level'])
    print (" ")
    returnedData = p110.getEnergyUsage()
    print("Current Stats:")
    todayRuntime = round((returnedData['result']['today_runtime'] / 60), 1)
    print ("Hours:", todayRuntime)
    todayEnergy = round ((returnedData['result']['today_energy'] / 1000), 2)
    print ("kWh:", todayEnergy)
    currentPower = round((returnedData['result']['current_power'] / 1000))
    print ("Watts:", currentPower)
    print (" ")