def get_leaf_update(): logging.debug("login = %s , password = %s" % (username, password)) logging.info("Prepare Session get car update") s = pycarwings2.Session(username, password, "NE") logging.info("Login...") logging.info(datetime.now().strftime("%Y-%m-%d %H:%M:%S")) try: l = s.get_leaf() except: logging.error("CarWings API error") logging.info("Requesting update from car..wait 30s") try: result_key = l.request_update() except: logging.error("ERROR: no responce from car update") time.sleep(30) battery_status = l.get_status_from_update(result_key) while battery_status is None: logging.error("ERROR: no responce from car") time.sleep(10) battery_status = l.get_status_from_update(result_key) leaf_info = l.get_latest_battery_status() return (leaf_info)
def get_leaf_status(): logging.debug("login = %s , password = %s" % (leaf_username, leaf_password)) logging.info("Prepare Session") s = pycarwings2.Session(leaf_username, leaf_password, nissan_region_code) logging.info("Login...") logging.info("Start update time: " + datetime.now().strftime("%Y-%m-%d %H:%M:%S")) try: l = s.get_leaf() except: logging.error("CarWings API error") return logging.info("get_latest_battery_status") leaf_info = l.get_latest_battery_status() if leaf_info: logging.info( "date %s" % leaf_info.answer["BatteryStatusRecords"]["OperationDateAndTime"]) logging.info( "date %s" % leaf_info.answer["BatteryStatusRecords"]["NotificationDateAndTime"] ) logging.info("battery_capacity2 %s" % leaf_info.answer["BatteryStatusRecords"]["BatteryStatus"] ["BatteryCapacity"]) logging.info("battery_capacity %s" % leaf_info.battery_capacity) logging.info("charging_status %s" % leaf_info.charging_status) logging.info("battery_capacity %s" % leaf_info.battery_capacity) logging.info("battery_remaining_amount %s" % leaf_info.battery_remaining_amount) logging.info("charging_status %s" % leaf_info.charging_status) logging.info("is_charging %s" % leaf_info.is_charging) logging.info("is_quick_charging %s" % leaf_info.is_quick_charging) logging.info("plugin_state %s" % leaf_info.plugin_state) logging.info("is_connected %s" % leaf_info.is_connected) logging.info("is_connected_to_quick_charger %s" % leaf_info.is_connected_to_quick_charger) logging.info("time_to_full_trickle %s" % leaf_info.time_to_full_trickle) logging.info("time_to_full_l2 %s" % leaf_info.time_to_full_l2) logging.info("time_to_full_l2_6kw %s" % leaf_info.time_to_full_l2_6kw) logging.info("leaf_info.battery_percent %s" % leaf_info.battery_percent) # logging.info("getting climate update") # climate = l.get_latest_hvac_status() # pprint.pprint(climate) logging.info("End update time: " + datetime.now().strftime("%Y-%m-%d %H:%M:%S")) #logging.info("Schedule API update every " + GET_UPDATE_INTERVAL + "min") return (leaf_info) else: logging.info("Did not get any response from the API") return
def get_leaf(auth): if auth is None: return None session = pycarwings2.Session(auth.username, auth.password , "NE") try: return session.get_leaf() except CarwingsError as e: return None
def getNissanSession(): logging.debug("login = %s, password = %s, region = %s" % (username, password, region)) s = pycarwings2.Session(username, password, region) leaf = s.get_leaf() # Give the nissan servers a bit of a delay so that we don't get stale data time.sleep(1) return leaf
def leaf_connect(config): """Connection to the carwings server. The connection elements are taken from the config dict. """ feedback(_(32050)) server = pycarwings2.Session(config['username'], config['password'], config['region']) leaf = server.get_leaf() return leaf
def Login(self): parser = SafeConfigParser() candidates = [ 'config.ini', 'my_config.ini' ] found = parser.read(candidates) username = parser.get('get-leaf-info', 'username') password = parser.get('get-leaf-info', 'password') logging.debug("login = %s , password = %s" % ( username , password) ) print("Prepare Session") s = pycarwings2.Session(username, password , "NNA") print("Login...") return s.get_leaf()
def setup(hass, config): username = config[DOMAIN][CONF_USERNAME] password = config[DOMAIN][CONF_PASSWORD] import pycarwings2 _LOGGER.debug("Logging into You+Nissan...") try: s = pycarwings2.Session(username, password, config[DOMAIN][CONF_REGION]) _LOGGER.debug("Fetching Leaf Data") leaf = s.get_leaf() except (RuntimeError, urllib.error.HTTPError): _LOGGER.error( "Unable to connect to Nissan Connect with username and password") return False except KeyError: _LOGGER.error( "Unable to fetch car details..." " do you actually have a Leaf connected to your account?") return False except: _LOGGER.error( "An unknown error occurred while connecting to Nissan: %s", sys.exc_info()[0]) _LOGGER.info("Successfully logged in and fetched Leaf info") _LOGGER.info( "WARNING: This may poll your Leaf too often, and drain the 12V." " If you drain your car's 12V it won't start" " as the drive train battery won't connect" " Don't set the intervals too low.") hass.data[DATA_LEAF] = {} hass.data[DATA_LEAF][leaf.vin] = LeafDataStore(leaf, hass, config) for component in LEAF_COMPONENTS: if (component != 'device_tracker' or config[DOMAIN][CONF_NCONNECT] is True): load_platform(hass, component, DOMAIN, {}, config) return True
def setup_leaf(car_config): """Set up a car.""" _LOGGER.debug("Logging into You+Nissan...") username = car_config[CONF_USERNAME] password = car_config[CONF_PASSWORD] region = car_config[CONF_REGION] leaf = None try: # This might need to be made async (somehow) causes # homeassistant to be slow to start sess = pycarwings2.Session(username, password, region) leaf = sess.get_leaf() except KeyError: _LOGGER.error( "Unable to fetch car details..." " do you actually have a Leaf connected to your account?") return False except pycarwings2.CarwingsError: _LOGGER.error( "An unknown error occurred while connecting to Nissan: %s", sys.exc_info()[0], ) return False _LOGGER.warning( "WARNING: This may poll your Leaf too often, and drain the 12V" " battery. If you drain your cars 12V battery it WILL NOT START" " as the drive train battery won't connect." " Don't set the intervals too low.") data_store = LeafDataStore(hass, leaf, car_config) hass.data[DATA_LEAF][leaf.vin] = data_store for component in LEAF_COMPONENTS: if component != "device_tracker" or car_config[CONF_NCONNECT]: load_platform(hass, component, DOMAIN, {}, car_config) async_track_point_in_utc_time(hass, data_store.async_update_data, utcnow() + INITIAL_UPDATE)
def climate_control(climate_control_instruction): logging.debug("login = %s , password = %s" % (username, password)) logging.info("Prepare Session climate control update") s = pycarwings2.Session(username, password, "NE") logging.info("Login...") logging.info(datetime.now().strftime("%Y-%m-%d %H:%M:%S")) l = s.get_leaf() if climate_control_instruction == 1: logging.info("Turning on climate control..wait 60s") result_key = l.start_climate_control() time.sleep(60) start_cc_result = l.get_start_climate_control_result(result_key) logging.info(start_cc_result) if climate_control_instruction == 0: logging.info("Turning off climate control..wait 60s") result_key = l.stop_climate_control() time.sleep(60) stop_cc_result = l.get_stop_climate_control_result(result_key) logging.info(stop_cc_result)
def __init__(self, username, password): self._leaf = None self.log = logging.getLogger() self.log.setLevel(logging.INFO) self.session = pycarwings2.Session(username, password, 'NE')
async def leaf_login(): nonlocal leaf sess = pycarwings2.Session(username, password, region) leaf = sess.get_leaf()
def main(): # Check zappi in eco mode & car connected zappi_data = get_zappi_status('') if (zappi_data == -1): return ('fail') if (zappi_data['zappi'][0]['pst'] != 'A') & (zappi_data['zappi'][0]['zmo'] == 3): # Get battery charge of leaf -> need to update battery status logging.info("Car connected & zappi in Eco+ mode") logging.info("Getting latest leaf battery status") print("Preparing Carwings Session") s = pycarwings2.Session(leaf_username, leaf_password, nissan_region_code) print("Login...") try: leaf = s.get_leaf() except: logging.error("CarWings API error (leaf = s.get_leaf())") return # Give the nissan servers a bit of a delay so that we don't get stale data time.sleep(1) logging.info("get_latest_battery_status from servers") # Make sure Nissan servers available before we try updating battery try: leaf_info = leaf.get_latest_battery_status() except: logging.error( "CarWings API error (leaf_info = leaf.get_latest_battery_status())" ) return # Update servers - warning depletes 12v onboard battery! #update_status = update_battery_status(leaf, sleepsecs) # Should have up to date info now leaf_info = leaf.get_latest_battery_status() # Make sure we have data if (battery_percent not in leaf_info): logging.error("No battery percentage data in leaf_info") return ('fail') battery_remaining_amount = int( int(leaf_info.battery_percent) * battery_cap / 100) logging.info("Leaf battery remaining amount = %d KwH", battery_remaining_amount) if (battery_target_amnt < battery_remaining_amount): # Don't need to charge logging.info("Current battery charge %d, exceeds target" % battery_remaining_amount) else: # Need to charge add_kwh = (battery_target_amnt - battery_remaining_amount) logging.info("Adding %d Kwh" % add_kwh) set_boost_mode('', add_kwh, '0000') # Check Zappi didn't do a hard reset.. time.sleep(120) # Refresh data zappi_data = get_zappi_status('') if "tbh" not in zappi_data: # Not set, try again! logging.info("Failed to set boost, re-trying") set_boost_mode('', add_kwh, '0000') return ('success') elif (zappi_data['zappi'][0]['pst'] == 'A'): logging.info("Car not connected") # Try looping? return ('Not connected') elif (zappi_data['zappi'][0]['zmo'] != 3): logging.info("Zappi not in Eco+ mode") return ('Not in Eco+ mode') else: logging.info("Unknown error") return ('Unknown error')
def test_bad_password(): with pytest.raises(pycarwings2.CarwingsError) as excinfo: s = pycarwings2.Session("*****@*****.**", "password", "NE") l = s.get_leaf() assert 'INVALID' in str(excinfo.value)
def __init__(self, username, password, region): try: self.session = pycarwings2.Session(username, password, region) self.leaf = self.session.get_leaf() except: pass
parser = configparser.SafeConfigParser() else: # SafeConfigParser was renamed to ConfigParser in Python 3.2+ parser = configparser.ConfigParser() candidates = ['config.ini', 'my_config.ini'] found = parser.read(candidates) username = parser.get('get-leaf-info', 'username') password = parser.get('get-leaf-info', 'password') region = parser.get('get-leaf-info', 'region') logging.debug("login = %s , password = %s" % (username, password)) print("Prepare Session") s = pycarwings2.Session(username, password, region) print("Login...") l = s.get_leaf() print("get_latest_battery_status") leaf_info = l.get_latest_battery_status() print("date %s" % leaf_info.answer["BatteryStatusRecords"]["OperationDateAndTime"]) print("date %s" % leaf_info.answer["BatteryStatusRecords"]["NotificationDateAndTime"]) print("battery_capacity2 %s" % leaf_info.answer["BatteryStatusRecords"] ["BatteryStatus"]["BatteryCapacity"]) print("battery_capacity %s" % leaf_info.battery_capacity) print("charging_status %s" % leaf_info.charging_status) print("battery_capacity %s" % leaf_info.battery_capacity)
import pprint logging.basicConfig(stream=sys.stdout, level=logging.ERROR) parser = SafeConfigParser() candidates = [ 'config.ini', 'my_config.ini' ] found = parser.read(candidates) username = parser.get('get-leaf-info', 'username') password = parser.get('get-leaf-info', 'password') logging.debug("login = %s , password = %s" % ( username , password) ) print "Prepare Session" s = pycarwings2.Session(username, password , "NE") print "Login..." l = s.get_leaf() print "get_latest_battery_status" leaf_info = l.get_latest_battery_status() print "date %s" % leaf_info.answer["BatteryStatusRecords"]["OperationDateAndTime"] print "date %s" % leaf_info.answer["BatteryStatusRecords"]["NotificationDateAndTime"] print "battery_capacity2 %s" % leaf_info.answer["BatteryStatusRecords"]["BatteryStatus"]["BatteryCapacity"] print "battery_capacity %s" % leaf_info.battery_capacity print "charging_status %s" % leaf_info.charging_status print "battery_capacity %s" % leaf_info.battery_capacity print "battery_remaining_amount %s" % leaf_info.battery_remaining_amount print "charging_status %s" % leaf_info.charging_status print "is_charging %s" % leaf_info.is_charging
def working_session(): global plug1 global plug2 global plug3 global last_plug1 global last_plug2 global last_plug3 global leaf1 global leaf2 locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') #help(SmartPlug) logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) logging.getLogger("pycarwings2").setLevel(logging.ERROR) logging.getLogger("urllib3").setLevel(logging.ERROR) parser = ConfigParser() candidates = ['config.ini', 'my_config.ini'] found = parser.read(candidates) bot_token = parser.get('get-leaf-info', 'bot_token') print("bot_token", bot_token) bot_chatID = parser.get('get-leaf-info', 'bot_chatID') print("bot_chatID", bot_chatID) test = telegram_bot_sendtext("Starting ....", bot_token, bot_chatID) while (1): print("\n\n\n\n\n\nAnother loop\n\n\n\n") found = parser.read(candidates) username = parser.get('get-leaf-info', 'username') password = parser.get('get-leaf-info', 'password') username2 = parser.get('get-leaf-info', 'username2') password2 = parser.get('get-leaf-info', 'password2') region = parser.get('get-leaf-info', 'region') plug1address = parser.get('get-leaf-info', 'plug1address') plug2address = parser.get('get-leaf-info', 'plug2address') plug3address = parser.get('get-leaf-info', 'plug3address') useweekday = ("True" == parser.get('get-leaf-info', 'cfg_use_weekday')) start_minimum_price = int( parser.get('get-leaf-info', 'start_minimum_price')) end_minimum_price = int( parser.get('get-leaf-info', 'end_minimum_price')) start_maximum_price = int( parser.get('get-leaf-info', 'start_maximum_price')) end_maximum_price = int( parser.get('get-leaf-info', 'end_maximum_price')) current_date_and_time = datetime.datetime.now() current_hour = current_date_and_time.hour if (current_hour >= start_minimum_price) and (current_hour < end_minimum_price): print("Time slot: Minimum price") charge_min = True charge_tgt = True charge_max = True charge_min_prio = True charge_tgt_prio = True charge_max_prio = True else: if (current_hour >= start_maximum_price) and (current_hour < end_maximum_price): print("Time slot: Maximum price") charge_min = False charge_tgt = False charge_max = False charge_min_prio = False charge_tgt_prio = False charge_max_prio = False else: print("Time slot: Normal price") charge_min = True charge_tgt = False charge_max = False charge_min_prio = True charge_tgt_prio = True charge_max_prio = False print("Using weekday?", useweekday) if not (useweekday): todaypriority = int(parser.get('Normal', 'todaypriority')) leaf1min = int(parser.get('Normal', 'leaf1min')) leaf2min = int(parser.get('Normal', 'leaf2min')) leaf1tgt = int(parser.get('Normal', 'leaf1tgt')) leaf2tgt = int(parser.get('Normal', 'leaf2tgt')) leaf1max = int(parser.get('Normal', 'leaf1max')) leaf2max = int(parser.get('Normal', 'leaf2max')) else: advancehours = int(parser.get('get-leaf-info', 'advancehours')) hours_added = datetime.timedelta(hours=advancehours) future_date_and_time = current_date_and_time + hours_added weekday = calendar.day_name[future_date_and_time.weekday()] print("Weekday:", weekday) todaypriority = int(parser.get(weekday, 'todaypriority')) leaf1min = int(parser.get(weekday, 'leaf1min')) leaf2min = int(parser.get(weekday, 'leaf2min')) leaf1tgt = int(parser.get(weekday, 'leaf1tgt')) leaf2tgt = int(parser.get(weekday, 'leaf2tgt')) leaf1max = int(parser.get(weekday, 'leaf1max')) leaf2max = int(parser.get(weekday, 'leaf2max')) plug1 = SmartPlug(plug1address) emeterinfo1 = infoEnchufe(plug1, "First car plug") plug2 = SmartPlug(plug2address) emeterinfo2 = infoEnchufe(plug2, "Second car plug") plug3 = SmartPlug(plug3address) emeterinfo3 = infoEnchufe(plug3, "Water warmer plug") if (write_thingsboard): print(config_tb.telemetry_address) print(config_tb.telemetry_address2) unixtime = int(time.mktime(plug1.time.timetuple()) * 1000) unixtime2 = int(time.mktime(plug2.time.timetuple()) * 1000) category = "plug1" pload = { 'ts': unixtime, "values": { category + '_is_on': plug1.is_on, category + '_rssi': plug1.rssi, category + '_current_ma': emeterinfo1['current_ma'], category + '_power_mw': emeterinfo1['power_mw'], } } print(pload) print("========") r = requests.post(config_tb.telemetry_address, json=pload) print(r.status_code) category = "plug2" pload = { 'ts': unixtime, "values": { category + '_is_on': plug2.is_on, category + '_rssi': plug2.rssi, category + '_current_ma': emeterinfo2['current_ma'], category + '_power_mw': emeterinfo2['power_mw'], } } print(pload) print("========") r = requests.post(config_tb.telemetry_address2, json=pload) print(r.status_code) category = "plug3" pload = { 'ts': unixtime, "values": { category + '_is_on': plug3.is_on, category + '_rssi': plug3.rssi, category + '_current_ma': emeterinfo3['current_ma'], category + '_power_mw': emeterinfo3['power_mw'], } } print(pload) print("========") r = requests.post(config_tb.telemetry_address3, json=pload) print(r.status_code) sleepsecs = 10 # Time to wait before polling Nissan servers for update sleepsecs2 = 10 # Time to wait before polling Nissan servers for update # Main program #logging.debug("login = %s, password = %s, region = %s" % (username, password, region)) #logging.debug("login2 = %s, password2 = %s, region = %s" % (username2, password2, region)) print("Prepare Session 1") s = pycarwings2.Session(username, password, region) print("Login...1") leaf1 = s.get_leaf() print("Prepare Session 2") s2 = pycarwings2.Session(username2, password2, region) print("Login...2") leaf2 = s2.get_leaf() # Give the nissan servers a bit of a delay so that we don't get stale data' time.sleep(1) print("********** First Car Last Status ************") print("get_latest_battery_status from servers") try: leaf1_info = leaf1.get_latest_battery_status() #start_date = leaf1_info.answer["BatteryStatusRecords"]["OperationDateAndTime"] #print("start_date=", start_date) print_info(leaf1_info) bat1 = leaf1_info.battery_percent except: print("No hubo suerte con el leaf1") bat1 = 0 print("request an update from the car itself") key = leaf1.request_update() print("********** Second Car Last Status ************") print("get_latest_battery_status from servers") try: leaf2_info = leaf2.get_latest_battery_status() #start_date = leaf2_info.answer["BatteryStatusRecords"]["OperationDateAndTime"] #print("start_date=", start_date) print_info(leaf2_info) bat2 = leaf2_info.battery_percent except: print("No hubo suerte con el leaf2") bat2 = 0 print("request an update from the car itself") key2 = leaf2.request_update() # Give the nissan servers a bit of a delay so that we don't get stale data time.sleep(1) print("***** Waiting for status update *****") print("... First car") update_status = wait_update_battery_status(leaf1, key, sleepsecs, 5, 5) print("... Second car") update_status2 = wait_update_battery_status(leaf2, key2, sleepsecs2, 5, 5) print("********** First Car Current Status************") if (update_status is not None): print("OK: >>>>", update_status.answer['status']) try: latest_leaf_info = leaf1.get_latest_battery_status() #latest_date = latest_leaf_info.answer["BatteryStatusRecords"]["OperationDateAndTime"] #print("latest_date=", latest_date) print_info(latest_leaf_info) print("llegue aqui!") bat1 = latest_leaf_info.battery_percent conn1 = latest_leaf_info.is_connected print("llegue aqui B!") print(latest_leaf_info.answer["BatteryStatusRecords"] ["OperationDateAndTime"]) print("llegue aqui B2!") locale.setlocale(locale.LC_ALL, 'es_ES.UTF-8') print(latest_leaf_info.answer["BatteryStatusRecords"] ["OperationDateAndTime"]) date_time_obj = datetime.datetime.strptime( latest_leaf_info.answer["BatteryStatusRecords"] ["OperationDateAndTime"], '%d-%b-%Y %H:%M') print("llegue aqui C!") unixtime = int( (time.mktime(date_time_obj.timetuple()) - 3600) * 1000) print("llegue aqui D!") remainingtime = latest_leaf_info.time_to_full_l2.total_seconds( ) print("pero si fue bien!") except: print("No hay informacion actualizada para leaf1") conn1 = True try: print("Vamos con la subida de datos") category = "car1" pload = { 'ts': unixtime, "values": { category + '_bat': bat1, category + '_conn': conn1, category + '_time2full': remainingtime } } print(pload) print("========") r = requests.post(config_tb.telemetry_address, json=pload) print(r.status_code) except: print("No se pudo subir la informaciĆ³n de leaf1 al panel") else: print("ERROR: >>>> status could not be retrieved") conn1 = True print("********** Second Car Current Status************") if (update_status2 is not None): print("OK: >>>>", update_status2.answer['status']) try: latest_leaf_info2 = leaf2.get_latest_battery_status() #latest_date2 = latest_leaf_info2.answer["BatteryStatusRecords"]["OperationDateAndTime"] #print("latest_date2=", latest_date2) print_info(latest_leaf_info2) print("llegue aqui 2") bat2 = latest_leaf_info2.battery_percent conn2 = latest_leaf_info2.is_connected date_time_obj = datetime.datetime.strptime( latest_leaf_info2.answer["BatteryStatusRecords"] ["OperationDateAndTime"], '%d-%b-%Y %H:%M') unixtime = int( (time.mktime(date_time_obj.timetuple()) - 3600) * 1000) remainingtime = latest_leaf_info2.time_to_full_l2.total_seconds( ) print("incluso acabe") except: print("No hay informacion actualizada para leaf2") conn2 = True try: print("intentamos subir al panel del coche 2") category = "car2" pload = { 'ts': unixtime, "values": { category + '_bat': bat2, category + '_conn': conn2, category + '_time2full': remainingtime } } print(pload) print("========") r = requests.post(config_tb.telemetry_address2, json=pload) print(r.status_code) print("acabe con el panel2") except: print("No se pudo subir la informaciĆ³n de leaf2 al panel") else: print("ERROR: >>>> status could not be retrieved") conn2 = True locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') if (todaypriority == 1): charge_leaf1_min = charge_min_prio charge_leaf2_min = charge_min charge_leaf1_tgt = charge_tgt_prio charge_leaf2_tgt = charge_tgt charge_leaf1_max = charge_max_prio charge_leaf2_max = charge_max else: charge_leaf2_min = charge_min_prio charge_leaf1_min = charge_min charge_leaf2_tgt = charge_tgt_prio charge_leaf1_tgt = charge_tgt charge_leaf2_max = charge_max_prio charge_leaf1_max = charge_max charge_leaf1 = 0 charge_leaf2 = 0 print("charge_leaf1_min", charge_leaf1_min) print("charge_leaf2_min", charge_leaf2_min) if (bat1 < leaf1min): print("leaf1 < min") if charge_leaf1_min: charge_leaf1 = 10 else: if (bat1 < leaf1tgt): print("leaf1 < tgt") if charge_leaf1_tgt: charge_leaf1 = 5 else: if (bat1 < leaf1max): print("leaf1 < max") if charge_leaf1_max: charge_leaf1 = 1 else: print("leaf1 >= max") if (bat2 < leaf2min): print("leaf2 < min") if charge_leaf2_min: charge_leaf2 = 10 else: if (bat2 < leaf2tgt): print("leaf2 < tgt") if charge_leaf2_tgt: charge_leaf2 = 5 else: if (bat2 < leaf2max): print("leaf2 < max") if charge_leaf2_max: charge_leaf2 = 1 else: print("leaf2 >= max") if todaypriority == 1: if (charge_leaf1 > 0): charge_leaf1 += 1 else: if (charge_leaf2 > 0): charge_leaf2 += 1 print("charge points 1", charge_leaf1) print("charge points 2", charge_leaf2) if not (conn1): charge_leaf1 = 0 print("charge points 1", charge_leaf1) print("charge points 2", charge_leaf2) if charge_leaf1 > charge_leaf2: turn_1_on() else: if charge_leaf1 < charge_leaf2: car2present = turn_2_on() if not car2present: print("Let's proceed to the next in the queue") if (charge_leaf1 > 0): turn_1_on() else: turn_off() else: turn_off() print('Plug 1 Is on: %s' % plug1.is_on) print('Plug 2 Is on: %s' % plug2.is_on) print('Plug 3 Is on: %s' % plug3.is_on) if (last_plug1 != plug1.is_on): test = telegram_bot_sendtext('Leaf 1 %s' % plug1.is_on, bot_token, bot_chatID) if (last_plug2 != plug2.is_on): test = telegram_bot_sendtext('Leaf 2 %s' % plug2.is_on, bot_token, bot_chatID) if (last_plug3 != plug3.is_on): test = telegram_bot_sendtext('Other3 %s' % plug3.is_on, bot_token, bot_chatID) last_plug1 = plug1.is_on last_plug2 = plug2.is_on last_plug3 = plug3.is_on print('Sleeping for 5 minutes') time.sleep(300)