def periodic_update(interval, out_file, verbose): if out_file is None: fp = sys.stdout else: # Open the file for appending fp = open(out_file, "a") __log("Establishing session", verbose) session = vivint.VivintCloudSession(os.environ["USERNAME"], os.environ["PASSWORD"]) __log("Listing panels", verbose) panels = session.get_panels() while running: for panel in panels: __log("Updating panel %d" % panel.id(), verbose) panel.update_devices() __log("Listing thermosats", verbose) thermostats = panel.get_devices(device_type_set=[ vivint.VivintCloudSession.VivintDevice.DEVICE_TYPE_THERMOSTAT ]) for thermostat in thermostats: __log( "Getting state of thermostat %d on panel %d" % (thermostat.id(), panel.id()), verbose) state = thermostat.current_state() # Now bolt the other context to the state, and write it out. state["panel_arm_state"] = panel.get_armed_state() state["panel_id"] = panel.id() state["thermostat_id"] = thermostat.id() state["timestamp"] = time.time() __log("Logging state", verbose) fp.write(json.dumps(state, sort_keys=True) + "\n") fp.flush() # Now, change the state to the night-time one if we're home at the same time every # day. print(json.dumps([ state, time.strftime("%FT%T"), last_state_change, state_change_time, state["climate_state"] == "home", time.strftime("%F") != last_state_change["date"], time.strftime("%T") >= state_change_time ]), file=sys.stdout, flush=True) if state["climate_state"] == "home" and time.strftime( "%F") != last_state_change["date"] and time.strftime( "%T") >= state_change_time: thermostat.set_state("sleep") last_state_change["date"] = time.strftime("%F") __log("Sleeping", verbose) time.sleep(interval)
def get_armed_state(self): logging.debug('contacting vivint') try: session = vivint.VivintCloudSession( Home.private.get('Vivint', 'username'), Home.private.get('Vivint', 'password')) panels = session.get_panels() for panel in panels: panel.update_devices() devices = panel.get_devices() logging.debug('vivint: ' + panel.get_armed_state()) return panel.get_armed_state() except: return "connection error"
def periodic_update(interval, out_file, verbose): if out_file is None: fp = sys.stdout else: # Open the file for appending fp = open(out_file, "a") __log("Establishing session", verbose) session = vivint.VivintCloudSession(os.environ["USERNAME"], os.environ["PASSWORD"]) __log("Listing panels", verbose) panels = session.get_panels() while running: for panel in panels: __log("Updating panel %d" % panel.id(), verbose) panel.update_devices() __log("Listing thermosats", verbose) thermostats = panel.get_devices(device_type_set=[ vivint.VivintCloudSession.VivintDevice.DEVICE_TYPE_THERMOSTAT ]) for thermostat in thermostats: __log( "Getting state of thermostat %d on panel %d" % (thermostat.id(), panel.id()), verbose) state = thermostat.current_state() # Now bolt the other context to the state, and write it out. state["panel_arm_state"] = panel.get_armed_state() state["panel_id"] = panel.id() state["thermostat_id"] = thermostat.id() state["timestamp"] = time.time() __log("Logging state", verbose) fp.write(json.dumps(state, sort_keys=True) + "\n") fp.flush() __log("Sleeping", verbose) time.sleep(interval)
#!/usr/bin/env python3 import time import vivint # Set up the connection to the cloud session session = vivint.VivintCloudSession("*****@*****.**", "SuperSecretPassword") # List all panels (sites) that this user account has access to panels = session.get_panels() for panel in panels: logger.debug("devices in panel {}: {}".format(panel, panel.get_devices())) # In this case, get the first door from the first site door = panels[0].get_devices(device_type_set=[ vivint.VivintCloudSession.VivintDevice.DEVICE_TYPE_DOOR_LOCK ])[0] # Get the current state and print it out print("Door state:", door.current_state()) # Let the change propagate for a bit time.sleep(2) for panel in panels: # Update every panel. Doing this also updates devices that # were spawned from those panels in-place, unless you set # devices' receive_updates property is set to False. panel.update_devices()
#!/usr/bin/env python3 import time import vivint from credentials import vivint_email, vivint_pwd # Set up the connection to the cloud session session = vivint.VivintCloudSession(vivint_email, vivint_pwd) # List all panels (sites) that this user account has access to panels = session.get_panels() # In this case, get the first thermostat from the first site thermostat = panels[0].get_devices(device_type_set=[ vivint.VivintCloudSession.VivintDevice.DEVICE_TYPE_THERMOSTAT ])[0] state = thermostat.current_state() carrier_state = thermostat.carrier_state(None) initial_state = True # Get the current state and print it out print(state) print(carrier_state) # Set a few thermostat things. #thermostat.set_operation_mode("heat") #thermostat.set_fan_mode("always") #thermostat.set_temperature(10) # Let the change propagate for a bit
#!/usr/bin/env python3 import time import os import vivint from datetime import datetime # Set up the connection to the cloud session session = vivint.VivintCloudSession(os.environ["USERNAME"], os.environ["PASSWORD"]) # Sensors and Switches # switch_one_name = "Living Room Main Lights" # switch_two_name = "Dining Room Lights" # sensor_one_name = "Living Room Motion Detector" # sensor_two_name = "Dining Room Motion Detector" # List all panels (sites) that this user account has access to panels = session.get_panels() multiswitches = panels[0].get_devices(device_type_set=[ vivint.VivintCloudSession.VivintDevice.DEVICE_TYPE_LIGHT_MODULE ]) sensors = panels[0].get_devices(device_type_set=[ vivint.VivintCloudSession.VivintDevice.DEVICE_TYPE_WIRELESS_SENSOR ]) # Let the change propagate for a bit time.sleep(2)