Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # PowerShell script to randomly set a bulb to a random color (from a pre-defined list) and random brightness.
- function Hue-Command([string]$light, [string]$func, [string]$json)
- {
- # Convert post data to UTF8.
- $post = [System.Text.Encoding]::UTF8.GetBytes($json)
- # Define location of Hue bridge, could just as easily be passed to the function via variable.
- $url = "http://192.168.1.114/api/58d35ff5cd80afcc09d4b77e70567590/lights/{0}/{1}" -f $light,$func
- # Build WebRequest. Make sure to set the type to PUT, the content to text/plain and the length just in case. May be able to get away without this but why bother.
- $http = [System.Net.WebRequest]::Create($url)
- $http.Method = "PUT"
- $http.ContentType = "text/plain"
- $http.ContentLength = $post.Length
- $http.ServicePoint.Expect100Continue = $false
- # Create, comit and close stream.
- $stream = $http.GetRequestStream()
- $stream.Write($post, 0, $post.Length)
- $stream.Close()
- # Capture response, if you don't care if it fails or not you could probably skip this, but...
- [System.Net.WebResponse] $response = $http.GetResponse();
- $rs = $response.GetResponseStream()
- $read = New-Object "System.IO.StreamReader" -ArgumentList $rs
- $result = $read.ReadToEnd()
- # Punt the WebRequest response.
- return $result
- }
- # Variable used for limit tracking.
- [int]$cvar = 1
- # Pre-Defined list of desired colors.
- $color = @("[0.1855,0.0765]", "[0.5916,0.3764]", "[0.6473,0.3309]", "[0.4401,0.2215]", "[0.1855,0.0765]", "[0.6363,0.3352]")
- # At 500 this will run for 83.33 minutes, set higher or lower accordingly, or change to while($cvar) to run indefinitely.
- while($cvar -lt 500)
- {
- $bri = Get-Random -Minimum 20 -Maximum 254
- # Set -Maximum one higher than the number of bulbs you have.
- $bulb = Get-Random -Minimum 1 -Maximum 4
- $shift = $color | Get-Random
- "Shift"+$shift
- # Whatever command you want to pass, put it here. Not limited to brightness or color.
- Hue-Command $bulb "state" "{`"bri`":$bri, `"xy`":$shift}"
- Start-Sleep -Seconds 10
- $cvar = $cvar+1
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement