Skip to content

Instantly share code, notes, and snippets.

@jamesbowles
Created March 8, 2016 09:53
Show Gist options
  • Save jamesbowles/a0318b14d201caab2411 to your computer and use it in GitHub Desktop.
Save jamesbowles/a0318b14d201caab2411 to your computer and use it in GitHub Desktop.
import bluetooth
import time
import urllib2
import json
while True:
hour = time.localtime().tm_hour
if (hour < 17):
print "it's too early for this"
else:
print "looking for James"
result = bluetooth.lookup_name('XX:XX:XX:XX:XX:XX', timeout=5)
if (result != None):
print "found James!"
print "checking the lights"
data = urllib2.urlopen("http://192.168.1.2/cgi-bin/json.cgi?get=state").read()
data.strip()
output = json.loads(data[1:-2])
if (output["state"] == "off"):
print "turning the light on!"
data = urllib2.urlopen("http://192.168.1.2/cgi-bin/json.cgi?set=on").read()
print data
time.sleep(1)
else:
print "the lights are already on"
time.sleep(5)
time.sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment