Skip to content

Instantly share code, notes, and snippets.

@darrenjrobinson
Last active March 16, 2018 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darrenjrobinson/0c0744a9868ff4e36ab776173f0889f4 to your computer and use it in GitHub Desktop.
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
# 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