Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.