-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-thermostat-data.ps1
56 lines (41 loc) · 1.32 KB
/
get-thermostat-data.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
param
(
[Parameter(Mandatory = $true)] [string] $ApiKey
, [Parameter(Mandatory = $true)] [string] $TokenFile
, [Parameter(Mandatory = $false)] [string] $BaseUri = "https://api.ecobee.com/"
)
$tokenData = Get-Content -Path $TokenFile | ConvertFrom-Json
# refresh the token
$uri = ("{0}token?grant_type=refresh_token&refresh_token={1}&client_id={2}" -f $BaseUri,$tokenData.refresh_token,$ApiKey)
$uri
try{
$response = Invoke-RestMethod -Uri $uri -Method Post
} catch {
$Error[0]
exit
}
$accessToken = $response.access_token
# Save the tokens
$response | ConvertTo-Json | Out-File -FilePath ecobeeToken.json
# get the thermostat data
#`{'selection':`{'selectionType':'registered','selectionMatch':'','includeRuntime':true`}`}
$uri = "$baseuri/1/thermostat?format=json&body=`{'selection':`{'selectionType':'registered','selectionMatch':'','includeRuntime':true,'includeSettings':true,'includeExtendedRuntime':true,'includeEvents':true,'includeDevice':true`}`}"
$uri
try{
$response = Invoke-WebRequest -Uri $uri -Headers @{"Authorization"="Bearer $accessToken"}
} catch {
$Error[0]
exit
}
$response
$jsonResponse = $response.Content | ConvertFrom-Json
foreach($t in $jsonResponse.thermostatList)
{
$t | fl *
"runtime"
$t.runtime | fl *
"events"
$t.events.count
$t.events
}