Exemplo n.º 1
0
import redis
import json
import requests
import time
import datetime
from zwave import ZStickInterface
from hue import HueInterface

# Set up database connection
db = redis.StrictRedis(host='localhost', port=4747, db=0)

# Initialize Z-wave network
zstick = ZStickInterface()

# Instantiate Hue Light helper
hue = HueInterface(db.get("hue_username"), db.get("hue_address"))
# Need to check if sensors already exist in database
# Remove items that are in db but not in recent discovery
'''hue_data = hue.discover()
for item in hue_data:
    db.rpush("sensors", item)'''

# Initialize sensor lists
zwave_sensors = []
wifi_sensors = []
hue_sensors = []

# Query database for sensors and sort into lists by type
sensors = db.lrange("sensors", 0, -1)
for sensor in sensors:
    sensor = json.loads(sensor)
Exemplo n.º 2
0
import time
import json
import redis
from hue import HueInterface

db = redis.StrictRedis(host='localhost', port=4747, db=0)

hue = HueInterface(db.get("hue_username"), db.get("hue_address"))

while True:
    try:
        sensor_data = hue.get_lights()
    except:
        print "Error getting data"
        sensor_data = {}
    for item in sensor_data.keys():
        sensor_data[item]["name"]
        if sensor_data[item]["state"]["on"]:
            state = "True"
        else:
            state = "False"
        if state != db.get(sensor_data[item]["name"]):
            db.set(sensor_data[item]["name"], state)
    time.sleep(1)