Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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)

This comment has been minimized.

Copy link
Owner Author

@qerub qerub commented May 13, 2014

Information about the LIFX lightbulb:

Video on YouTube:
LIFX Sunrise Simulator on YouTube

Another implementation:


This comment has been minimized.

Copy link

@ryanseddon ryanseddon commented May 16, 2014

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.


This comment has been minimized.

Copy link

@obsidianjaguar obsidianjaguar commented Jun 20, 2014

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