Sunrise / sunset emulation

Hello!

I’m going to realize sunset / sunrise emulation.

The idea is:

  1. SUNRISE: Light turns on at a specific time. During “sunrise” light intensity smoothly increases and the color changes from red to orange, yellow and warm write.

  2. SUNSET: It begins at a specific time. During “sunset” light intensity smoothly decreases and the color changes from warm white to yellow, orange and red. Light turns off.

  • The duration of “sunset/sunrise” and start time should be editable option.
  • Ideal solution should not require a permanent internet connection…

Is it possible to realize this idea based on LIFX? What should I use to control: mobile app / some kind of programming languages / service like a ifttt?

Thank you in advance!
BR, Evgueni

You can use the light scheduler built into the LIFX app to achieve this. Or you can make calls to the HTTP API if you have a webserver and some experience programming. Or you can use the LAN API if you’re familiar with TCP/UDP packets.

Easiest way is the LIFX scheduler.

Thank you for the information!

Does that app realize scheduled fade-in / fade-out options with fixed duration and fixed color? Or it can change color and light intensity as I wish during specific time to emulate sunset/sunrise?

It’s a fixed duration and color. It’s not very dynamic but with careful tweaking you can do quite a lot.

I’ve added this to lifxDynamic. The times for sunset and sunrise are calculated from your location and you have the choice of switching the bulbs off at a user configuration “bedtime” or using a nightlight setting.

Lights will transition across brightness and color temperature along with the day.

The app is UWP for Windows PC, mobile and Xbox One.

Thank you for the information! Will your app realize my version of Sunset / Sunrise (with colors transition and flexible duration)?

Do I need to keep the Windows on to control bulbs simulating sunset / sunrise? Or I need your app and windows only to setup sunset/sunrise parameters and I can turn them off after setup phase?
Unfortunately I have no windows PC and windows mobile. I can start it using a virtual machine… But I can’t keep it on for a long time…

I was able to do this with Python 2.7 using the following API: https://github.com/mclarkk/lifxlan

from lifxlan import *

wake_time = 30 # Time in minutes

lifx = LifxLAN(1)

# get devices
devices = lifx.get_lights()
light = devices[0]

light.set_color([0,65535,0,3500], 1, 1)
light.set_power(True)

light.set_color([0,0,65535,3500], (wake_time * 60 * 1000), 1)

Here is a similar code for sunset effect:

from lifxlan import *
from time import sleep

sunset_time = 30 # Time in minutes

lifx = LifxLAN(1)

# get devices
devices = lifx.get_lights()
light = devices[0]

light.set_color([0,0,65535,3500], 1, 1)
light.set_power(True)

light.set_color([0,65535,0,3500], (sunset_time * 60 * 1000), 1)
sleep(sunset_time * 60)
light.set_power(False)

Hey! Thanx a lot!

Do I need to keep my computer with Python and controlling code on to get my sunset/sunrise? Or I need my computer only to setup sunset/sunrise option?

And one more question…

In my e-mail I got quoted below code as a reply in my topic. But here, in the topic, I see other reply and other code from you. Have you changed it? Is the code quoted below correct or not?

I was able to do this with Python 2.7 using the following API: GitHub - pHaeusler/lifx: LIFX Python API
You’d have to change ‘LIFX Desk’ to whatever label you gave your bulb.
Also, fade_time and interval variables can be adjusted according to what you want

import lifx
import time

network = lifx.Network()
network.search()

light = network.get_light_by_label(‘LIFX Desk’)

saturation_MIN = 1000
saturation_MAX = 65000

brightness_MIN = 100
brightness_MAX = 65500

fade_time = 1800 # time in seconds
interval = 0.5 # run every half a second
increment = fade_time/interval

sat = saturation_MAX
bright = brightness_MIN
saturation_decrease = (saturation_MAX - saturation_MIN) / increment
brightness_increase = (brightness_MAX - brightness_MIN) / increment

light.set_light_state(stream=1, hue=0, saturation=saturation_MAX, brightness=brightness_MIN, kelvin=4000, duration=1)
light.on()

for i in range(int(increment)):
time.sleep(interval)
sat -= saturation_decrease
bright += brightness_increase
light.set_light_state(stream=1, hue=0, saturation=sat, brightness=bright, kelvin=4000, duration=1)

Yes you need your computer to be running in order for the code to be executed. You can create a task schedule in windows to have it run at a specific time. I’m sure there are ways to do this on a Mac.

The code referenced in the email was the first that I got to work. The one on my post above is the most updated version. I also changed the API I used from the first code to this latest one.

Great! I think I should buy LIFX now…

Do you know ways to run this Python code remotely? I don’t want to keep my computer on all the night.

I think it’s not a problem to schedule this code running at a specific time on any web hosting supports Python… But maybe you know free ways to run Python code remotely…

To make a sunrise is actually pretty easy. No need to send a new color to the bulb every other second. Just send a “start” color to the bulb and then a “target” color with a fade-in duration right after it. The bulb will then transition from one to the other on its own. Works all right for orange to yellow/warm white or yellow to neutral white but can produce pink colors if you transition “too far” (e.g. red to white).

My little app “Sunrise Alarm with LIFX” does it this way using the http api.

panacorn, I’m not sure how you’d do it via a websever unless you have one setup in your home with, for example, a raspberry pi. The python code I sent you has to be run from within your network in order to find your bulb. If you were to write this with the HTTP API there must be a way to find your bulb via IP address + MAC address, I’m sure you can figure it out.

dymas, is your app for andriod/ios? I’d love to have this directly on my iPhone. I did run into the pinkish color issue, I ended up creating multiple steps as you suggested and it works great, thanks for the advice.

It’s for android only. It reads the next alarm set and initiates the sunrise at a time before it.

I don’t think it’s possible to do it like this on iOS, sorry.

My app RedLamp does something similar to this, warming your lights at night and cooling them during the day. It also automatically turns your lights on when the sun starts to go down, and you can set an alarm time for your lights to wake you up. www.redlamp.com.au