def main(): print("Starting energy monitor example") energenie.init() # Replace the names here with those in your own registry.kvs d_plug = energenie.registry.get("plug893") d_open = energenie.registry.get("open2664") d_motion = energenie.registry.get("motion4162") devices = (d_plug, d_open, d_motion) with IOT.Client(config="energenie_pi_staging.ini") as client: # create energenie "Thing" t_energenie = create_energenie_thing(client) # create a feed for each room and add its instance to the rooms dict f_monitor = create_monitor_feed(t_energenie) f_open = create_open_feed(t_energenie) f_motion = create_motion_feed(t_energenie) feeds = (f_monitor, f_open, f_motion) t_energenie.set_public(True) # provide a default incoming message handler, useful for logging every message def incoming(address, message): print("\nIncoming from %s" % str(address)) Logger.logMessage(message) energenie.fsk_router.when_incoming(incoming) print("Logging to file:%s" % Logger.LOG_FILENAME) try: while True: sensor_monitor_loop(feeds, devices) finally: energenie.finished()
def __init__(self, outlet, controller): energenie.init() self.state = True if controller.localdb: unique_name = controller.localdb.get("outlet-" + str(outlet)) if unique_name: self.name = unique_name else: self.name = OUTLETS[outlet]["name"] self.instance = OUTLETS[outlet]["instance"]
def run_func(): energenie.init() # Load all devices into variables auto created in the global scope # You can pass any context here, such as a class to contain your devices import sys me_global = sys.modules[__name__] energenie.registry.load_into(me_global) try: count = 0 while count < 2: auto_loop() count = count + 1 finally: energenie.finished()
def main(): print("init...") cleanup_GPIO.cleanup() energenie.init() print("done") try: test_loop() finally: print("cleanup...") try: energenie.finished() finally: try: energenie.cleanup() # forceably clean up GPIO lines finally: print("done")
def test_loop(): print("init...") energenie.init() print("done") try: while True: cycle(HOLDOFF) finally: print("cleanup...") try: energenie.finished() finally: try: energenie.cleanup() # forceably clean up GPIO lines finally: print("done")
def load_energenie(elib=False): energenie_monitors = [] energenie_buttons = [] if elib: elib.init() # Load all energenie sockets for b in getAllButtons(): b['device'] = elib.Devices.ENER002((b['remote'], b['socket'])) energenie_buttons.append(b) logger.debug("Adding device %s.%s" % (str(hex(b['remote'])), b['socket'])) # Load all energenie power monitor devices for k in config.POWER_MONITORS: d = elib.registry.get(config.POWER_MONITORS[k]['deviceid']) #d = elib.Devices.MIHO004(device_id = config.POWER_MONITORS[k]['deviceid']) energenie_monitors.append(d) logger.debug("Adding monitor %s" % (config.POWER_MONITORS[k]['text'])) logger.info("Added %s Energenie power socket devices" % len(energenie_buttons)) logger.info("Added %s Energenie power monitor devices" % len(energenie_monitors)) else: logger.warn("Energenie radio functions not available") # Add some dummy energy monitoring devices dd1 = dummyDevice() dd2 = dummyDevice() dd3 = dummyDevice() energenie_monitors.append(dd1) energenie_monitors.append(dd2) energenie_monitors.append(dd3) energenie_monitors.append(dd2) energenie = { 'lib': elib, 'buttons': energenie_buttons, 'monitors': energenie_monitors, } return energenie
def main(): """Main entry point""" print("PYENERGENIE setup tool") print("If it hangs here,") print("please disable hardware SPI in PREFERENCES/CONFIGURATION") print() print("init...") energenie.init() print("done") try: setup_tool() finally: print("cleanup...") try: energenie.finished() finally: try: energenie.cleanup() # forceably clean up GPIO lines finally: print("done")
global socket_state print("Setting socket switches to %s" % str(socket_state)) for device in energenie.registry.devices(): # Only try to toggle the switch for devices that actually have a switch if device.has_switch(): print(" socket id %s" % device) device.set_switch(socket_state) socket_state = not socket_state time.sleep(APP_DELAY) if __name__ == "__main__": print("starting socket tester (from registry)") energenie.init() socket_state = False try: while True: socket_toggle_loop() finally: energenie.finished() # END
fan.turn_on() tv.turn_on() time.sleep(APP_DELAY) print("Turning OFF") fan.turn_off() tv.turn_off() time.sleep(APP_DELAY) if __name__ == "__main__": print("Starting auto example") energenie.init() # Load all devices into variables auto created in the global scope # You can pass any context here, such as a class to contain your devices import sys me_global = sys.modules[__name__] energenie.registry.load_into(me_global) try: while True: auto_loop() finally: energenie.finished() # END
def main(): energenie.init() socket_runner = EnergenieSocketRunner(config='m2_fan.ini') energenie.discovery_ask(energenie_ask_fn) in_background(socket_runner) energenie.finished()