One of the local news stations in Grand Rapids has a lighted weather ball that gives you a quick snapshot of the coming day's forecast by changing colors. It over looks an intersection of freeways and is pretty hard to miss when driving into downtown.When I first moved here I'd never seen anything like it. It was a weird, cheesy looking thing. But over time I came to appreciate the sight. Seeing the weather ball meant I was almost home.

blue - which means the temperature tomorrow will be cooler

So when we got the Philips Hue light bulbs the first project Chris suggested was a weather ball (well, more like lamp). We wanted a visual cue in the morning before work as to what the weather would be like that day. So the Hue Weather Lamp basically indicates four things:
  • If the temperature for today is cooler than yesterday, the lamp will turn blue
  • If the temperature for today is warmer than yestrerday, the lamp will turn red
  • If the temperature for today is the same as yesterday, the lamp will turn green
  • If there is a 70% or higher chance of precipitation the lamp will be purple, regardless of a temperature increase or decrease.
green - which means the temperature tomorrow will be the same

The whole thing is pretty simple. All of the files can be found here. Here's what I did.

First, I installed the python library for the Philips Hue which can be found on github here: phue. Setting up the Hue python library is fairly straight forward, as long as a username has already been established with the Hue Hub. If not, that will need to be done first (this is how I did it)

Once the python module is installed (or a work around like I did) all that needs to be done is to set up authentication with the b.connect() command. The basic steps are:
  • Press of the "connect" button on the Philip Hue Hub
  • Run the python script with b.connect() (examples are in the phue github)
  • Voila! Authenticated.
purple - which means a 70% or higher chance of precipitation tomorrow

Next, once I had access to the Hue, I started work on a python script to check the weather and then adjust the lamp accordingly. I started with the python script from the Kindle Weather Display and adapted it to pull both the weather and chance of precipitation from NOAA.

Since the NOAA page doesn't keep yesterday's forecast, I had to figure out a way to log and save yesterday's temp for comparison purposes the next day. For my purposes, I only need the lamp to turn on once a day, in the morning, so I decided writing the value to a simple text file was the easiest way to achieve this. 

The python script goes through these basic steps:
  • reads a text file for yesterday's temp
  • pulls weather forecast from NOAA
  • compares yesterday's temp from the text file to today's foretasted temp from NOAA
  • assigns the appropriate color based on temperature difference
  • write today's temperature over yesterday's temperature in the text file so the data is ready for tomorrow morning
  • turn the lamp off after one hour
Now, the text file needs to be manually set with yesterday's temperature before the first script run. After that the python script will continue to write to the text file and be ready for the next day.

red - which means the temperature tomorrow will be warmer

After the python script was complete, the next step was to set up a schedule on the web server to run the python script at a certain interval. Since the intent was to see a quick glance in the morning before work, I set up a cron job to run in the morning. Here's what I'm using on my web server.

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

#execute by typing crontab
# m h  dom mon dow   command
  0 7 * * *    /usr/bin/python /PATH/TO/FILE/HueWeatherLamp.py

# this is an alternative cron job example if there are any issues running the python script directly in cron
#  0 7 * * *    /PATH/TO/FILE/weatherballpy.sh


There are a few additional things I'd like to play around with at some point, but most importantly I think I'd like to adjust the python script to count count days +/-5 degrees as the same day. A single degree difference warmer or cooler isn't cause for celebration, but five or ten degrees would be. I'll probably let this run as-is for awhile before making that adjustment though.

UPDATE 1/7/2013: I had some issues running the script directly from a cron job. It would execute the python script partially (turn the lamp on) but not change the color. I created a shell script to execute the python script and that works fine. I've updated the below download files with the shell script and a modified cron job example.

NOTE: as noted in the comments by the phue author: You do not need to have a registered username prior to using the library. The library will register itself, for example you can call
b = Bridge(IPADDR) then call connect() and it will register the python_hue app on the bridge and save the md5 key to your home folder in .python_hue
Downloads
Github: Hue Weather Lamp
of if you prefer - dropbox link: Hue Weather Lamp

2 comments:

Hi there ! I'm the phue author ! Nice to see the library being used in nice projects !
Just wanted to mention that you do not need to have a registered username prior to using the library. The library will register itself, for example you can call
b = Bridge(IPADDR) then call connect() and it will register the python_hue app on the bridge and save the md5 key to your home folder in .python_hue

Weather activities are quite awesome to me. Hiking, skating, drenching in rainy days, summer vacation feels relieving and like stress free life. cabled weather stations and gadgets give updates on these weather reports.

Post a Comment