Skip to content

Instantly share code, notes, and snippets.

@bjeanes
Forked from qerub/lifx-sunrise-simulator.rb
Last active August 29, 2015 14:04
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 bjeanes/1dd20a85c55099fe5e58 to your computer and use it in GitHub Desktop.
Save bjeanes/1dd20a85c55099fe5e58 to your computer and use it in GitHub Desktop.
require "lifx" # http://rubydoc.info/github/lifx/lifx-gem/master/frames
def calculate_color(i) # 0 <= i <= 1
h = [40 * 2 * i, 40].min # will be 40 (yellow) at i=1/2 and stay there
s = 1.0 - [(i - 0.5) * 2, 0].max # will be 1 until i=1/2 and then go down to 0
b = i
LIFX::Color.hsbk(h, s, b, LIFX::Color::KELVIN_MIN)
end
duration = 30 * 60 # seconds
step_duration = 15 # seconds
client = LIFX::Client.lan
client.discover!
colors = (0..1).step(step_duration.to_f / duration.to_f).map { |i| calculate_color(i) }
# ensure the bulbs are actually *on* but turn brightness down *first* to avoid a flash to previous color
# before the sunrise timer starts
client.lights.set_color(colors.first, duration: 0)
sleep 1
client.lights.turn_on
colors.each do |color|
client.lights.set_color(color, duration: step_duration)
sleep(step_duration)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment