-
-
Save darrenjrobinson/0c0744a9868ff4e36ab776173f0889f4 to your computer and use it in GitHub Desktop.
Get the state of a hue light. If ON turn OFF, if OFF turn ON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Hue Bridge | |
$hueBridge = "http://<huebridge>/api" | |
# Light to control | |
$lightNumber = 5 | |
# Username | |
$username = 'xgwoLFMYggwjPkzaoLF234567890' | |
$result = Invoke-RestMethod -Method Get -Uri "$($hueBridge)/$($username)/lights" | |
$currentState = $result.$lightNumber | select state | |
If ($currentState.state.on.Equals($false)){ | |
$body = @{"on"=$true} | ConvertTo-Json | |
write-host "Light 5 is OFF, turning it ON" | |
} else { | |
$body = @{"on"=$false} | ConvertTo-Json | |
write-host "Light 5 is ON, turning it OFF" | |
} | |
$result = Invoke-RestMethod -Method PUT -Uri "$($hueBridge)/$($username)/lights/$($lightNumber)/state" -Body $body | |
$result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment