mirror of
https://github.com/paradizelost/Powershell-Public.git
synced 2024-11-25 02:04:43 -06:00
Initial Commit of Powershell script to work with smartthings rest api
This commit is contained in:
parent
e7b016871d
commit
281190e0e2
38
Smartthings.ps1
Normal file
38
Smartthings.ps1
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
$token="PERSONAL_ACCESS_TOKEN"
|
||||||
|
$headers=@{
|
||||||
|
Authorization = "Bearer $token"
|
||||||
|
}
|
||||||
|
$url="https://api.smartthings.com/v1/devices"
|
||||||
|
$things = (invoke-RestMethod -Method Get -Uri $url -Headers $headers).items
|
||||||
|
foreach($thing in $things){
|
||||||
|
if($thing.components.capabilities.id -contains "switch"){
|
||||||
|
write-host $thing.label
|
||||||
|
$offcommandhash = @{
|
||||||
|
"component"="main";
|
||||||
|
"capability"="switch";
|
||||||
|
"command"="off";
|
||||||
|
}
|
||||||
|
$oncommandhash = @{
|
||||||
|
"component"="main";
|
||||||
|
"capability"="switch";
|
||||||
|
"command"="on";
|
||||||
|
}
|
||||||
|
$offcommand = "[$($offcommandhash | ConvertTo-Json)]"
|
||||||
|
$oncommand = "[$($oncommandhash | ConvertTo-Json)]"
|
||||||
|
if($thing.label -eq "FamilyRoom South East 1"){
|
||||||
|
$commandURL = "https://api.smartthings.com/v1/devices/$($thing.deviceid)/commands"
|
||||||
|
write-host $commandurl
|
||||||
|
do{
|
||||||
|
write-host "-----"
|
||||||
|
if((get-random -Minimum 0 -Maximum 2)){
|
||||||
|
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
|
||||||
|
}
|
||||||
|
start-sleep 3
|
||||||
|
} while($true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user