My DIY Automatic Wake Up Light

Thursday 29 January 2015

My DIY Automatic Wake Up Light


Every year I notice that I have little issue waking up at 7am during summer months, yet waking up at 8am during winter is always unpleasant. Some quick research led me to find that the body is gradually woken up by light, which is why products such as the Phillips Wake-Up Light exist. However, with  a starting price of £60 for the (very) basic version, I've opted to make my own smartphone-connected, automated wake up light instead.


My aim was to create a setup that could automatically turn on a bright light 20 minutes before the next alarm on my phone - something that I could 'set and forget'. Simple solutions are always favoured because they're usually cheap, so I decided to go with a desk lamp connected to a timed mains switch. This unfortunately means that there's no dimming of the light. For the phone-based automation, I chose Belkin's WeMo WiFi timed switch (£30 from Maplin). There are cheaper Chinese alternatives available, but my research found them to be lacking in third-party support. I then decided on getting a 5000K lightbulb, since that's apparently a close match to the colour temperature of summer daylight. I found a 50W (200W equivalent) fluorescent spiral bulb on eBay for £5. I've already got a standard E27-screw desk lamp, so the total cost for this project was £35.


The desk lamp (with the huge daylight bulb fitted) is flipped to on, then plugged into the WeMo switch, which is connected to my WiFi network. This allows me to be able to turn the lamp on and off from my phone. Getting the automation working correctly was a bit more difficult.

Belkin's WeMo Android app is very basic, with a slow interface and no Tasker integration. I decided to use WeMoWay, a fast and lightweight alternative with (buggy) Tasker integration. WeMo Manager also has Tasker integration, but it's not free and, unlike WeMo Way, would require a second always-on server device for my plans to work correctly. I wanted to make sure that everything would work even if my internet connection went down, which is why using services like IFTTT was out of the question. I've had to install three other plugins to get everything working as I like: AutoAlarm, Taskkill, and WiFi Connect. The last two are used to get WeMoWay Tasker integration working reliably; AutoAlarm is used to get the time of the next alarm in Android.

We'll first of all want to create a task that checks when the next alarm is and then sets two custom variables for 20 minutes before that alarm (to turn on the lamp) and 10 minutes after (to turn off the lamp and clear the variables). I'll simply be copying the task description and adding screenshots along with a brief explanation of what the task does.
CheckNextAlarm (13)
A1: Wait [ MS:0 Seconds:30 Minutes:0 Hours:0 Days:0 ]
A2: AutoAlarm [ Configuration:No configuration needed Package:com.joaomgcd.autoalarm Name:AutoAlarm Timeout (Seconds):5 ]
A3: Wait [ MS:0 Seconds:1 Minutes:0 Hours:0 Days:0 ]
A4: If [ %seconds > 2 ]
A5: Variable Set [ Name:%seconds To:%TIMES + %seconds - 1200 Do Maths:On Append:Off ]
A6: Variable Convert [ Name:%seconds Function:Seconds to Date Time Store Result In:%Nextalarm ]
A7: Wait [ MS:0 Seconds:1 Minutes:0 Hours:0 Days:0 ]
A8: Variable Section [ Name:%Nextalarm From:12 Length:5 Adapt To Fit:Off Store Result In:%Nextalarm ]
A9: Flash [ Text:%hours Long:Off ]
A10: Variable Set [ Name:%seconds To:%seconds + 1720 Do Maths:On Append:Off ]
A11: Variable Convert [ Name:%seconds Function:Seconds to Date Time Store Result In:%Afternextalarm ]
A12: Variable Section [ Name:%Afternextalarm From:12 Length:5 Adapt To Fit:Off Store Result In:%Afternextalarm ]
A13: End If


This queries the phone for the time until the next alarm. It then adds this time in seconds to the current time in seconds before subtracting 1200 seconds (20 minutes). It then stores this time in a variable (which you have to create yourself, titled %Nextalarm) before adding 12 minutes to that time and storing this value in another variable (%Afternextalarm). All of the "if" statements and wait times in these tasks are important, as there are slight delays in getting values.

The next step is to create the task that will turn on the lamp 20 minutes before an alarm. Because WemoWay is still in beta, it's rather buggy. I've also noticed that sometimes the instructions sent from WemoWay don't get through until I've manually reconnected my WiFi connection in Android. The task shown below will restart WiFi and then force a connection to my home network. It will then kill the WemoWay service before manually launching the app and then executing a command to toggle the lamp. This has been reliable so far.

Togglewemo for alarm (25)
A1: WiFi [ Set:Off ]
A2: Wait [ MS:0 Seconds:2 Minutes:0 Hours:0 Days:0 ]
A3: WiFi [ Set:On ]
A4: Wait [ MS:0 Seconds:1 Minutes:0 Hours:0 Days:0 ]
A5: WiFi Connect [ Configuration:"Yeezus Lives" Package:jp.meridiani.apps.wificonnect Name:WiFi Connect Timeout (Seconds):0 ]
A6: Taskkill [ Configuration:Method=Extreme; Package=com.twolinessoftware.android.wemo.wemotoolkit Package:com.laptopfreek0.taskkill Name:Taskkill Timeout (Seconds):0 ]
A7: Wait [ MS:0 Seconds:3 Minutes:0 Hours:0 Days:0 ]
A8: Launch App [ App:WemoWay:activity.MainActivity Data: Exclude From Recent Apps:Off ]
A9: Wait [ MS:0 Seconds:4 Minutes:0 Hours:0 Days:0 ]
A10: WeMo Device [ Configuration:Toggle WeMo Alarm Lamp Package:com.twolinessoftware.android.wemo.wemotoolkit Name:WeMo Device Timeout (Seconds):0 ] 


We then create another task that will run 12 minutes after the alarm has sounded. It will toggle the lamp off, and then clear the values for the variables we created. You can simply clone the task above and then add variable clears for %nextalarm and %afternextalarm.


The final step is to create three profiles. We want to create a profile that will trigger the task that checks when the next alarm is. I've opted to check for the next alarm 30 seconds after the Android Clock application has been opened (this is why there is a 30-second wait at the start of the CheckNextAlarm task). You can do this by creating a profile based on 'application', and then selecting the clock application. Run the 'get next alarm' task for this profile.

The next profile will be triggered based on time. This is where the variables we made come in. Add a time profile, and tap on the intertwining arrows on the left, below "From:". Here you can select %Nextalarm. Do the same for the "To:" field. Run the 'toggle wemo on' task for this profile..

The final profile is the same -- a time profile, but using %Afternextalarm for the time instead of %Nextalarm. Run the 'toggle wemo off/clear variables' task for this profile.

Once all of this is done, all you have to do is make sure you set your alarm within 30 seconds of opening the Clock application, and everything else will be done automatically. This setup has made my early mornings much, much easier.

4 comments :

  1. This is a great hack. While researching making our own wake-up light at Lark (https://heylark.com/), we were surprised at how simple these lights would be to make on your own. One bonus of using the WeMo is that it has a back-up battery in case the power goes out, which many wake-up alarm clocks on the market surprisingly don't include.

    ReplyDelete
  2. This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information... lichtwecker-24.de

    ReplyDelete
  3. The Best Casinos in USA - APRCasino
    It is one of the most www.jtmhub.com well-known casino casinos, and it is owned wooricasinos.info and operated 바카라 by the Rincon Band of Luiseno Indians. 토토 사이트 홍보 There are over aprcasino 100 different

    ReplyDelete