def start(): if plugin_options['use_footer']: door_footer = showInFooter() # instantiate class to enable data in footer door_footer.button = "door_opening/start" # button redirect on footer door_footer.label = _(u'Opening Door') # label on footer msg = _(u'Time {} seconds').format(plugin_options['open_time']) door_footer.val = msg.encode('utf8').decode('utf8') # value on footer pass
def run(self): global stats temp_upd = None if plugin_options['use_footer']: temp_upd = showInFooter( ) # instantiate class to enable data in footer temp_upd.button = "system_update/status" # button redirect on footer temp_upd.label = _(u'System Update') # label on footer msg = _(u'Waiting to state') temp_upd.val = msg.encode('utf8').decode('utf8') # value on footer while not self._stop_event.is_set(): try: if plugin_options['use_update']: log.clear(NAME) self._update_rev_data() if self.status['can_update']: msg = _(u'New OSPy version is available!') stats['can_update'] = True report_ospyupdate() else: msg = _(u'Up-to-date') stats['can_update'] = False if self.status['can_update'] and plugin_options[ 'auto_update']: perform_update() self.started.set() else: msg = _(u'Plugin is not enabled') if plugin_options['use_footer']: if temp_upd is not None: temp_upd.val = msg.encode('utf8').decode( 'utf8') # value on footer else: log.error( NAME, _(u'Error: restart this plugin! Show in homepage footer have enabled.' )) self._sleep(3600) except Exception: self.started.set() log.error( NAME, _(u'System update plug-in') + ':\n' + traceback.format_exc()) self._sleep(60)
def run(self): last_msg = '' act_msg = '' ven_blind = None if plugin_options['use_footer']: ven_blind = showInFooter( ) # instantiate class to enable data in footer ven_blind.button = "venetian_blind/home" # button redirect on footer ven_blind.label = _(u'Venetian blind') # label on footer while not self._stop_event.is_set(): try: if plugin_options['use_control']: # if plugin is enabled show_msg = read_blinds_status() if plugin_options['use_footer']: # if footer is enabled if ven_blind is not None: if is_python2(): # in Python 2 ven_blind.val = show_msg else: # in Python 3 ven_blind.val = show_msg.encode('utf8').decode( 'utf8') # value on footer else: act_msg = _('Venetian blind is disabled.') if act_msg != last_msg: log.clear(NAME) log.info(NAME, act_msg) last_msg = act_msg if plugin_options['use_footer']: if ven_blind is not None: if is_python2(): ven_blind.val = act_msg else: ven_blind.val = act_msg.encode( 'utf8').decode( 'utf8') # value on footer self._sleep(2) except Exception: log.error( NAME, _('Venetian blind plug-in') + ':\n' + traceback.format_exc()) pass
def run(self): weather_mon = None if plugin_options['use_footer']: weather_mon = showInFooter( ) # instantiate class to enable data in footer weather_mon.label = _(u'Weather') # label on footer weather_mon.button = "weather_based_rain_delay/settings" # button redirect on footer weather_mon.val = '---' # value on footer while not self._stop_event.is_set(): try: if plugin_options[ 'enabled']: # if Weather-based Rain Delay plug-in is enabled if plugin_options['use_netatmo']: authorization = ClientAuth() devList = WeatherStationData(authorization) now = time.time() begin = now - (plugin_options['netatmo_hour']) * 3600 mac2 = plugin_options['netatmomac'] rainmac2 = plugin_options['netatmorain'] resp = (devList.getMeasure(mac2, '1hour', 'sum_rain', rainmac2, date_begin=begin, date_end=now, limit=None, optimize=False)) result = [(time.ctime(int(k)), v[0]) for k, v in resp['body'].items()] result.sort() xdate, xrain = zip(*result) zrain = 0 for yrain in xrain: zrain = zrain + yrain else: zrain = 0 log.clear(NAME) log.info(NAME, _(u'Checking rain status') + '...') current_data = weather.get_current_data() delaytime = int(plugin_options['delay_duration']) delaytimeAtmo = int( plugin_options['netatmo_interval']) * 60 if zrain > 0: log.info( NAME, _(u'Netatmo detected Rain') + ': %.1f ' % zrain + _(u'mm') + '. ' + _(u'Adding delay of') + ' ' + str(delaytime) + ' ' + _(u'hours') + '.') tempText = "" tempText += _( u'Netatmo detected Rain') + u' %.1f ' % zrain + _( u'mm') + '. ' + _( u'Adding delay of') + ' ' + str( delaytime) + ' ' + _(u'hours') if plugin_options['use_footer']: if weather_mon is not None: weather_mon.val = tempText.encode( 'utf8').decode('utf8') # value on footer rain_blocks[NAME] = datetime.datetime.now( ) + datetime.timedelta(hours=float(delaytime)) stop_onrain() self._sleep(delaytimeAtmo) else: if 'precipProbability' in current_data: if current_data['precipProbability'] > 0.75: log.info( NAME, _(u'Weather detected Rain') + ': ' + current_data['summary'] + _(u'Adding delay of') + ' ' + str(plugin_options['delay_duration']) + '.') rain_blocks[NAME] = datetime.datetime.now( ) + datetime.timedelta(hours=float( plugin_options['delay_duration'])) stop_onrain() tempText = "" tempText += _(u'Weather detected Rain') elif current_data['precipProbability'] > 0.1: log.info( NAME, _(u'No rain detected') + ': ' + current_data['summary'] + '. ' + _(u'No action.')) tempText = "" tempText += _(u'No rain detected') else: log.info( NAME, _(u'Good weather detected') + ': ' + current_data['summary'] + '. ' + _(u'Removing rain delay.')) tempText = "" tempText += _(u'Good weather detected') if NAME in rain_blocks: del rain_blocks[NAME] if plugin_options['use_footer']: if weather_mon is not None: weather_mon.val = tempText.encode( 'utf8').decode('utf8') # value on footer self._sleep(3600) else: log.clear(NAME) log.info(NAME, _(u'Plug-in is disabled.')) if NAME in rain_blocks: del rain_blocks[NAME] self._sleep(24 * 3600) except Exception: log.error( NAME, _(u'Weather-based Rain Delay plug-in') + ':\n' + traceback.format_exc()) self._sleep(3600)
def run(self): global stats temp_upd = None if plugin_options['use_footer']: temp_upd = showInFooter() # instantiate class to enable data in footer temp_upd.button = "sunrise_and_sunset/status" # button redirect on footer temp_upd.label = _('Sunrise and Sunset') # label on footer msg = _('Waiting to state') temp_upd.val = msg.encode('utf8').decode('utf8') # value on footer try: from astral.geocoder import database except ImportError: log.clear(NAME) log.info(NAME, _('Astral is not installed.')) log.info(NAME, _('Please wait installing astral...')) cmd = "pip3 install astral" run_command(cmd) log.info(NAME, _('Astral is now installed.')) while not self._stop_event.is_set(): try: if plugin_options['use_astro']: log.clear(NAME) city = None found_name = '' found_region = '' found_timezone ='' found_latitude = 0 found_longitude = 0 try: if plugin_options['location'] != 0: # 0 is none location from astral.geocoder import database, lookup find_loc = city_table[plugin_options['location']] city = lookup(find_loc, database()) # return example: LocationInfo(name='Addis Ababa', region='Ethiopia', timezone='Africa/Addis_Ababa', latitude=9.033333333333333, longitude=38.7) found_name = city.name found_region = city.region found_timezone = city.timezone found_latitude = city.latitude found_longitude = city.longitude else: if plugin_options['custom_location'] and plugin_options['custom_region'] and plugin_options['custom_timezone'] and plugin_options['custom_lati_longit']: from astral.geocoder import add_locations, database, lookup db = database() _loc = '{},{},{},{}'.format(plugin_options['custom_location'], plugin_options['custom_region'], plugin_options['custom_timezone'], plugin_options['custom_lati_longit']) add_locations(_loc, db) # "Somewhere,Secret Location,UTC,24°28'N,39°36'E" city = lookup(plugin_options['custom_location'], db) found_name = city.name found_region = city.region found_timezone = city.timezone found_latitude = city.latitude found_longitude = city.longitude else: log.info(NAME, _('You must fill in all required fields (location, region, timezone/name, latitude and longitude!')) city = None s = None if city is not None: log.info(NAME, _('Found city')) log.info(NAME, _('Name') + ': {}'.format(found_name)) log.info(NAME, _('Region') + ': {}'.format(found_region)) log.info(NAME, _('Timezone') + ': {}'.format(found_timezone)) log.info(NAME, _('Latitude') + ': {}'.format(round(found_latitude, 2))) log.info(NAME, _('Longitude') + ': {}'.format(round(found_longitude, 2))) import datetime from astral.sun import sun today = datetime.date.today() _day = int(today.strftime("%d")) _month = int(today.strftime("%m")) _year = int(today.strftime("%Y")) s = sun(city.observer, date=datetime.date(_year, _month, _day), tzinfo=found_timezone) log.info(NAME, '_______________ ' + '{}'.format(today) + ' _______________') log.info(NAME, _('Dawn') + ': {}'.format(s["dawn"].strftime("%H:%M:%S"))) log.info(NAME, _('Sunrise') + ': {}'.format(s["sunrise"].strftime("%H:%M:%S"))) log.info(NAME, _('Noon') + ': {}'.format(s["noon"].strftime("%H:%M:%S"))) log.info(NAME, _('Sunset') + ': {}'.format(s["sunset"].strftime("%H:%M:%S"))) log.info(NAME, _('Dusk') + ': {}'.format(s["dusk"].strftime("%H:%M:%S"))) msg = _('Sunrise') + ': {}, '.format(s["sunrise"].strftime("%H:%M:%S")) + _('Sunset') + ': {}'.format(s["sunset"].strftime("%H:%M:%S")) from astral import moon m = moon.phase(datetime.date(_year, _month, _day)) log.info(NAME, _('Moon phase') + ': {}'.format(round(m, 2))) msg += ', ' + _('Moon phase') + ': ' if m < 7: log.info(NAME, '* ' + _('New moon')) msg += _('New moon') elif m >= 7 and m < 14: log.info(NAME, '* ' + _('First quarter')) msg += _('First quarter') elif m >= 14 and m < 21: log.info(NAME, '* ' + _('Full moon')) msg += _('Full moon') elif m >= 21 and m < 28: log.info(NAME, '* ' + _('Last quarter')) msg += _('Last quarter') else: log.info(NAME, '* ' + _('Unkown phase')) msg += _('Unkown phase') except Exception: self.started.set() log.error(NAME, _('Astro plug-in') + ':\n' + traceback.format_exc()) self._sleep(2) else: msg =_(u'Plugin is not enabled') if plugin_options['use_footer']: if temp_upd is not None: temp_upd.val = msg.encode('utf8').decode('utf8') # value on footer else: log.error(NAME, _('Error: restart this plugin! Show in homepage footer have enabled.')) self._sleep(3600) except Exception: self.started.set() log.error(NAME, _('Astro plug-in') + ':\n' + traceback.format_exc()) self._sleep(60)
def run(self): temperature_ds = [-127, -127, -127, -127, -127, -127] msg_a_on = True msg_a_off = True last_text = '' send = False temp_sw = None if plugin_options['use_footer']: temp_sw = showInFooter( ) # instantiate class to enable data in footer temp_sw.button = "pool_heating/settings" # button redirect on footer temp_sw.label = _('Pool Heating') # label on footer ds_a_on = -127.0 ds_a_off = -127.0 millis = 0 # timer for clearing status on the web pages after 5 sec last_millis = int(round(time.time() * 1000)) safety_start = datetime.datetime.now() safety_end = datetime.datetime.now() + datetime.timedelta( minutes=plugin_options['safety_mm']) a_state = -3 # for state in footer "Waiting." regulation_text = _(u'Waiting to turned on or off.') if not plugin_options['enabled_a']: a_state = -1 # for state in footer "Waiting (not enabled regulation in options)." log.info(NAME, datetime_string() + ' ' + _('Waiting.')) end = datetime.datetime.now() while not self._stop_event.is_set(): try: if plugin_options[ "sensor_probe"] == 2: # loading probe name from plugin air_temp_humi try: from plugins.air_temp_humi import plugin_options as air_temp_data self.status['ds_name_0'] = air_temp_data['label_ds0'] self.status['ds_name_1'] = air_temp_data['label_ds1'] self.status['ds_name_2'] = air_temp_data['label_ds2'] self.status['ds_name_3'] = air_temp_data['label_ds3'] self.status['ds_name_4'] = air_temp_data['label_ds4'] self.status['ds_name_5'] = air_temp_data['label_ds5'] self.status['ds_count'] = air_temp_data['ds_used'] from plugins.air_temp_humi import DS18B20_read_probe # value with temperature from probe DS1-DS6 temperature_ds = [ DS18B20_read_probe(0), DS18B20_read_probe(1), DS18B20_read_probe(2), DS18B20_read_probe(3), DS18B20_read_probe(4), DS18B20_read_probe(5) ] except: log.error( NAME, _('Unable to load settings from Air Temperature and Humidity Monitor plugin! Is the plugin Air Temperature and Humidity Monitor installed and set up?' )) pass # regulation if plugin_options['enabled_a'] and plugin_options[ "sensor_probe"] != 0: # enabled regulation and selected input for probes sensor/airtemp plugin if plugin_options["sensor_probe"] == 1 and sensors.count( ) > 0: sensor_on = sensors.get( int(plugin_options['probe_A_on_sens'])) # pool if sensor_on.sens_type == 5: # temperature sensor ds_a_on = self._try_read(sensor_on.last_read_value) elif sensor_on.sens_type == 6 and sensor_on.multi_type == 0: # multitemperature sensor DS1 ds_a_on = self._try_read( sensor_on.last_read_value[0]) elif sensor_on.sens_type == 6 and sensor_on.multi_type == 1: # multitemperature sensor DS2 ds_a_on = self._try_read( sensor_on.last_read_value[1]) elif sensor_on.sens_type == 6 and sensor_on.multi_type == 2: # multitemperature sensor DS3 ds_a_on = self._try_read( sensor_on.last_read_value[2]) elif sensor_on.sens_type == 6 and sensor_on.multi_type == 3: # multitemperature sensor DS4 ds_a_on = self._try_read( sensor_on.last_read_value[3]) else: ds_a_on = -127.0 sensor_off = sensors.get( int(plugin_options['probe_A_off_sens'])) # solar if sensor_off.sens_type == 5: # temperature sensor ds_a_off = self._try_read( sensor_off.last_read_value) elif sensor_off.sens_type == 6 and sensor_off.multi_type == 0: # multitemperature sensor DS1 ds_a_off = self._try_read( sensor_off.last_read_value[0]) elif sensor_off.sens_type == 6 and sensor_off.multi_type == 1: # multitemperature sensor DS2 ds_a_off = self._try_read( sensor_off.last_read_value[1]) elif sensor_off.sens_type == 6 and sensor_off.multi_type == 2: # multitemperature sensor DS3 ds_a_off = self._try_read( sensor_off.last_read_value[2]) elif sensor_off.sens_type == 6 and sensor_off.multi_type == 3: # multitemperature sensor DS4 ds_a_off = self._try_read( sensor_off.last_read_value[3]) else: ds_a_off = -127.0 elif plugin_options["sensor_probe"] == 2: ds_a_on = temperature_ds[ plugin_options['probe_A_on']] # pool ds_a_off = temperature_ds[ plugin_options['probe_A_off']] # solar station_a = stations.get( plugin_options['control_output_A']) # only for testing... without airtemp plugin or sensors #ds_a_on = 15 #ds_a_off = 25 probes_ok = True if ds_a_on == -127.0 or ds_a_off == -127.0: probes_ok = False a_state = -2 # The station switches off if the sensors has a fault sid = station_a.index active = log.active_runs() for interval in active: if interval['station'] == sid: stations.deactivate(sid) log.finish_run(interval) regulation_text = datetime_string() + ' ' + _( 'Regulation set OFF.') + ' ' + ' (' + _( 'Output') + ' ' + str(station_a.index + 1) + ').' log.clear(NAME) log.info(NAME, regulation_text) # release msg_a_on and msg_a_off to true for future regulation (after probes is ok) msg_a_on = True msg_a_off = True if (ds_a_off - ds_a_on ) > plugin_options['temp_a_on'] and probes_ok: # ON a_state = 1 if msg_a_on: msg_a_on = False msg_a_off = True regulation_text = datetime_string() + ' ' + _( 'Regulation set ON.') + ' ' + ' (' + _( 'Output') + ' ' + str(station_a.index + 1) + ').' log.clear(NAME) log.info(NAME, regulation_text) start = datetime.datetime.now() sid = station_a.index end = datetime.datetime.now() + datetime.timedelta( seconds=plugin_options['reg_ss'], minutes=plugin_options['reg_mm']) new_schedule = { 'active': True, 'program': -1, 'station': sid, 'program_name': _(u'Pool Heating'), 'fixed': True, 'cut_off': 0, 'manual': True, 'blocked': False, 'start': start, 'original_start': start, 'end': end, 'uid': '%s-%s-%d' % (str(start), "Manual", sid), 'usage': stations.get(sid).usage } log.start_run(new_schedule) stations.activate(new_schedule['station']) if plugin_options[ 'enabled_safety']: # safety check safety_end = datetime.datetime.now( ) + datetime.timedelta( minutes=plugin_options['safety_mm']) if (ds_a_off - ds_a_on ) < plugin_options['temp_a_off'] and probes_ok: # OFF a_state = 0 if msg_a_off: msg_a_off = False msg_a_on = True regulation_text = datetime_string() + ' ' + _( 'Regulation set OFF.') + ' ' + ' (' + _( 'Output') + ' ' + str(station_a.index + 1) + ').' log.clear(NAME) log.info(NAME, regulation_text) sid = station_a.index stations.deactivate(sid) active = log.active_runs() for interval in active: if interval['station'] == sid: log.finish_run(interval) if plugin_options[ 'enabled_safety']: # safety check safety_end = datetime.datetime.now( ) + datetime.timedelta( minutes=plugin_options['safety_mm']) ### if "pool" end in schedule release msg_a_on to true in regulation for next scheduling ### now = datetime.datetime.now() if now > end: msg_a_off = False msg_a_on = True if probes_ok: a_state = -3 if plugin_options['enabled_safety']: # safety check safety_start = datetime.datetime.now() if safety_start > safety_end and probes_ok: # is time for check if (ds_a_off - ds_a_on) > plugin_options[ 'temp_safety']: # temperature difference is bigger a_state = -4 msg_a_off = False msg_a_on = True regulation_text = datetime_string() + ' ' + _( 'Safety shutdown!' ) + ' ' + ' (' + _('Output') + ' ' + str( station_a.index + 1) + ').\n' + _('Regulation disabled!') log.clear(NAME) log.info(NAME, regulation_text) sid = station_a.index stations.deactivate(sid) active = log.active_runs() for interval in active: # stop stations if interval['station'] == sid: log.finish_run(interval) send = True # send e-mail plugin_options[ 'enabled_a'] = False # disabling plugin else: if a_state != -4: # if safety error not print waiting also safety shutdown! a_state = -1 # footer text tempText = ' ' if a_state == 0: tempText += regulation_text if a_state == 1: tempText += regulation_text if a_state == -1: tempText = _( 'Waiting (not enabled regulation in options, or not selected input).' ) if a_state == -2: tempText = _( 'Some probe shows a fault, regulation is blocked!') if a_state == -3: tempText = _('Waiting.') if a_state == -4: tempText = _('Safety shutdown!') if plugin_options['use_footer']: if temp_sw is not None: temp_sw.val = tempText.encode('utf8').decode( 'utf8') # value on footer self._sleep(2) millis = int(round(time.time() * 1000)) if (millis - last_millis ) > 5000: # 5 second to clearing status on the webpage last_millis = millis log.clear(NAME) if plugin_options["sensor_probe"] == 1: try: if options.temp_unit == 'C': log.info( NAME, datetime_string() + '\n' + sensor_on.name + ' (' + _('Pool') + ') %.1f \u2103 \n' % ds_a_on + sensor_off.name + ' (' + _('Solar') + ') %.1f \u2103' % ds_a_off) else: log.info( NAME, datetime_string() + '\n' + sensor_on.name + ' (' + _('Pool') + ') %.1f \u2109 \n' % ds_a_on + sensor_off.name + ' (' + _('Solar') + ') %.1f \u2103' % ds_a_off) except: pass elif plugin_options["sensor_probe"] == 2: log.info( NAME, datetime_string() + '\n' + _('Pool') + u' %.1f \u2103 \n' % ds_a_on + _('Solar') + ' %.1f \u2103' % ds_a_off) if last_text != tempText: log.info(NAME, tempText) last_text = tempText if send: msg = '<b>' + _( 'Pool Heating plug-in' ) + '</b> ' + '<br><p style="color:red;">' + _( 'System detected error: The temperature did not drop when the pump was switched on after the setuped time. Stations set to OFF. Safety shutdown!' ) + '</p>' msglog = _( 'System detected error: The temperature did not drop when the pump was switched on after the setuped time. Stations set to OFF. Safety shutdown!' ) send = False try: try_mail = None if plugin_options['eplug'] == 0: # email_notifications from plugins.email_notifications import try_mail if plugin_options[ 'eplug'] == 1: # email_notifications SSL from plugins.email_notifications_ssl import try_mail if try_mail is not None: try_mail( msg, msglog, attachment=None, subject=plugin_options['emlsubject'] ) # try_mail(text, logtext, attachment=None, subject=None) except Exception: log.error( NAME, _('Pool Heating plug-in') + ':\n' + traceback.format_exc()) self._sleep(2) except Exception: log.error( NAME, _('Pool Heating plug-in') + ':\n' + traceback.format_exc()) self._sleep(60)
def run(self): last_millis = 0 # timer for save log once_text = True # once_text to mini is auxiliary for blocking two_text = True three_text = True five_text = True six_text = True send = False mini = True sonic_cm = -1 level_in_tank = 0 regulation_text = _(u'Regulation NONE.') if NAME in rain_blocks: del rain_blocks[NAME] self._sleep(2) tank_mon = None if tank_options['use_footer']: tank_mon = showInFooter( ) # instantiate class to enable data in footer tank_mon.button = "tank_monitor/settings" # button redirect on footer tank_mon.label = _(u'Tank') # label on footer end = datetime.datetime.now() avg_lst = [0] * tank_options['avg_samples'] avg_cnt = 0 avg_rdy = False while not self._stop_event.is_set(): try: if tank_options['use_sonic']: if two_text: log.clear(NAME) log.info(NAME, _(u'Water tank monitor is enabled.')) once_text = True two_text = False ping_read = get_sonic_cm() if tank_options[ 'use_avg'] and ping_read > 0: # use averaging try: avg_lst[avg_cnt] = ping_read except: avg_lst.append(ping_read) avg_cnt += 1 if avg_cnt > tank_options['avg_samples']: avg_cnt = 0 avg_rdy = True if avg_rdy: sonic_cm = average_list(avg_lst) level_in_tank = get_sonic_tank_cm(sonic_cm) else: sonic_cm = 0 log.clear(NAME) log.info( NAME, _(u'Waiting for {} samples to be read from the sensor (when using averaging).' ).format(tank_options['avg_samples'])) else: # without averaging if ping_read > 0: # if sonic value is bad (-1) not use these sonic_cm = ping_read level_in_tank = get_sonic_tank_cm(sonic_cm) else: sonic_cm = 0 level_in_tank = 0 tempText = "" if level_in_tank > 0 and sonic_cm != 0: # if level is ok and sonic is ok three_text = True status['level'] = level_in_tank status['ping'] = sonic_cm status['volume'] = get_volume(level_in_tank) status['percent'] = get_tank(level_in_tank) log.clear(NAME) log.info( NAME, datetime_string() + ' ' + _(u'Water level') + ': ' + str(status['level']) + ' ' + _(u'cm') + ' (' + str(status['percent']) + ' ' + (u'%).')) if tank_options['check_liters']: # display in liters tempText = str( status['volume'] ) + ' ' + _(u'liters') + ', ' + str( status['level']) + ' ' + _(u'cm') + ' (' + str( status['percent']) + ' ' + (u'%)') log.info( NAME, _(u'Ping') + ': ' + str(status['ping']) + ' ' + _(u'cm') + ', ' + _(u'Volume') + ': ' + str(status['volume']) + ' ' + _(u'liters') + '.') else: tempText = str( status['volume'] ) + ' ' + _(u'm3') + ', ' + str( status['level']) + ' ' + _(u'cm') + ' (' + str( status['percent']) + ' ' + (u'%)') log.info( NAME, _(u'Ping') + ': ' + str(status['ping']) + ' ' + _(u'cm') + ', ' + _(u'Volume') + ': ' + str(status['volume']) + ' ' + _(u'm3') + '.') log.info( NAME, str(status['maxlevel_datetime']) + ' ' + _(u'Maximum Water level') + ': ' + str(status['maxlevel']) + ' ' + _(u'cm') + '.') log.info( NAME, str(status['minlevel_datetime']) + ' ' + _(u'Minimum Water level') + ': ' + str(status['minlevel']) + ' ' + _(u'cm') + '.') log.info(NAME, regulation_text) if tank_options[ 'enable_reg']: # if enable regulation "maximum water level" reg_station = stations.get( tank_options['reg_output']) if level_in_tank > tank_options[ 'reg_max']: # if actual level in tank > set maximum water level if five_text: five_text = False six_text = True regulation_text = datetime_string( ) + ' ' + _( u'Regulation set ON.' ) + ' ' + ' (' + _(u'Output') + ' ' + str( reg_station.index + 1) + ').' start = datetime.datetime.now() sid = reg_station.index end = datetime.datetime.now( ) + datetime.timedelta( seconds=tank_options['reg_ss'], minutes=tank_options['reg_mm']) new_schedule = { 'active': True, 'program': -1, 'station': sid, 'program_name': _('Tank Monitor'), 'fixed': True, 'cut_off': 0, 'manual': True, 'blocked': False, 'start': start, 'original_start': start, 'end': end, 'uid': '%s-%s-%d' % (str(start), "Manual", sid), 'usage': stations.get(sid).usage } log.start_run(new_schedule) stations.activate(new_schedule['station']) if level_in_tank < tank_options[ 'reg_min']: # if actual level in tank < set minimum water level if six_text: # blocking for once five_text = True six_text = False regulation_text = datetime_string( ) + ' ' + _( u'Regulation set OFF.' ) + ' ' + ' (' + _(u'Output') + ' ' + str( reg_station.index + 1) + ').' sid = reg_station.index stations.deactivate(sid) active = log.active_runs() for interval in active: if interval['station'] == sid: log.finish_run(interval) now = datetime.datetime.now() if now > end: # if program end in schedule release five_text to true in regulation for next scheduling # five_text = True six_text = False regulation_text = datetime_string() + ' ' + _( u'Waiting.') if status['level'] > status[ 'maxlevel']: # maximum level check status['maxlevel'] = status['level'] tank_options.__setitem__('saved_max', status['level']) status['maxlevel_datetime'] = datetime_string() log.info( NAME, datetime_string() + ': ' + _(u'Maximum has updated.')) update_log() if status['level'] < status['minlevel'] and status[ 'level'] > 2: # minimum level check status['minlevel'] = status['level'] tank_options.__setitem__('saved_min', status['level']) status['minlevel_datetime'] = datetime_string() log.info( NAME, datetime_string() + ': ' + _(u'Minimum has updated.')) update_log() if status['level'] <= int( tank_options['water_minimum'] ) and mini and not options.manual_mode and status[ 'level'] > 2: # level value is lower if tank_options[ 'use_send_email']: # if email is enabled send = True # send mini = False if tank_options['use_stop']: # if stop scheduler set_stations_in_scheduler_off() log.info( NAME, datetime_string() + ' ' + _(u'ERROR: Water in Tank') + ' < ' + str(tank_options['water_minimum']) + ' ' + _(u'cm') + _(u'!')) delaytime = int(tank_options['delay_duration']) if delaytime > 0: # if there is no water in the tank and the stations stop, then we set the rain delay for this time for blocking rain_blocks[NAME] = datetime.datetime.now( ) + datetime.timedelta( hours=float(delaytime)) if level_in_tank > int( tank_options['water_minimum'] ) + 5 and not mini: # refresh send email if actual level > options minimum +5 mini = True if NAME in rain_blocks and level_in_tank > int( tank_options['water_minimum']): del rain_blocks[NAME] if tank_options['enable_log']: millis = int(round(time.time() * 1000)) interval = (tank_options['log_interval'] * 60000) if (millis - last_millis) > interval: last_millis = millis update_log() elif level_in_tank == -1 and sonic_cm == 0: # waiting for samples tempText = _('Waiting for samples') else: # error probe tempText = _('FAULT') log.clear(NAME) log.info( NAME, datetime_string() + ' ' + _(u'Water level: Error.')) if tank_options[ 'use_water_err'] and three_text: # if probe has error send email three_text = False log.info( NAME, datetime_string() + ' ' + _(u'ERROR: Water probe has fault?')) msg = '<b>' + _( u'Water Tank Monitor plug-in' ) + '</b> ' + '<br><p style="color:red;">' + _( u'System detected error: Water probe has fault?' ) + '</p>' msglog = _( u'Water Tank Monitor plug-in' ) + ': ' + _( u'System detected error: Water probe has fault?' ) try: from plugins.email_notifications import try_mail try_mail( msg, msglog, attachment=None, subject=tank_options['emlsubject'] ) # try_mail(text, logtext, attachment=None, subject=None) except Exception: log.error( NAME, _(u'Water Tank Monitor plug-in') + ':\n' + traceback.format_exc()) if tank_options['use_water_stop']: if NAME not in rain_blocks: set_stations_in_scheduler_off() delaytime = int(tank_options['delay_duration']) if delaytime > 0: # if probe has fault, then we set the rain delay for this time for blocking rain_blocks[NAME] = datetime.datetime.now( ) + datetime.timedelta( hours=float(delaytime)) if tank_options['enable_reg']: tempText += ', ' + regulation_text if tank_options['use_footer']: if tank_mon is not None: tank_mon.val = tempText.encode('utf8').decode( 'utf8') # value on footer self._sleep(3) else: if once_text: log.clear(NAME) log.info(NAME, _(u'Water tank monitor is disabled.')) once_text = False two_text = True last_level = 0 self._sleep(1) if send: msg = '<b>' + _( u'Water Tank Monitor plug-in' ) + '</b> ' + '<br><p style="color:red;">' + _( u'System detected error: Water Tank has minimum Water Level' ) + ': ' + str(tank_options['water_minimum']) + _( u'cm') + '.\n' + '</p>' msglog = _(u'Water Tank Monitor plug-in') + ': ' + _( u'System detected error: Water Tank has minimum Water Level' ) + ': ' + str( tank_options['water_minimum']) + _(u'cm') + '. ' send = False try: try_mail = None if tank_options['eplug'] == 0: # email_notifications from plugins.email_notifications import try_mail if tank_options[ 'eplug'] == 1: # email_notifications SSL from plugins.email_notifications_ssl import try_mail if try_mail is not None: try_mail( msg, msglog, attachment=None, subject=tank_options['emlsubject'] ) # try_mail(text, logtext, attachment=None, subject=None) except Exception: log.info( NAME, _(u'E-mail not send! The Email Notifications plug-in is not found in OSPy or not correctly setuped.' )) log.error( NAME, _(u'Water Tank Monitor plug-in') + ':\n' + traceback.format_exc()) except Exception: log.clear(NAME) log.error( NAME, _(u'Water Tank Monitor plug-in') + ':\n' + traceback.format_exc()) self._sleep(60)
def run(self): Temperature = 0 Humidity = 0 last_millis = 0 # timer for save log var1 = True # Auxiliary variable for once on var2 = True # Auxiliary variable for once off air_temp = None if plugin_options['use_footer']: air_temp = showInFooter( ) # instantiate class to enable data in footer air_temp.button = "air_temp_humi/settings" # button redirect on footer air_temp.label = _(u'Temperature') # label on footer regulation_text = '' #flow = showOnTimeline() # instantiate class to enable data display #flow.unit = _(u'Liters') #flow.val = 10 #flow.clear while not self._stop_event.is_set(): try: if plugin_options['enabled']: # if plugin is enabled log.clear(NAME) log.info(NAME, datetime_string()) tempText = "" if plugin_options[ 'enable_dht']: # if DHTxx probe is enabled try: result = 1 # 1=ERR_MISSING_DATA if plugin_options['dht_type'] == 0: # DHT11 result = instance.read() if plugin_options['dht_type'] == 1: # DHT22 result = instance22.read() if result.is_valid( ): # 0=ERR_NO_ERROR, 1=ERR_MISSING_DATA, 2=ERR_CRC Temperature = result.temperature Humidity = result.humidity global tempDHT, humiDHT tempDHT = Temperature humiDHT = Humidity except: log.clear(NAME) log.info(NAME, datetime_string()) if plugin_options['dht_type'] == 0: # DHT11 log.info(NAME, _(u'DHT11 data is not valid')) tempText += ' ' + _(u'DHT11 data is not valid') if plugin_options['dht_type'] == 1: # DHT22 log.info(NAME, _(u'DHT22 data is not valid')) tempText += ' ' + _(u'DHT22 data is not valid') if Humidity and Temperature != 0: self.status['temp'] = Temperature self.status['humi'] = Humidity log.info( NAME, _(u'Temperature') + ' ' + _(u'DHT') + ': ' + u'%.1f \u2103' % Temperature) log.info( NAME, _(u'Humidity') + ' ' + _(u'DHT') + ': ' + u'%.1f' % Humidity + ' %RH') tempText += ' ' + _( u'DHT' ) + ': ' + u'%.1f \u2103' % Temperature + ' ' + u'%.1f' % Humidity + ' %RH' + ' ' if plugin_options['enabled_reg']: log.info(NAME, regulation_text) station = stations.get( plugin_options['control_output']) if plugin_options[ 'enabled_reg']: # if regulation is enabled if Humidity > (plugin_options['humidity_on'] + plugin_options['hysteresis'] / 2) and var1 is True: start = datetime.datetime.now() sid = station.index end = datetime.datetime.now( ) + datetime.timedelta( seconds=plugin_options['reg_ss'], minutes=plugin_options['reg_mm']) new_schedule = { 'active': True, 'program': -1, 'station': sid, 'program_name': _('Air Temperature'), 'fixed': True, 'cut_off': 0, 'manual': True, 'blocked': False, 'start': start, 'original_start': start, 'end': end, 'uid': '%s-%s-%d' % (str(start), "Manual", sid), 'usage': stations.get(sid).usage } log.start_run(new_schedule) stations.activate(new_schedule['station']) var1 = False var2 = True self.status['outp'] = 1 regulation_text = datetime_string( ) + ' ' + _( u'Regulation set ON.' ) + ' ' + ' (' + _('Output') + ' ' + str( station.index + 1) + ').' update_log(self.status) if Humidity < (plugin_options['humidity_off'] - plugin_options['hysteresis'] / 2) and var2 is True: sid = station.index stations.deactivate(sid) active = log.active_runs() for interval in active: if interval['station'] == sid: log.finish_run(interval) var1 = True var2 = False self.status['outp'] = 0 regulation_text = datetime_string( ) + ' ' + _( u'Regulation set OFF.' ) + ' ' + ' (' + _('Output') + ' ' + str( station.index + 1) + ').' update_log(self.status) if plugin_options[ 'ds_enabled']: # if in plugin is enabled DS18B20 DS18B20_read_data( ) # get read DS18B20 temperature data to global tempDS[xx] tempText += _(u'DS') + ': ' for i in range(0, plugin_options['ds_used']): self.status['DS%d' % i] = tempDS[i] log.info( NAME, _(u'Temperature') + ' ' + _(u'DS') + str(i + 1) + ' (' + u'%s' % plugin_options['label_ds%d' % i] + '): ' + u'%.1f \u2103' % self.status['DS%d' % i]) tempText += u' %s' % plugin_options[ 'label_ds%d' % i] + u' %.1f \u2103' % self.status['DS%d' % i] if plugin_options['enabled_reg']: tempText += ' ' + regulation_text if plugin_options['use_footer']: if air_temp is not None: if is_python2(): air_temp.val = tempText # value on footer else: air_temp.val = tempText.encode('utf8').decode( 'utf8') # value on footer if plugin_options['enable_log']: # enabled logging millis = int(round(time.time() * 1000)) interval = (plugin_options['log_interval'] * 60000) if (millis - last_millis) > interval: last_millis = millis update_log(self.status) self._sleep(5) except Exception: log.error( NAME, _(u'Air Temperature and Humidity Monitor plug-in') + ':\n' + traceback.format_exc()) self._sleep(60)
def run(self): tempText = '' telegram_ftr = None if plugin_options['use_footer']: telegram_ftr = showInFooter() # instantiate class to enable data in footer telegram_ftr.button = "telegram_bot/settings" # button redirect on footer telegram_ftr.label = _(u'Telegram Bot') # label on footer telegram_bad_import_test = False try: import telegram except: telegram_bad_import_test = True pass if telegram_bad_import_test: log.clear(NAME) log.error(NAME, _(u'Telegram not found, installing. Please wait...')) if is_python2(): # https://pypi.org/project/python-telegram-bot/2.4/ cmd = "sudo pip install python-telegram-bot==2.4" # python 2.7 end telegram support else: cmd = "sudo pip3 install python-telegram-bot --upgrade" # python 3+ proc = subprocess.Popen(cmd,stderr=subprocess.STDOUT,stdout=subprocess.PIPE,shell=True) output = proc.communicate()[0].decode('utf8') log.info(NAME, u'{}'.format(output)) try: import telegram except: telegram_bad_import_test = True pass try: # https://www.toptal.com/python/telegram-bot-tutorial-python if plugin_options['use_plugin'] and plugin_options['botToken'] != "" and not telegram_bad_import_test: log.clear(NAME) self._currentChats = plugin_options['currentChats'] self._lastChatDate = plugin_options['lastChatDate'] self.bot = telegram.Bot(token = plugin_options['botToken']) getbot = self.bot.getMe() info_id = getbot.id plugin_options['botID'] = info_id info_username = getbot.username info_first_name = getbot.first_name log.info(NAME, _(u'Hi connect is OK my ID: {}, User Name: {}, First Name: {}.').format(info_id, info_username, info_first_name)) if plugin_options['use_footer']: tempText = _(u'Hi connect is OK my Name: {}.').format(info_username) if telegram_ftr is not None: telegram_ftr.val = tempText.encode('utf8').decode('utf8') self._announce(_(u'Bot on {} has just started!').format(options.name)) except Exception: exc_type, exc_value, exc_traceback = sys.exc_info() err_string = u"".join(traceback.format_exception(exc_type, exc_value, exc_traceback)) log.error(NAME, _(u'Telegram Bot plug-in') + ':\n' + err_string) if plugin_options['use_footer']: tempText = _(u'Telegram Bot has error, check in plugin status!') if telegram_ftr is not None: telegram_ftr.val = tempText.encode('utf8').decode('utf8') zone_change = signal('zone_change') zone_change.connect(notify_zone_change) while not self._stop_event.is_set() and self.bot is not None: try: updates = self.bot.getUpdates() if updates: for update in updates: if update.message: message = update.message else: message = None if message is not None: chat_date = message.date # time stamp chat_id = message.chat.id # chat ID msg_id = message.message_id # msg ID msg_text = message.text # msg text msg_from = u'{} {}'.format(message.chat.first_name, message.chat.last_name) # from user: first name last name if msg_id != self._lastMsgID and chat_date not in self._lastChatDate: self._lastMsgID = msg_id self._lastChatDate.append(chat_date) plugin_options['lastChatDate'] = chat_date #self._lastChatDate log.clear(NAME) log.info(NAME, _(u'New message: {} ID: {}.').format(msg_text, msg_id)) log.info(NAME, _(u'From: {} ID: {}.').format(msg_from, chat_id)) self._echo(self.bot, update) if msg_text == u'/start': self._botCmd_start_chat(self.bot, update) tempText = _('Last msg: /start') log.info(NAME, tempText) plugin_options['lastChatDate'] = [] elif msg_text == u'/{}'.format(plugin_options['help_cmd']): self._botCmd_help(self.bot, update) tempText = _('Last msg: /{}').format(plugin_options['help_cmd']) log.info(NAME, tempText) elif msg_text == u'/{}'.format(plugin_options['info_cmd']): self._botCmd_info(self.bot, update) tempText = _('Last msg: /{}').format(plugin_options['info_cmd']) log.info(NAME, tempText) elif msg_text == u'/{}'.format(plugin_options['enable_cmd']): self._botCmd_enable(self.bot, update) tempText = _('Last msg: /{}').format(plugin_options['enable_cmd']) log.info(NAME, tempText) elif msg_text == u'/{}'.format(plugin_options['disable_cmd']): self._botCmd_disable(self.bot, update) tempText = _('Last msg: /{}').format(plugin_options['disable_cmd']) log.info(NAME, tempText) elif msg_text == u'/{}'.format(plugin_options['stop_cmd']): self._botCmd_stop(self.bot, update) tempText = _('Last msg: /{}').format(plugin_options['stop_cmd']) log.info(NAME, tempText) elif u'/{}'.format(plugin_options['runOnce_cmd']) in msg_text: runlen = len(u'/{}'.format(plugin_options['runOnce_cmd'])) pgmid = int(msg_text[runlen:]) args = pgmid self._botCmd_runOnce(self.bot, update, args) tempText = _('Last msg: /{} arg: {}').format(plugin_options['runOnce_cmd'], args) log.info(NAME, tempText) elif u'/{}'.format(plugin_options['botID']) in msg_text: self._botCmd_subscribe(self.bot, update) tempText = _('Last msg: /subscribe') log.info(NAME, tempText) else: txt= _('Sorry command "{}" is not supported!').format(msg_text) self.bot.sendMessage(update.message.chat.id, text= txt) log.info(NAME, txt) tempText = txt if plugin_options['use_footer']: if telegram_ftr is not None: telegram_ftr.val = tempText.encode('utf8').decode('utf8') self._sleep(5) except Exception: exc_type, exc_value, exc_traceback = sys.exc_info() err_string = u"".join(traceback.format_exception(exc_type, exc_value, exc_traceback)) log.error(NAME, _(u'Telegram Bot plug-in') + ':\n' + err_string) self._sleep(30)
def run(self): millis = int(round(time_.time() * 1000)) last_millis = millis # timer for save log last_clear_millis = millis # last clear millis for timer last_24h_millis = millis # deleting maximal spead after 24 hour send = False # send email disable_text = True val = 0 en_del_24h = True wind_mon = None if wind_options['use_footer']: wind_mon = showInFooter( ) # instantiate class to enable data in footer wind_mon.label = _(u'Wind Speed') # label on footer wind_mon.val = '---' # value on footer wind_mon.button = "wind_monitor/settings" # button redirect on footer while not self._stop_event.is_set(): try: if wind_options[ 'use_wind_monitor']: # if wind plugin is enabled disable_text = True try: import smbus # for PCF 8583 self.bus = smbus.SMBus( 0 if helpers.get_rpi_revision() == 1 else 1) except ImportError: log.warning(NAME, _(u'Could not import smbus.')) if self.bus is not None: set_counter(self.bus) # set pcf8583 as counter puls = counter(self.bus) # read pulses if puls is not None and puls < 1000: # limiter for maximal pulses from counter (error filter) puls = counter( self.bus) / 10.0 # counter value is value/10sec val = puls / (wind_options['pulses'] * 1.0) val = val * wind_options['metperrot'] self.status['meter'] = round(val * 1.0, 2) self.status['kmeter'] = round(val * 3.6, 2) if self.status['meter'] > self.status['max_meter']: self.status['max_meter'] = self.status['meter'] self.status['log_date_maxspeed'] = datetime_string( ) if wind_options['enable_log_change']: update_log() log.info(NAME, datetime_string()) if wind_options['use_kmh']: log.info( NAME, _(u'Speed') + ': ' + u'%.1f' % round(self.status['meter'] * 3.6, 2) + ' ' + _(u'km/h') + ', ' + _(u'Pulses') + ': ' + u'%s' % puls + ' ' + _(u'pulses/sec')) else: log.info( NAME, _(u'Speed') + ': ' + u'%.1f' % round(self.status['meter'], 2) + ' ' + _(u'm/sec') + ', ' + _(u'Pulses') + ': ' + u'%s' % puls + ' ' + _(u'pulses/sec')) if wind_options['use_kmh']: log.info( NAME, u'%s' % self.status['log_date_maxspeed'] + ' ' + _(u'Maximal speed') + ': ' + u'%s' % round(self.status['max_meter'] * 3.6, 2) + ' ' + _(u'km/h')) else: log.info( NAME, u'%s' % self.status['log_date_maxspeed'] + ' ' + _(u'Maximal speed') + ': ' + u'%s' % round(self.status['max_meter'], 2) + ' ' + _(u'm/sec')) if self.status['meter'] >= 42: log.error( NAME, datetime_string() + ' ' + _(u'Wind speed > 150 km/h (42 m/sec)')) if self.status['meter'] >= int( wind_options['maxspeed'] ): # if wind speed is > options max speed log.clear(NAME) if wind_options[ 'sendeml']: # if enabled send email send = True log.info( NAME, datetime_string() + ' ' + _(u'Sending E-mail with notification.')) if wind_options[ 'stoperr']: # if enabled stoping for running stations in scheduler set_stations_in_scheduler_off( ) # set selected stations to stop in scheduler millis = int(round(time_.time() * 1000)) if wind_options['enable_log']: # if logging interval = (wind_options['log_interval'] * 60000) if (millis - last_millis) >= interval: last_millis = millis update_log() if ( millis - last_clear_millis ) >= 120000: # after 120 second deleting in status screen last_clear_millis = millis log.clear(NAME) if wind_options[ 'delete_max_24h']: # if enable deleting max after 24 hours (86400000 ms) is_interval = True if wind_options[ 'delete_max'] == '1': # after one minute int_ms = 60000 elif wind_options[ 'delete_max'] == '10': # after 10 minutes int_ms = 600000 elif wind_options[ 'delete_max'] == '30': # after 30 minutes int_ms = 1800000 elif wind_options[ 'delete_max'] == '1h': # after one hours int_ms = 3600000 elif wind_options[ 'delete_max'] == '2h': # after two hours int_ms = 7200000 elif wind_options[ 'delete_max'] == '10h': # after 10 hours int_ms = 36000000 elif wind_options[ 'delete_max'] == '24h': # after 24 hours int_ms = 86400000 else: is_interval = False if ( millis - last_24h_millis ) >= int_ms and is_interval: # after xx minutes or hours deleting maximal speed last_24h_millis = millis self.status['meter'] = 0 self.status['kmeter'] = 0 self.status['max_meter'] = 0 self.status[ 'log_date_maxspeed'] = datetime_string() log.info( NAME, datetime_string() + ' ' + _(u'Deleting maximal speed after selected interval.' )) update_log() tempText = "" if wind_options['use_kmh']: tempText += u'%s' % self.status[ 'kmeter'] + ' ' + _(u'km/h') else: tempText += u'%s' % self.status['meter'] + ' ' + _( u'm/s') if wind_options['use_footer']: if wind_mon is not None: wind_mon.val = tempText.encode('utf8').decode( 'utf8') # value on footer else: self._sleep(1) else: if disable_text: log.clear(NAME) log.info(NAME, _(u'Wind speed monitor plug-in is disabled.')) disable_text = False self._sleep(1) if send: msg = '<b>' + _( u'Wind speed monitor plug-in' ) + '</b> ' + '<br><p style="color:red;">' + _( u'System detected error: wind speed monitor. All stations set to OFF. Wind is' ) + ': ' + u'%.1f' % (round( val * 3.6, 2)) + ' ' + _(u'km/h') + '. </p>' msglog = _( u'System detected error: wind speed monitor. All stations set to OFF. Wind is' ) + ': ' + u'%.1f' % (round(val, 2) * 3.6) + ' ' + _(u'km/h') + '.' send = False try: try_mail = None if wind_options['eplug'] == 0: # email_notifications from plugins.email_notifications import try_mail if wind_options[ 'eplug'] == 1: # email_notifications SSL from plugins.email_notifications_ssl import try_mail if try_mail is not None: try_mail( msg, msglog, attachment=None, subject=wind_options['emlsubject'] ) # try_mail(text, logtext, attachment=None, subject=None) except Exception: log.error( NAME, _(u'Wind Speed monitor plug-in') + ':\n' + traceback.format_exc()) except Exception: log.clear(NAME) log.error( NAME, _(u'Wind Speed monitor plug-in') + ':\n' + traceback.format_exc()) self._sleep(60)
def run(self): last_millis = 0 # timer for save log last_test_millis = 0 # timer for testing speed speed_mon = None footText = "" tempText = _('Has not been loaded yet') if speed_options['use_monitor']: new_speeds = get_new_speeds() if speed_options['use_footer']: speed_mon = showInFooter( ) # instantiate class to enable data in footer speed_mon.button = "speed_monitor/settings" # button redirect on footer speed_mon.label = _('Speed') # label on footer speed_mon.val = tempText.encode('utf8').decode( 'utf8') # value on footer if speed_options['use_monitor']: log.clear(NAME) log.info(NAME, tempText) else: tempText = _('Speed monitor is disabled.') while not self._stop_event.is_set(): try: if speed_options['use_monitor']: millis = int(round(time.time() * 1000)) test_interval = (speed_options['test_interval'] * 60000) if (millis - last_test_millis) > test_interval: last_test_millis = millis try: new_speeds = get_new_speeds() tempText = _( 'Ping {} ms, Download {} Mb/s, Upload {} Mb/s' ).format(self.status['ping'], self.status['down'], self.status['up']) except: new_speeds = 0, 0, 0 tempText = _('Cannot be loaded') pass self.status['ping'] = new_speeds[0] # Ping (ms) self.status['down'] = new_speeds[1] # Download (Mb/s) self.status['up'] = new_speeds[2] # Upload (Mb/s) footText = tempText + ' (' + datetime_string() + ' )' log.clear(NAME) log.info(NAME, datetime_string() + '\n' + tempText) if speed_options['enable_log']: interval = (speed_options['log_interval'] * 60000) if (millis - last_millis) > interval: last_millis = millis update_log() if speed_options['use_footer']: if speed_mon is not None: speed_mon.val = footText.encode('utf8').decode( 'utf8') # value on footer self._sleep(1) except Exception: log.clear(NAME) log.error( NAME, _('Speed Monitor plug-in') + ':\n' + traceback.format_exc()) self._sleep(60)
def run(self): reboot_time = False once = True once_two = True once_three = True last_time = int(time.time()) ups_mon = None if ups_options['use_footer']: ups_mon = showInFooter() # instantiate class to enable data in footer ups_mon.button = "ups_adj/settings" # button redirect on footer ups_mon.label = _(u'UPS') # label on footer while not self._stop_event.is_set(): try: if ups_options['ups']: # if ups plugin is enabled test = get_check_power() if not test: text = _(u'OK') else: text = _(u'FAULT') self.status['power%d'] = text if ups_options['use_footer']: if ups_mon is not None: ups_mon.val = text.encode('utf8').decode('utf8') # value on footer if not test: last_time = int(time.time()) if test: # if power line is not active reboot_time = True # start countdown timer if once: # send email with info power line fault msg = '<b>' + _(u'UPS plug-in') + '</b> ' + '<br><p style="color:red;">' + _(u'Detected fault on power line.') + '</p>' msglog = _(u'UPS plug-in') + ': ' + _(u'Detected fault on power line.') log.info(NAME, msglog) if ups_options['sendeml']: # if enabled send email try: try_mail = None if ups_options['eplug']==0: # email_notifications from plugins.email_notifications import try_mail if ups_options['eplug']==1: # email_notifications SSL from plugins.email_notifications_ssl import try_mail if try_mail is not None: try_mail(msg, msglog, attachment=None, subject=ups_options['emlsubject']) # try_mail(text, logtext, attachment=None, subject=None) except Exception: log.error(NAME, _(u'UPS plug-in') + ':\n' + traceback.format_exc()) once_three = True if ups_options['enable_log']: update_log(0) once = False if reboot_time and test: count_val = int(ups_options['time']) * 60 # value for countdown actual_time = int(time.time()) log.clear(NAME) log.info(NAME, _(u'Time to shutdown') + ': ' + str(count_val - (actual_time - last_time)) + ' ' + _(u'sec')) if ((actual_time - last_time) >= count_val): # if countdown is 0 last_time = actual_time test = get_check_power() if test: # if power line is current not active log.clear(NAME) log.info(NAME, _(u'Power line is not restore in time -> sends email and shutdown system.')) reboot_time = False if ups_options['sendeml']: # if enabled send email if once_two: # send email with info shutdown system msg = '<b>' + _(u'UPS plug-in') + '</b> ' + '<br><p style="color:red;">' + _(u'Power line is not restore in time -> shutdown system!') + '</p>' msglog = _(u'UPS plug-in') + ': ' + _(u'Power line is not restore in time -> shutdown system!') try: try_mail = None if ups_options['eplug']==0: # email_notifications from plugins.email_notifications import try_mail if ups_options['eplug']==1: # email_notifications SSL from plugins.email_notifications_ssl import try_mail if try_mail is not None: try_mail(msg, msglog, attachment=None, subject=ups_options['emlsubject']) # try_mail(text, logtext, attachment=None, subject=None) except Exception: log.error(NAME, _(u'UPS plug-in') + ':\n' + traceback.format_exc()) once_two = False GPIO.output(pin_ups_down, GPIO.HIGH) # switch on GPIO fo countdown UPS battery power off self._sleep(4) GPIO.output(pin_ups_down, GPIO.LOW) poweroff(1, True) # shutdown system if not test: if once_three: if ups_options['sendeml']: # if enabled send email msg = '<b>' + _(u'UPS plug-in') + '</b> ' + '<br><p style="color:green;">' + _(u'Power line has restored - OK.') + '</p>' msglog = _(u'UPS plug-in') + ': ' + _(u'Power line has restored - OK.') log.clear(NAME) log.info(NAME, msglog) try: try_mail = None if ups_options['eplug']==0: # email_notifications from plugins.email_notifications import try_mail if ups_options['eplug']==1: # email_notifications SSL from plugins.email_notifications_ssl import try_mail if try_mail is not None: try_mail(msg, msglog, attachment=None, subject=ups_options['emlsubject']) # try_mail(text, logtext, attachment=None, subject=None) except Exception: log.error(NAME, _(u'UPS plug-in') + ':\n' + traceback.format_exc()) once = True once_two = True once_three = False if ups_options['enable_log']: update_log(1) self._sleep(2) except Exception: log.error(NAME, _(u'UPS plug-in') + ': \n' + traceback.format_exc()) self._sleep(60)
def run(self): temperature_ds = [-127, -127, -127, -127, -127, -127] msg_a_on = True msg_a_off = True msg_b_on = True msg_b_off = True msg_c_on = True msg_c_off = True temp_sw = None if plugin_options['use_footer']: temp_sw = showInFooter( ) # instantiate class to enable data in footer temp_sw.button = "temperature_switch/settings" # button redirect on footer temp_sw.label = _(u'Temperature Switch') # label on footer millis = int(round( time.time() * 1000)) # timer for clearing status on the web pages after 60 sec last_millis = millis a_state = -1 # for state in footer (-1 disable regulation A, 0 = Aoff, 1 = Aon) b_state = -1 c_state = -1 helper_text = '' while not self._stop_event.is_set(): try: try: from plugins.air_temp_humi import plugin_options as air_temp_data plugin_options['ds_name_0'] = air_temp_data['label_ds0'] plugin_options['ds_name_1'] = air_temp_data['label_ds1'] plugin_options['ds_name_2'] = air_temp_data['label_ds2'] plugin_options['ds_name_3'] = air_temp_data['label_ds3'] plugin_options['ds_name_4'] = air_temp_data['label_ds4'] plugin_options['ds_name_5'] = air_temp_data['label_ds5'] plugin_options['ds_count'] = air_temp_data['ds_used'] from plugins.air_temp_humi import DS18B20_read_probe temperature_ds = [ DS18B20_read_probe(0), DS18B20_read_probe(1), DS18B20_read_probe(2), DS18B20_read_probe(3), DS18B20_read_probe(4), DS18B20_read_probe(5) ] except: log.error( NAME, _(u'Unable to load settings from Air Temperature and Humidity Monitor plugin! Is the plugin Air Temperature and Humidity Monitor installed and set up?' )) self._sleep(60) # regulation A if plugin_options['enabled_a']: ds_a_on = temperature_ds[plugin_options['probe_A_on']] ds_a_off = temperature_ds[plugin_options['probe_A_off']] station_a = stations.get( plugin_options['control_output_A']) if ds_a_on > plugin_options[ 'temp_a_on']: # if DSxx > temperature AON a_state = 1 if msg_a_on: msg_a_on = False msg_a_off = True log.info( NAME, datetime_string() + ' ' + u'%s' % station_a.name + ' ' + _(u'was turned on.')) start = datetime.datetime.now() sid = station_a.index end = datetime.datetime.now() + datetime.timedelta( seconds=plugin_options['reg_ss_a'], minutes=plugin_options['reg_mm_a']) new_schedule = { 'active': True, 'program': -1, 'station': sid, 'program_name': _('Temperature Switch A'), 'fixed': True, 'cut_off': 0, 'manual': True, 'blocked': False, 'start': start, 'original_start': start, 'end': end, 'uid': '%s-%s-%d' % (str(start), "Manual", sid), 'usage': stations.get(sid).usage } log.start_run(new_schedule) stations.activate(new_schedule['station']) if ds_a_off < plugin_options[ 'temp_a_off']: # if DSxx < temperature AOFF a_state = 0 if msg_a_off: msg_a_off = False msg_a_on = True log.info( NAME, datetime_string() + ' ' + u'%s' % station_a.name + ' ' + _(u'was turned off.')) sid = station_a.index stations.deactivate(sid) active = log.active_runs() for interval in active: if interval['station'] == sid: log.finish_run(interval) else: a_state = -1 # regulation B if plugin_options['enabled_b']: ds_b_on = temperature_ds[plugin_options['probe_B_on']] ds_b_off = temperature_ds[plugin_options['probe_B_off']] station_b = stations.get( plugin_options['control_output_B']) if ds_b_on > plugin_options[ 'temp_b_on']: # if DSxx > temperature BON b_state = 1 if msg_b_on: msg_b_on = False msg_b_off = True log.info( NAME, datetime_string() + ' ' + u'%s' % station_b.name + ' ' + _(u'was turned on.')) start = datetime.datetime.now() sid = station_b.index end = datetime.datetime.now() + datetime.timedelta( seconds=plugin_options['reg_ss_b'], minutes=plugin_options['reg_mm_b']) new_schedule = { 'active': True, 'program': -1, 'station': sid, 'program_name': _('Temperature Switch B'), 'fixed': True, 'cut_off': 0, 'manual': True, 'blocked': False, 'start': start, 'original_start': start, 'end': end, 'uid': '%s-%s-%d' % (str(start), "Manual", sid), 'usage': stations.get(sid).usage } log.start_run(new_schedule) stations.activate(new_schedule['station']) if ds_b_off < plugin_options[ 'temp_b_off']: # if DSxx < temperature BOFF b_state = 0 if msg_b_off: msg_b_off = False msg_b_on = True log.info( NAME, datetime_string() + ' ' + u'%s' % station_b.name + ' ' + _(u'was turned off.')) sid = station_b.index stations.deactivate(sid) active = log.active_runs() for interval in active: if interval['station'] == sid: log.finish_run(interval) else: b_state = -1 # regulation C if plugin_options['enabled_c']: ds_c_on = temperature_ds[plugin_options['probe_C_on']] ds_c_off = temperature_ds[plugin_options['probe_C_off']] station_c = stations.get( plugin_options['control_output_C']) if ds_c_on > plugin_options[ 'temp_c_on']: # if DSxx > temperature CON c_state = 1 if msg_c_on: msg_c_on = False msg_c_off = True log.info( NAME, datetime_string() + ' ' + u'%s' % station_c.name + ' ' + _(u'was turned on.')) start = datetime.datetime.now() sid = station_c.index end = datetime.datetime.now() + datetime.timedelta( seconds=plugin_options['reg_ss_c'], minutes=plugin_options['reg_mm_c']) new_schedule = { 'active': True, 'program': -1, 'station': sid, 'program_name': _('Temperature Switch C'), 'fixed': True, 'cut_off': 0, 'manual': True, 'blocked': False, 'start': start, 'original_start': start, 'end': end, 'uid': '%s-%s-%d' % (str(start), "Manual", sid), 'usage': stations.get(sid).usage } log.start_run(new_schedule) stations.activate(new_schedule['station']) if ds_c_off < plugin_options[ 'temp_c_off']: # if DSxx < temperature COFF c_state = 0 if msg_c_off: msg_c_off = False msg_c_on = True log.info( NAME, datetime_string() + ' ' + u'%s' % station_c.name + ' ' + _(u'was turned off.')) sid = station_c.index stations.deactivate(sid) active = log.active_runs() for interval in active: if interval['station'] == sid: log.finish_run(interval) else: c_state = -1 # footer text tempText = ' ' if a_state == 0: tempText += _(u'Regulation A set OFF') + '. ' if a_state == 1: tempText += _(u'Regulation A set ON') + '. ' if b_state == 0: tempText += ' ' + _(u'Regulation B set OFF') + '. ' if b_state == 1: tempText += ' ' + _(u'Regulation B set ON') + '. ' if c_state == 0: tempText += ' ' + _(u'Regulation C set OFF') + '. ' if c_state == 1: tempText += ' ' + _(u'Regulation C set ON') + '. ' if (a_state == -1) and (b_state == -1) and (c_state == -1): tempText = _(u'No change') + '. ' if plugin_options['use_footer']: if temp_sw is not None: if tempText != helper_text: temp_sw.val = tempText.encode('utf8').decode( 'utf8') # value on footer helper_text = tempText self._sleep(2) millis = int(round(time.time() * 1000)) if (millis - last_millis ) > 60000: # 60 second to clearing status on the webpage last_millis = millis log.clear(NAME) except Exception: log.error( NAME, _(u'Temperature Switch plug-in') + ':\n' + traceback.format_exc()) self._sleep(60)