-
-
Save bjeanes/1dd20a85c55099fe5e58 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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