def main(): d = db() Homie = homie.Homie("configs/archiver.json") archiver = Archiver(d, Homie) Homie.setFirmware("archiver", "1.0.0") Homie.setup() while True: pass
def main(): d = db() Homie = homie.Homie("configs/schedule.json") schedule = Schedule(d, Homie) Homie.setFirmware("schedule-controller", "1.0.0") Homie.setup() while True: schedule.loopHandler() time.sleep(5)
def main(): Homie = homie.Homie("configs/device.json") d = db() dd = Device(d, Homie) Homie.setFirmware("device-handler", "1.0.0") Homie.setup() while True: dd.loopHandler() time.sleep(5)
def main(configfile="homie-python.json"): global fan global Homie global switchNode json_data = open(configfile).read() data = json.loads(json_data) fanMouth = data["relay"]["pin"] logname = data["relay"]["log"] logging.basicConfig(filename=logname, level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s') turnedon = 0 logging.info("Setting up GPIO ports") GPIO.setwarnings(False) GPIO.setmode( GPIO.BCM) ## Indicates which pin numbering configuration to use print("Setting up GPIO ports") GPIO.setup(fanMouth, GPIO.OUT) GPIO.output(fanMouth, GPIO.HIGH) fan = GPIO.PWM(fanMouth, 100) logging.info("GPIO ports set up on port %s" % fanMouth) print("GPIO ports set up on port %s" % fanMouth) fan.start(0) PAUSE_TIME = 60.02 logging.info("Starting homie") print("Starting homie") Homie = homie.Homie(configfile) switchNode = Homie.Node("switch", "switch") Homie.setFirmware("fancontrol", "1.0.0") Homie.subscribe(switchNode, "on", switchOnHandler) logging.info("Running setup") print("Running setup") Homie.setup() print Homie print switchNode while True: try: time.sleep(1) except Exception, e: # Error appending data, most likely because credentials are stale. # Null out the worksheet so a login is performed at the top of the lo logging.error("Error in mqtt loop") print('Append error, logging in again: ' + str(e)) continue except KeyboardInterrupt: print("error") GPIO.cleanup() exit(0)
def main(): d = db() Homie = homie.Homie("configs/logger.json") log = Logger(d, Homie) Homie.setFirmware("logger", "1.0.0") Homie.setup() while True: log.loopHandler() time.sleep(5)
def main(): d = db() Homie = homie.Homie("configs/heating.json") heating = Heating(d, Homie) Homie.setFirmware("heating-controller", "1.0.0") Homie.setup() while True: heating.loopHandler() time.sleep(5)
def main(): d = db() Homie = homie.Homie("configs/repeater.json") repeater = Repeater(d, Homie) Homie.setFirmware("repeater-controller", "1.0.0") Homie.setup() repeater.init() while True: time.sleep(1)
def main(): d = db() # config = homie.loadConfigFile("configs/weather.json") # Homie = homie.Homie(config) Homie = homie.Homie("configs/weather.json") weather = Weather(d, Homie) Homie.setFirmware("weather", "1.0.0") Homie.setup() while True: weather.loopHandler() time.sleep(5)
def main(configfile='homie-dht.json'): Homie = homie.Homie(configfile) temperatureNode = Homie.Node("temperature", "temperature") humidityNode = Homie.Node("humidity", "humidity") json_data = open(configfile).read() data = json.loads(json_data) FREQUENCY_SECONDS = data["dht"]["frequency"] DHT_PIN = data["dht"]["pin"] print('Logging sensor measurements to {0} every {1} seconds.'.format( 'MQTT', FREQUENCY_SECONDS)) Homie.setFirmware("dht-temperature", "1.0.0") Homie.setup() while True: try: # Attempt to get sensor reading. print('Performing read on dht') humidity, temp = Adafruit_DHT.read(DHT_TYPE, DHT_PIN) print('After dht read') # Skip to the next reading if a valid measurement couldn't be taken. # This might happen if the CPU is under a lot of load and the sensor # can't be reliably read (timing is critical to read the sensor). if humidity is None or temp is None: time.sleep(2) print "Nothing received from sensor" continue currentdate = time.strftime('%Y-%m-%d %H:%M:%S') print('Date Time: {0}'.format(currentdate)) print('Temperature: {0:0.2f} C'.format(temp)) print('Humidity: {0:0.2f} %'.format(humidity)) # Publish to the MQTT channel print('Connecting to host') print("Posting Temperature to homie") Homie.setNodeProperty(temperatureNode, "degrees", temp, True) Homie.setNodeProperty(humidityNode, "humidity", humidity, True) except Exception, e: # Error appending data, most likely because credentials are stale. # Null out the worksheet so a login is performed at the top of the loop. print('Append error, logging in again: ' + str(e)) continue else: # Wait 30 seconds before continuing print('Wrote a message tp MQQTT') time.sleep(FREQUENCY_SECONDS)
def main(): d = db() config = homie.loadConfigFile("configs/sonos.json") Homie = homie.Homie(config) sonos = Sonos(d, Homie) Homie.setFirmware("sonos", "1.0.0") Homie.setup() try: while True: sonos.loopHandler() finally: sonos.shutdown()
def main(): d = db() config = homie.loadConfigFile("configs/daapd.json") Homie = homie.Homie(config) daapd = Daapd(d, Homie) Homie.setFirmware("daapd", "1.0.0") Homie.setup() try: while True: daapd.loopHandler() finally: daapd.shutdown()
def main(): args = parse_args() config_dir = args.config_dir or "config" config = homie.loadConfigFile(f"{config_dir}/huebridge.json") Homie = homie.Homie(config) hue = Huebridge(Homie, args, config) Homie.setFirmware("huebridge", "1.0.0") Homie.setup() try: while True: time.sleep(1) finally: hue.shutdown()
#!/usr/bin/env python # -*- coding: UTF-8 -*- import time import homie import logging import RPi.GPIO as GPIO logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) TEMP_INTERVAL = 60 IDLE_INTERVAL = 45 Homie = homie.Homie("range_sensor.json") temperatureNode = Homie.Node("temperature", "temperature") switchNode = Homie.Node("switch", "switch") # define GPIO pins GPIOEcho = 11 GPIORelais1 = 16 GPIORelais2 = 18 GPIOTrigger = 13 OVERRULED = False # function to measure the distance def measureDistance(): # set trigger to high GPIO.output(GPIOTrigger, True) # set trigger after 10µs to low
def main(configfile='homie-bluetooth.json'): Homie = homie.Homie(configfile) Homie.setFirmware("bluemaestro-temperature", "1.0.0") Homie.setup() json_data = open(configfile).read() data = json.loads(json_data) FREQUENCY_SECONDS = data["bluetooth"]["frequency"] LOG = data["bluetooth"]["log"] logging.basicConfig(filename=LOG, level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s') try: sock = bluez.hci_open_dev(dev_id) logging.info("ble thread started") except: print "error accessing bluetooth device..." logging.info("error accessing bluetooth device...") sys.exit(1) bluemaestroscan.hci_le_set_scan_parameters(sock) bluemaestroscan.hci_enable_le_scan(sock) while True: try: returnedList = bluemaestroscan.parse_events(sock, 2) nodes = {} print "-------------------------------------------------------------------------------------------------------" logging.info( "-------------------------------------------------------------------------------------------------------" ) mac = "" temp = 0 currentdate = time.strftime('%Y-%m-%d %H:%M:%S') print('Date Time: {0}'.format(currentdate)) logging.info('Date Time: {0}'.format(currentdate)) for beacon in returnedList: val = returnedList[beacon] print beacon, val mac = returnedList["mac"] temp = returnedList["temp"] print "number of beacons found {0}".format(len(returnedList)) logging.info("number of beacons found {0}".format( len(returnedList))) if len(returnedList) > 0: print "%s/temperature = %.2f" % (returnedList["mac"], returnedList["temp"]) logging.info("%s/temperature = %.2f" % (returnedList["mac"], returnedList["temp"])) # Publish to the MQTT channel try: print("CHecking nodes for " + mac + "temperature") updatenode(Homie, nodes, mac, "temperature", float(returnedList["temp"])) #if mac+"temperature" in nodes: # logging.info("Found existing temperature node: " + mac+"temperature") # print("Found existing temperature node: " + mac+"temperature") # temperatureNode = nodes[mac+"temperature"] # print ("Obtained temperature node for updating") # Homie.setNodeProperty(tempNode,"temperature",float(returnedList["temp"]),True) #else: # logging.info("Added new temperature node for mac" + mac) # print("Adding new temperature node for mac" + mac) # temperatureNode = Homie.Node(mac,"temperature") # Homie.setNodeProperty(temperatureNode,"temperature",float(returnedList["temp"]),True) # nodes[mac+"temperature"] = temperatureNode # print("Added new temperature node for mac" + mac) print 'Updating temp for {0} to {1}'.format( returnedList["mac"], float(returnedList["temp"])) logging.info('Updating temp for {0} to {1}'.format( returnedList["mac"], float(returnedList["temp"]))) print("CHecking nodes for " + mac + "humidity") updatenode(Homie, nodes, mac, "humidity", float(returnedList["humidity"])) #humidityNode = Homie.Node(mac,"humidity") #Homie.setNodeProperty(humidityNode,"humidity",float(returnedList["humidity"]),True) print 'Updating humidity {0} = {1}'.format( returnedList["mac"], float(returnedList["humidity"])) logging.info('Updating humidity {0} = {1}'.format( returnedList["mac"], float(returnedList["humidity"]))) print("CHecking nodes for " + mac + "battery") updatenode(Homie, nodes, mac, "battery", float(returnedList["battery"])) #batteryNode = Homie.Node(mac,"battery") #Homie.setNodeProperty(batteryNode,"battery",float(returnedList["battery"]),True) print 'Updating battery {0}/battery = {1}'.format( returnedList["mac"], float(returnedList["battery"])) logging.info( 'Updating battery {0}/battery = {1}'.format( returnedList["mac"], float(returnedList["battery"]))) print("CHecking nodes for " + mac + "dewpoint") updatenode(Homie, nodes, mac, "dewpoint", float(returnedList["dewpoint"])) #dewpointNode = Homie.Node(mac,"dewpoint") #Homie.setNodeProperty(dewpointNode,"dewpoint",float(returnedList["dewpoint"]),True) print 'Updating {0}/dewpoint = {1}'.format( returnedList["mac"], returnedList["dewpoint"]) logging.info('Updating {0}/dewpoint = {1}'.format( returnedList["mac"], returnedList["dewpoint"])) print("CHecking nodes for " + mac + "name") updatenode(Homie, nodes, mac, "name", returnedList["name"]) #nameNode = Homie.Node(mac,"name") #Homie.setNodeProperty(nameNode,"name",returnedList["name"],True) print 'Updating name {0}/name = {1}'.format( returnedList["mac"], returnedList["name"]) logging.info('Updating name {0}/name = {1}'.format( returnedList["mac"], returnedList["name"])) time.sleep(1) except Exception, e: # Null out the worksheet so a login is performed at the top of the loop. logging.error('Append error, logging in again: ' + str(e)) logging.error("Sleeping for 60 seconds") time.sleep(60) continue else: print "Sleeping for 30 seconds" logging.info("Sleeping for 30 seconds") time.sleep(30) logging.info("Sleeping for %s seconds" % FREQUENCY_SECONDS) print("Sleeping for %s seconds" % FREQUENCY_SECONDS) time.sleep(FREQUENCY_SECONDS) except Exception, e: # Error appending data, most likely because credentials are stale. # Null out the worksheet so a login is performed at the top of the loop. print('Append error, logging in again: ' + str(e)) print "Sleeping for 60 seconds" time.sleep(60) continue
def main(configfile='homie-bluetooth.json'): Homie = homie.Homie(configfile) Homie.setFirmware("bluemaestro-temperature", "1.0.0") Homie.setup() try: sock = bluez.hci_open_dev(dev_id) print "ble thread started" except: print "error accessing bluetooth device..." sys.exit(1) bluemaestroscan.hci_le_set_scan_parameters(sock) bluemaestroscan.hci_enable_le_scan(sock) try: returnedList = bluemaestroscan.parse_events(sock, 2) nodes = {} print "-------------------------------------------------------------------------------------------------------" mac = "" temp = 0 currentdate = time.strftime('%Y-%m-%d %H:%M:%S') print('Date Time: {0}'.format(currentdate)) for beacon in returnedList: val = returnedList[beacon] print beacon, val mac = returnedList["mac"] temp = returnedList["temp"] print "number of beacons found {0}".format(len(returnedList)) if len(returnedList) > 0: print "%s/temperature = %.2f" % (returnedList["mac"], returnedList["temp"]) # Publish to the MQTT channel try: temperatureNode = Homie.Node(mac, "temperature") Homie.setNodeProperty(temperatureNode, "temperature", float(returnedList["temp"]), True) print 'Updating temp for {0} to {1}'.format( returnedList["mac"], float(returnedList["temp"])) humidityNode = Homie.Node(mac, "humidity") Homie.setNodeProperty(humidityNode, "humidity", float(returnedList["humidity"]), True) print 'Updating humidity {0} = {1}'.format( returnedList["mac"], float(returnedList["humidity"])) batteryNode = Homie.Node(mac, "battery") Homie.setNodeProperty(batteryNode, "battery", float(returnedList["battery"]), True) print 'Updating battery {0}/battery = {1}'.format( returnedList["mac"], float(returnedList["battery"])) dewpointNode = Homie.Node(mac, "dewpoint") Homie.setNodeProperty(dewpointNode, "dewpoint", float(returnedList["dewpoint"]), True) print 'Updating {0}/dewpoint = {1}'.format( returnedList["mac"], returnedList["dewpoint"]) nameNode = Homie.Node(mac, "name") Homie.setNodeProperty(nameNode, "name", returnedList["name"], True) print 'Updating name {0}/name = {1}'.format( returnedList["mac"], returnedList["name"]) time.sleep(1) print "Sleeping for %d seconds" % FREQUENCY_SECONDS except Exception, e: # Null out the worksheet so a login is performed at the top of the loop. print('Append error, logging in again: ' + str(e)) print "Sleeping for 60 seconds" except Exception, e: # Error appending data, most likely because credentials are stale. # Null out the worksheet so a login is performed at the top of the loop. print('Append error, logging in again: ' + str(e)) print "Sleeping for 60 seconds"
#!/usr/bin/env python # -*- coding: UTF-8 -*- import time import homie import logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) TEMPERATURE_INTERVAL = 3 Homie = homie.Homie("homie-python.json") temperatureNode = Homie.Node("temperature", "temperature") humidityNode = Homie.Node("humidity", "humidity") def main(): Homie.setFirmware("awesome-temperature", "1.0.0") Homie.setup() while True: temperature = 22.0 humidity = 60.0 logger.info("Temperature: {:0.2f} °C".format(temperature)) Homie.setNodeProperty(temperatureNode, "degrees", temperature, True) logger.info("Humidity: {:0.2f} %".format(humidity)) Homie.setNodeProperty(humidityNode, "humidity", humidity, True) time.sleep(TEMPERATURE_INTERVAL)
import homie import logging import string import threading import json import hashlib import uuid import time import urllib.request, urllib.error, urllib.parse logging.basicConfig(level=logging.INFO) logging.getLogger("urllib3").setLevel(logging.WARNING) logger = logging.getLogger(__name__) configFile = "config/config.json" Homie = homie.Homie(configFile) node = Homie.Node("narodmon", "sensors") sensor_type_desc = {11: 'lux'} def init(): global configFile, api_key, users, sensor_types, timeout config = Homie._loadConfig(configFile) users = config.get('USERS', '') logger.info("users: ") logger.info(users) sensor_types = config.get('SENSOR_TYPES', '') logger.info("sensor_types: ") logger.info(sensor_types)
#!/usr/bin/env python # -*- coding: UTF-8 -*- import time import homie import logging import random logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) TEMPERATURE_INTERVAL = 3 config = homie.loadConfigFile("homie-python.json") Homie = homie.Homie(config) temperatureNode = Homie.Node("temperature", "temperature") humidityNode = Homie.Node("humidity", "humidity") relayNode = Homie.Node("relay","relay") def main(): Homie.setFirmware("awesome-temperature", "1.0.0") temperatureNode.advertise("value") temperatureNode.advertise("unit") humidityNode.advertise("value") humidityNode.advertise("unit") relayNode.advertise("value") temperatureNode.advertise("unit") Homie.setup()
Homie.setNodeProperty(switchNode, "on", "false", True) def isUpdateTime(nextStatusCheck): return nextStatusCheck < time.time() def isNasStarting(): return nasWakeUpGraceTime > time.time() # ------------- # # MQTT settings # # ------------- # Homie = homie.Homie("mqtt-nas.json") switchNode = Homie.Node("switch", "switch") def switchOnHandler(mqttc, obj, msg): global nasWakeUpGraceTime global nasState payload = msg.payload.decode("UTF-8").lower() if payload == 'true': logger.info("Switch: ON") if not isNasStarting(): logger.debug("Sending WOL package") sendWol() nasWakeUpGraceTime = time.time() + nasWakeGraceInterval logger.debug("new wakeupgrace is: " + str(nasWakeUpGraceTime)) Homie.setNodeProperty(switchNode, "on", "true", True)
def main(): path = os.path.dirname(os.path.realpath(__file__)) Homie = homie.Homie("{path}/configs/manage.json".format(path=path)) m = Manager(None, Homie) m.run()