TP-LINK HS110 Get daily power consumption via PowerShell


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 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:
$euUri = “” (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”}

Thank you for help.

Is the purpose of this so you can track usage over time?

Exactly. The mobile Kasa app only showing averages. I would like to have detailed stats.

@Gutheinz maybe able to assist as he wrote the dth and smartapp for the tp interface

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.

Device Handler file: (Cloud) TP-Link Plug-Switch.groovy

Service Manager file: TPLink Cloud Connect V2.groovy

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:

@Gutheinz Thank you. But there is a requirement that this must be done in PowerShell…

Here is complete source code:

I am using exactly the same syntax to get daily statistic for given month

Still getting {“error_code”:-20002,“msg”:“Request timeout”} as response.

One potential error comparing my groovy code with yours:

$addr = $euUri + “?token=” + $authToken

should be

$addr = $euUri + “/?token=” + $authToken

There should be a “/” after the $euUri.


PS - This was done by comparing your code to my Service Manager code mentioned in initial response.

this code is working
find and replace XXXXX with your config


$uri = “
$euUri = “
#Some random GUID
$uid = “84ddc92e-c0be-4132-91cb-13305db401a9”

#Login to get token
$login = “{‘method’: ‘login’,‘params’: {‘appType’: ‘Kasa_Android’,‘cloudUserName’: ‘XXXX’,‘cloudPassword’: ‘XXXX’,‘terminalUUID’: $uid }}”
Write-Host “Getting token” -ForegroundColor Yellow
$loginResult = Invoke-WebRequest -Uri $uri -Method POST -Body $login -ContentType “application/json”
$resultJson = $loginResult.Content | ConvertFrom-Json
$authToken = $resultJson.result.token
Write-Host “Token is” $authToken -ForegroundColor Green

#Use device list to get device ID
$getDevice = “{‘method’:‘getDeviceList’}”
$addr = $euUri + “?token=” + $authToken
Write-Host “Getting device ID” -ForegroundColor Yellow
$deviceResult = Invoke-WebRequest -Uri $addr -Method POST -Body $getDevice -ContentType “application/json”
$resultJson = $deviceResult.Content | ConvertFrom-Json
$devID = $resultJson.result.deviceList[0].deviceId
Write-Host “Device ID is” $devID -ForegroundColor Green

#Call emeter to get some power usage data
Write-Host “Getting power usage data” -ForegroundColor Yellow

$command = “{‘system’:{‘get_sysinfo’:null}}”


#Show the command
Write-Host $getStat

#Send request
$deviceResult = Invoke-WebRequest -Uri $addr -Method POST -Body $getStat -ContentType “application/json” -TimeoutSec 60

requestData value is a string " {json}"

Hi all,

I’m trying this:


But get always wrong JSON Format:

StatusCode : 200
StatusDescription : OK
Content : {“error_code”:-10100,“msg”:“JSON format error”}
RawContent : HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 47
Content-Type: application/json;charset=UTF-8
Date: Sun, 29 Dec 2019 19:33:06 GMT
Server: Apache-Coyote/1.1


Forms : {}
Headers : {[Connection, keep-alive], [Content-Length, 47], [Content-Type, application/json;charset=UTF-8], [Date, Sun, 29 Dec 2019 19:33:06 GMT]…}
Images : {}
InputFields : {}
Links : {}
ParsedHtml : mshtml.HTMLDocumentClass
RawContentLength : 47

what is the issue?