-
Notifications
You must be signed in to change notification settings - Fork 0
/
Smartthings.ps1
43 lines (41 loc) · 1.71 KB
/
Smartthings.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
$token="PERSONAL_ACCESS_TOKEN"
$headers=@{
Authorization = "Bearer $token"
}
$url="https://api.smartthings.com/v1/devices"
$offcommandhash = @{
"component"="main";
"capability"="switch";
"command"="off";
}
$oncommandhash = @{
"component"="main";
"capability"="switch";
"command"="on";
}
$offcommand = "[$($offcommandhash | ConvertTo-Json)]"
$oncommand = "[$($oncommandhash | ConvertTo-Json)]"
$things = (invoke-RestMethod -Method Get -Uri $url -Headers $headers).items
function toggle-lights(){
param([string]$DeviceLabel)
foreach($thing in $things){
if($thing.components.capabilities.id -contains "switch"){
if($thing.label -eq $DeviceLabel){
write-host $thing.label
$lightstatus = (Invoke-RestMethod -Method GET -uri "https://api.smartthings.com/v1/devices/$($thing.deviceid)/status" -headers $headers).components.main.switch.switch.value
$commandURL = "https://api.smartthings.com/v1/devices/$($thing.deviceid)/commands"
write-host $commandurl
write-host "-----"
if(($lightstatus -eq "off")){
write-host "ON"
invoke-RestMethod -Method POST -Uri $commandURL -Headers $headers -Body $oncommand
} else {
write-host "OFF"
invoke-RestMethod -Method POST -Uri $commandURL -Headers $headers -Body $offcommand
}
Invoke-RestMethod -Method GET -uri "https://api.smartthings.com/v1/devices/$($thing.deviceid)/status" -headers $headers
}
}
}
}
do{toggle-lights -devicelabel "FamilyRoom South East 1"}while($true)