Skip to content

Instantly share code, notes, and snippets.

Created December 2, 2013 05:39
Show Gist options
  • 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

bridge = Bridge(device={'ip':''}, 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= ""
		weightedprices = urlopen(weightedprices_url)
		weightedprices = json.loads(
		weighted_24 = float(weightedprices["USD"]["24h"])

		currentprices_url = ""
		currentprices = urlopen(currentprices_url)
		currentprices = json.loads(
		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

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