Skip to content

Instantly share code, notes, and snippets.

Last active September 9, 2020 11:44
  • Star 17 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save qerub/55e35bcbc30b7e810160 to your computer and use it in GitHub Desktop.
LIFX Sunrise Simulator
require "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)
duration = 10 * 60 # seconds
step_duration = 1 # seconds
client = LIFX::Client.lan!(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)
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.

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