Skip to content

Instantly share code, notes, and snippets.

@andete
Created November 23, 2013 10:16
Show Gist options
  • Save andete/7612927 to your computer and use it in GitHub Desktop.
Save andete/7612927 to your computer and use it in GitHub Desktop.
Checking if my lab Philips Hue lamp is on and turning it on if needed:
#!/usr/bin/env python
import json
import requests
from settings import host, key
data = requests.get('http://%s/api/%s/lights/2' % (host, key)).json()
lamp_on = data['state']['on']
print data
if not lamp_on:
  payload = { u'on': True }
  requests.put('http://%s/api/%s/lights/2/state' % (host, key), data=json.dumps(payload))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment