forked from AaronH/RubyHue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boot.rb
25 lines (22 loc) · 768 Bytes
/
boot.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
require 'httparty'
require 'digest'
require 'json'
BASE = 'http://192.168.0.5/api'
UUID = Digest::MD5::hexdigest('ruby-hue')
response = HTTParty.get("#{BASE}/#{UUID}/lights")
if response.body =~ /unauthorized/
post = {:username => UUID, :devicetype => "huebert"}
response = HTTParty.post(BASE, :body => post.to_json)
if response.body =~ /link button not pressed/
puts "Push the link button on the controller and run this script again."
end
end
load 'hue.rb'
Hue::Bridge.identities.each_with_index do |name, index|
hue = rand(65535)
sat = 255
brightness = 255
puts "Setting #{name} to hue #{hue}, saturation #{sat} and brightness #{brightness}"
bulb = Hue::Bulb.new(index)
bulb.update(:hue => hue, :sat => sat, :brightness => brightness)
end