Skip to content

Instantly share code, notes, and snippets.

Created December 2, 2013 05:39
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/7745593 to your computer and use it in GitHub Desktop.
Save anonymous/7745593 to your computer and use it in GitHub Desktop.
BTC Philip's Hue Over/Under Colors

#BTC Ticker Light This script updates one of your Philip's Hue lights to be either red or green depending on if the current price of bitcoin is below or above the 24 hour weighted price.

The light

##Install Dependencies
easy_install install beautifulhue

##The Script
Save this to a python file after customizing your Philip's Hue Bridge ip, username, and light_id.

from urllib import urlopen
import json
import time
from beautifulhue.api import Bridge

# CONFIGURE HERE
bridge = Bridge(device={'ip':'192.168.1.28'}, user={'name': 'newdeveloper'})
light_id = 1

while True:
    active_light = bridge.light.get({'which': light_id})
	previous_color = -1
	if active_light['resource']['state']['on']:
		weightedprices_url= "http://api.bitcoincharts.com/v1/weighted_prices.json"
		weightedprices = urlopen(weightedprices_url)
		weightedprices = json.loads(weightedprices.read())
		weighted_24 = float(weightedprices["USD"]["24h"])

		currentprices_url = "https://www.bitstamp.net/api/ticker/"
		currentprices = urlopen(currentprices_url)
		currentprices = json.loads(currentprices.read())
		currentprice = float(currentprices["last"])
		
		color = 0 # red
		if currentprice > weighted_24:
			color = 25500 # green
		if color != previous_color:
			bridge.light.update({'which': light_id, 'data': {'state': {'hue': color}}})
			previous_color = color
			print "updating light color -- current=%s, avg=%s" % (currentprice, weighted_24)
	
	time.sleep(60 * 1000)

##To Run python script_name.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment