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.
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.
- 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
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
1 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
Post a Comment