Simulate Sunrise With WiFi Bulb and Home-Assistant

Living up North in the Winter we have long hours of darkness because of the earth’s tilt away from the sun.  This means getting up before the sun rises, and it’s a bit annoying to be jolted awake at 6:00am by an alarm when it’s pitch black outside.   Or if I wake up before the alarm goes off, it’s dark, and I can’t tell if I should be going back to sleep or getting ready to get up without consulting a clock.

Earth Title in Winter (for Northern hemisphere)

Wake-up Naturally with Your Own IoT Bulb

WiFi BulbFor Christmas I got a couple of these MagicLight WiFi Smart LED Bulbs.

(The same bulb is also sold under a different brand name: Flux Wifi Smart LED Bulb.)

There are quite a few IoT (Internet of Things) WiFi Light bulbs on the market, the reason I like these is they don’t rely on the vendors software to control them, and they don’t need to connect out to some cloud service on the internet which increases ones surface area to hackers.

Connect to WiFi

When the bulbs are initially turned on they power on and create their own WiFi hotspot, a phone app connects to it and programs it to connect to your WiFi network.  As with all IoT devices I suggest having a dedicated IoT WiFi SSID and VLAN to keep them off the main network.  They should get an IP address from DHCP, I then give it a static IP assignment with DHCP in pfSense.

Automate with Home Assistant

Home Assistant Controlling LightBulbNext, install Home Assistant (which is a free open source home automation platform) on a server.  I spun up an Ubuntu 16.04 VM.

The MagicLight / Flux Bulbs aren’t smart enough to gradually turn on or off, but I used multiple automation tasks to simulate a gradual fade-on over 30 minutes.  The example below will gradually make the light brighter.  It starts very dim, at 5:15am and stays dim for awhile.   This won’t wake me up if I’m still asleep.  Then around 5:40am it starts to get brighter at a faster rate until it reaches full brightness at 6:10am.

This wakes me up “naturally” every winter morning.  I’m usually awake well before 6 and feel much better than if I had used an alarm.

The light stays on until 8am then it turns off and waits for the next day.

Home Assistant Main Screen ScreenShot

The nice thing about waking up to a gradual light is if I’m already waking up I’ll get up sometime after 5:15am, but if I’m in a deep sleep it won’t wake me up suddenly so I can get a few extra minutes of sleep until around 6am.

Here’s the part I added to configuration.yaml

There are also some other things one could do, Home Assistant can also monitor the weather and sunrise times.  I could probably spend a little more effort and make the script only activate the bulb if the sun hasn’t risen yet, or I could have the bulb wake me up earlier if there’s a lot of snow so I have more time to shovel.  Maybe it could be blue when it’s raining so I know to grab my hat.

My home automation script could definitely use some improvements, but even in it’s present state it’s a big improvement over waking up to an alarm.