mirror of
https://github.com/paradizelost/Powershell-Public.git
synced 2024-11-25 02:04:43 -06:00
Get status and flipflop
Added pull for current light status to toggle rather than using a random.
This commit is contained in:
parent
281190e0e2
commit
9ba565b408
@ -3,10 +3,6 @@ $headers=@{
|
|||||||
Authorization = "Bearer $token"
|
Authorization = "Bearer $token"
|
||||||
}
|
}
|
||||||
$url="https://api.smartthings.com/v1/devices"
|
$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 = @{
|
$offcommandhash = @{
|
||||||
"component"="main";
|
"component"="main";
|
||||||
"capability"="switch";
|
"capability"="switch";
|
||||||
@ -19,20 +15,29 @@ foreach($thing in $things){
|
|||||||
}
|
}
|
||||||
$offcommand = "[$($offcommandhash | ConvertTo-Json)]"
|
$offcommand = "[$($offcommandhash | ConvertTo-Json)]"
|
||||||
$oncommand = "[$($oncommandhash | ConvertTo-Json)]"
|
$oncommand = "[$($oncommandhash | ConvertTo-Json)]"
|
||||||
if($thing.label -eq "FamilyRoom South East 1"){
|
$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"
|
$commandURL = "https://api.smartthings.com/v1/devices/$($thing.deviceid)/commands"
|
||||||
write-host $commandurl
|
write-host $commandurl
|
||||||
do{
|
|
||||||
write-host "-----"
|
write-host "-----"
|
||||||
if((get-random -Minimum 0 -Maximum 2)){
|
if(($lightstatus -eq "off")){
|
||||||
write-host "ON"
|
write-host "ON"
|
||||||
invoke-RestMethod -Method POST -Uri $commandURL -Headers $headers -Body $oncommand
|
invoke-RestMethod -Method POST -Uri $commandURL -Headers $headers -Body $oncommand
|
||||||
} else {
|
} else {
|
||||||
write-host "OFF"
|
write-host "OFF"
|
||||||
invoke-RestMethod -Method POST -Uri $commandURL -Headers $headers -Body $offcommand
|
invoke-RestMethod -Method POST -Uri $commandURL -Headers $headers -Body $offcommand
|
||||||
}
|
}
|
||||||
start-sleep 3
|
Invoke-RestMethod -Method GET -uri "https://api.smartthings.com/v1/devices/$($thing.deviceid)/status" -headers $headers
|
||||||
} while($true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
do{toggle-lights -devicelabel "FamilyRoom South East 1"}while($true)
|
||||||
|
Loading…
Reference in New Issue
Block a user