The seasons are changing and summer is on its way. Of course this means that the days of wearing shorts and a t-shirt are upon us. The transition time can be a tough one for figuring out what to wear every morning. I decided to solve this problem with a quick scripting project.
The concept is simple: When I wake up for work every morning, change the colour of my bedroom light to give me data on what the weather is going to be like that day.
Products and software used:
How it works:
My first step was to actually read in today’s weather. I did this using Yahoo’s public weather API. I read in today’s high, low and the text. The text will be something like “Sunny” or “Partly Cloudy” etc. I use this variable to check for rain or snow. I then save these variables to a file so that they can be compared tomorrow.
A sample of my getWeather function is below:
Next comes the logic of using this data to decide what colour to ramp the lights up to in the morning.
Basic if/then logic is:
Compare today’s high against yesterday’s high.
If today is 4+ degrees Celsius hotter than yesterday, turn bedroom light red.
If today is 4+ degrees Celsius colder than yesterday, turn bedroom light purple.
If today is less than 4 degrees hotter than yesterday and less than 4 degrees colder than yesterday, turn bedroom light yellow.
If it will rain or snow today, turn bedroom light blue.
Blue is a bad colour…
To actually change the colour of my bedroom light I use the Phillips Hue RESTful API. I was pleasantly surprised with how simple this was, especially since I had worked with the difficult Wemo Light Switch in a past project.
Below is the code I used to set the light. I borrowed this from jheyman.
I decided I wanted the light to slowly get brighter as I woke up. I start the brightness ramp up about 15 minutes before I want to get up and it continues to get brighter for 15 minutes after I get up. This way I am not blinded by a full blast light right in the morning.
Now that my script works, the last thing I had to do was set up a cron job on my raspberry pi to run every morning (not including weekends).
0 7 * * 1 cd /root/hueweather/ && /usr/bin/python wakeup.py
0 7 * * 2 cd /root/hueweather/ && /usr/bin/python wakeup.py
0 7 * * 3 cd /root/hueweather/ && /usr/bin/python wakeup.py
0 7 * * 4 cd /root/hueweather/ && /usr/bin/python wakeup.py
0 7 * * 5 cd /root/hueweather/ && /usr/bin/python wakeup.py
Now when I wake up, I have a pretty good idea of what the weather will be like that day… pending the weatherman is right.
*Video sped up.