Last active
September 9, 2020 11:44
-
-
Save qerub/55e35bcbc30b7e810160 to your computer and use it in GitHub Desktop.
LIFX Sunrise Simulator
This file contains 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://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 |
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.
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
Information about the LIFX lightbulb: http://lifx.co/
Video on YouTube:
Another implementation: https://github.com/ryanseddon/sunrise-lifx