Skip to content

Instantly share code, notes, and snippets.

@qerub
Last active September 9, 2020 11:44
Show Gist options
  • Save qerub/55e35bcbc30b7e810160 to your computer and use it in GitHub Desktop.
Save qerub/55e35bcbc30b7e810160 to your computer and use it in GitHub Desktop.
LIFX Sunrise Simulator
require "lifx" # http://www.rubydoc.info/gems/lifx
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 = 10 * 60 # seconds
step_duration = 1 # seconds
client = LIFX::Client.lan
client.discover!(timeout: 60)
colors = (0..1).step(step_duration.to_f / duration.to_f).map { |i| calculate_color(i) }
colors.each do |color|
client.lights.set_color(color, duration: step_duration)
client.flush
sleep(step_duration)
end
@ryanseddon
Copy link

Nice! I have been nerding out on watching sunrise timelapse videos and seems a more natural sunrise starts blue/purpelish and then goes red/orange and finally a bright yellow.

@obsidianjaguar
Copy link

would be cool to have a sunset that goes from current state of bulb to dark at a set time too :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment