I am trying to create Powershell script to read TP-LINK HS 110 daily / monthly power consumption using Invoke-WebRequest command.
I am able to get token from https://wap.tplinkcloud.com and also to get my device ID. Then when i try to use {‘system’:{‘get_sysinfo’:{}}} or {‘emeter’:{‘get_daystat’:{‘month’:2,‘year’:2018}}} it ends after few seconds with request timeout message. What i am doing wrong?
Here is command list:
Here is a PowerShell example:
$authToken = “TOKEN FROM LOGIN REQUEST”
$euUri = “https://eu-wap.tplinkcloud.com” (FROM deviceList.appServerUrl)
$addr = $euUri + “?token=” + $authToken
$devID = “DEVICE ID FROM {‘method’:‘getDeviceList’}”
$command = “{‘system’:{‘get_sysinfo’:null}}”
$getStat = “{‘method’:‘passthrough’,‘params’:{‘deviceId’:’”+$devID+"’,‘requestData’:"+$command+"}}"
$result = Invoke-WebRequest -Uri $addr -Method POST -Body $getStat -ContentType “application/json” -TimeoutSec 60
And the response is {“error_code”:-20002,“msg”:“Request timeout”}
Do you have a SmartThings and SmartThings account?
I have groovy code on gitHub in a service manager and device handler that may be of assistance. It includes cloud login. Additionally, it includes the commands to get daily data for for the last 31 days (I then average them, like the Kasa App). There is also another command to the plug that gets monthly totals for a year or so.
The energy meter commands are (need to change month and year.
Get Daily Statistic for given Month: {“emeter”:{“get_daystat”:{“month”:1,“year”:2016}}}
Get Montly Statistic for given Year: {“emeter”:{"“get_monthstat”:{“year”:2016}}
Finally, if you are local to the device (on same network), you can control it without going through the cloud. I used node.js to test the bulbs and plugs originally (flush out the commands). Also, I created a logger you can use as an example. It gets the current usage periodically, but changing the frequency and command would allow daily logging. Location: https://github.com/DaveGut/TP-Link-Power-Logger