Ejemplo n.º 1
0
def get_first_calibrate_measure(scale, scale_settings_table,
                                calibrate_scale_key):
    try:
        # scale.setReferenceUnit(1)
        scale.setReferenceUnit(
            pi_ager_database.get_table_value(scale_settings_table,
                                             pi_ager_names.referenceunit_key))
        scale.setSamples(
            int(
                pi_ager_database.get_table_value(
                    pi_ager_names.config_settings_table,
                    pi_ager_names.samples_refunit_tara_key)))
        scale.setSpikes(
            int(
                pi_ager_database.get_table_value(
                    pi_ager_names.config_settings_table,
                    pi_ager_names.spikes_refunit_tara_key)))
        # scale.reset()
        # scale.tare()
        clear_history = scale.getWeight()
        calibrate_value_before_weight = scale.getMeasure()
        pi_ager_database.write_current_value(calibrate_scale_key, 2)
        scale.setSamples(
            int(
                pi_ager_database.get_table_value(scale_settings_table,
                                                 pi_ager_names.samples_key)))
        scale.setSpikes(
            int(
                pi_ager_database.get_table_value(scale_settings_table,
                                                 pi_ager_names.spikes_key)))
    except Exception as cx_error:
        cl_fact_logic_messenger().get_instance().handle_exception(cx_error)
        calibrate_value_before_weight = 0
    return calibrate_value_before_weight
Ejemplo n.º 2
0
def tara_scale(scale, tara_key, data_table, calibrate_key, offset,
               settings_table):
    cl_fact_logger.get_instance().debug('performing tara')
    try:
        #scale.reset()
        #scale.tare()

        pi_ager_database.update_value_in_table(
            settings_table, pi_ager_names.offset_scale_key,
            0)  # set offset to zero to get right offset value
        offset = 0

        scale.setSamples(
            int(
                pi_ager_database.get_table_value(
                    pi_ager_names.config_settings_table,
                    pi_ager_names.samples_refunit_tara_key)))
        scale.setSpikes(
            int(
                pi_ager_database.get_table_value(
                    pi_ager_names.config_settings_table,
                    pi_ager_names.spikes_refunit_tara_key)))

        clear_history = scale.getWeight()  # delete values out of history

        tara_measuring_endtime = pi_ager_database.get_current_time() + 1
        pi_ager_database.update_value_in_table(
            pi_ager_names.current_values_table, tara_key, 2)

        newoffset = scale_measures(scale, tara_measuring_endtime, data_table,
                                   1, tara_key, calibrate_key, offset,
                                   settings_table)
        pi_ager_database.update_value_in_table(settings_table,
                                               pi_ager_names.offset_scale_key,
                                               newoffset)
        pi_ager_database.write_stop_in_database(tara_key)

        scale.setSamples(
            int(
                pi_ager_database.get_table_value(settings_table,
                                                 pi_ager_names.samples_key)))
        scale.setSpikes(
            int(
                pi_ager_database.get_table_value(settings_table,
                                                 pi_ager_names.spikes_key)))

        cl_fact_logger.get_instance().debug(
            'tara performed - runnig control-measurement')
        # im Anschluss eine Kontrollmessung machen
        scale_measures(scale, tara_measuring_endtime, data_table, 1, tara_key,
                       calibrate_key, newoffset, settings_table)
    except Exception as cx_error:
        cl_fact_logic_messenger().get_instance().handle_exception(cx_error)
Ejemplo n.º 3
0
def set_language():
    """
    setting up language
    """
    # global logger

    # logger.debug('set_language()')
    cl_fact_logger.get_instance().debug('set_language()')
    # Sprache der Textausgabe
    language = pi_ager_database.get_table_value(
        pi_ager_names.config_settings_table, pi_ager_names.language_key)

    ####   Set up message catalog access
    # translation = gettext.translation('pi_ager', '/var/www/locale', fallback=True)
    # _ = translation.ugettext

    if language == 1:
        translation = gettext.translation('pi_ager',
                                          '/var/www/locale',
                                          languages=['en'],
                                          fallback=True)
    elif language == 2:
        translation = gettext.translation('pi_ager',
                                          '/var/www/locale',
                                          languages=['de'],
                                          fallback=True)

    translation.install()
Ejemplo n.º 4
0
def continue_after_power_failure(current_dictionary):
    """
    after power failure, this function is performed to analyze states and failure values
    """
    failure_temperature_delta = pi_ager_database.get_table_value(
        pi_ager_names.config_settings_table, pi_ager_names.
        failure_temperature_delta_key)  # Maximaler Temperatur-Unterschied
    failure_humidity_delta = pi_ager_database.get_table_value(
        pi_ager_names.config_settings_table, pi_ager_names.
        failure_humidity_delta_key)  # Maximaler Feuchte-Unterschied
    period = pi_ager_database.get_table_value(
        pi_ager_names.current_values_table,
        pi_ager_names.agingtable_period_key)  # setzt periodenzaehler

    temperature_last_change = 0
    current_time = pi_ager_database.get_current_time()

    current_temperature = pi_ager_database.get_table_value(
        pi_ager_names.current_values_table,
        pi_ager_names.sensor_temperature_key)
    current_humidity = pi_ager_database.get_table_value(
        pi_ager_names.current_values_table, pi_ager_names.sensor_humidity_key)

    agingtable_temperature = current_dictionary[
        pi_ager_names.agingtable_setpoint_temperature_field]
    if agingtable_temperature == None:
        agingtable_temperature = pi_ager_database.get_table_value(
            pi_ager_names.config_settings_table,
            pi_ager_names.setpoint_temperature_key)

    agingtable_humidity = current_dictionary[
        pi_ager_names.agingtable_setpoint_humidity_field]
    if agingtable_humidity == None:
        agingtable_humidity = pi_ager_database.get_table_value(
            pi_ager_names.config_settings_table,
            pi_ager_names.setpoint_humidity_key)

    cl_fact_logger.get_instance().info(
        _('current period') + ': ' + str(int(period)))
    cl_fact_logger.get_instance().info(
        'agingtable continues after power failure')
    cl_fact_logger.get_instance().debug(current_dictionary)
    cl_fact_logger.get_instance().debug(
        'current_temperature - agingtable_temperature: ' +
        str(abs(current_temperature - agingtable_temperature)))
    cl_fact_logger.get_instance().debug('failure_temperature_delta: ' +
                                        str(failure_temperature_delta))
    cl_fact_logger.get_instance().debug(
        'current_humidity - agingtable_humidity: ' +
        str(abs(current_humidity - agingtable_humidity)))
    cl_fact_logger.get_instance().debug('failure_humidity_delta: ' +
                                        str(failure_humidity_delta))

    if abs(current_temperature -
           agingtable_temperature) > failure_temperature_delta or abs(
               current_humidity -
               agingtable_humidity) > failure_humidity_delta:
        return False
    else:
        return True
def autostart_loop():
    """
    starting loop. pi is startet. pi-ager is not startet. waiting for value 1 in database pi-ager-status
    """
    global status_pi_ager
    global logger
    
    while True:
        status_pi_ager = pi_ager_database.get_table_value(pi_ager_names.current_values_table, pi_ager_names.status_pi_ager_key)
        status_agingtable = pi_ager_database.get_table_value(pi_ager_names.current_values_table, pi_ager_names.status_agingtable_key)
        current_agingtable_period = pi_ager_database.get_table_value(pi_ager_names.current_values_table, pi_ager_names.agingtable_period_key)
        check_and_set_light()
        
        logger.debug('autostart_loop ' + time.strftime('%H:%M:%S', time.localtime()))
        if status_agingtable == 1:
            os.system('sudo /var/sudowebscript.sh startagingtable &')
            doMainLoop()
        elif status_pi_ager == 1:
            doMainLoop()
        pi_ager_logging.check_website_logfile()
        time.sleep(5)
Ejemplo n.º 6
0
def scale_measures(scale, scale_measuring_endtime, data_table, saving_period,
                   tara_key, calibrate_scale_key, offset, settings_table):
    cl_fact_logger.get_instance().debug('scale_measures()')
    try:
        measure_start_time = pi_ager_database.get_current_time()

        save_time = 0
        current_time = measure_start_time
        while current_time <= int(scale_measuring_endtime):
            calibrate_scale = pi_ager_database.get_table_value(
                pi_ager_names.current_values_table, calibrate_scale_key)
            if calibrate_scale != 0:
                scale_measuring_endtime = current_time
            status_tara_scale = pi_ager_database.get_table_value(
                pi_ager_names.current_values_table, tara_key)
            if status_tara_scale == 1:
                tara_scale(scale, tara_key, data_table, calibrate_scale_key,
                           offset, settings_table)
            value = scale.getMeasure()
            value = value - offset
            if status_tara_scale == 2:
                cl_fact_logger.get_instance().debug(
                    'tara measurement performed')
                return value
            formated_value = round(value, 3)
            if (
                    current_time - measure_start_time
            ) % saving_period == 0 and current_time != save_time:  # speichern je nach datenbankeintrag fuer saving_period
                save_time = current_time
                pi_ager_database.write_scale(data_table, value)
                cl_fact_logger.get_instance().debug(
                    'scale-value saved in database ' +
                    time.strftime('%H:%M:%S', time.localtime()))
            current_time = pi_ager_database.get_current_time()
        cl_fact_logger.get_instance().debug('measurement performed')
    except Exception as cx_error:
        cl_fact_logic_messenger().get_instance().handle_exception(cx_error)
def check_status_agingtable():
    """
    check status of agingtable
    """
    status_agingtable = pi_ager_database.get_table_value(pi_ager_names.current_values_table, pi_ager_names.status_agingtable_key)
    process_agingtable = subprocess.getstatusoutput('ps ax | grep -v grep | grep agingtable.py &')
    # (0, '16114 pts/0    R+     0:01 python3 /opt/pi-ager/agingtable.py\n16238 pts/1    S+     0:00 sudo python3 agingtable.py\n16256 pts/1    R+     0:00 python3 agingtable.py')
    # läuft nicht Exitcode 0
    # (1, '')
    # läuft nicht Exitcode 1
    
    if process_agingtable[1] == '':
        process_agingtable_running = False
    else:
        process_agingtable_running = True
    if status_agingtable == 1 and process_agingtable_running == False:
        os.system('sudo /var/sudowebscript.sh startagingtable &')
Ejemplo n.º 8
0
    def _read_sensor_type(self):
        # logger.debug(cl_fact_logger.get_instance().me())
        cl_fact_logger.get_instance().debug(cl_fact_logger.get_instance().me())
        self._type = int(
            pi_ager_database.get_table_value(
                pi_ager_names.config_settings_table,
                pi_ager_names.sensortype_key))

        # logger.info('Sensor number is: ' + str(self._type))
        cl_fact_logger.get_instance().info('Sensor number is: ' +
                                           str(self._type))
        if self._is_valid() == False:
            raise cx_Sensor_not_defined(self._type_ui)
        self._type_ui = self._get_type_ui()
        # logger.debug("Sensor type is: " + str(self._type_ui))
        cl_fact_logger.get_instance().debug("Sensor type is: " +
                                            str(self._type_ui))
        return ()
Ejemplo n.º 9
0
def set_sensortype():
    """
    setting up sensortype
    """
    global sensor
    global sensortype
    global sensorname
    global sensorvalue
    # global logger

    # logger.debug('set_sensortype()')
    cl_fact_logger.get_instance().debug('set_sensortype()')

    # Sensortyp
    sensortype = pi_ager_database.get_table_value(
        pi_ager_names.config_settings_table, pi_ager_names.sensortype_key)
    sensorname = cl_fact_main_sensor_type.get_instance().get_sensor_type_ui()
    # logger.info(_('sensortype set to') + ' ' + sensorname)
    cl_fact_logger.get_instance().info(
        _('sensortype set to') + ' ' + sensorname)
Ejemplo n.º 10
0
def calculate_reference_unit(scale, calibrate_scale_key, scale_settings_table,
                             calibrate_value_first_measure):
    try:
        # scale.setReferenceUnit(1)
        old_ref_unit = pi_ager_database.get_table_value(
            scale_settings_table, pi_ager_names.referenceunit_key)
        scale.setReferenceUnit(old_ref_unit)
        scale.setSamples(
            int(
                pi_ager_database.get_table_value(
                    pi_ager_names.config_settings_table,
                    pi_ager_names.samples_refunit_tara_key)))
        scale.setSpikes(
            int(
                pi_ager_database.get_table_value(
                    pi_ager_names.config_settings_table,
                    pi_ager_names.spikes_refunit_tara_key)))

        calibrate_weight = pi_ager_database.get_table_value(
            pi_ager_names.current_values_table,
            pi_ager_names.calibrate_weight_key)
        clear_history = scale.getWeight()
        calibrate_value_after_weight = scale.getMeasure()
        reference_unit = (
            calibrate_value_after_weight -
            calibrate_value_first_measure) / calibrate_weight * old_ref_unit
        if reference_unit == 0:
            pi_ager_database.write_current_value(calibrate_scale_key, 5)
        else:
            pi_ager_database.update_value_in_table(
                scale_settings_table, pi_ager_names.referenceunit_key,
                reference_unit)
            scale.setReferenceUnit(reference_unit)
            pi_ager_database.write_current_value(calibrate_scale_key, 4)
        scale.setSamples(
            int(
                pi_ager_database.get_table_value(scale_settings_table,
                                                 pi_ager_names.samples_key)))
        scale.setSpikes(
            int(
                pi_ager_database.get_table_value(scale_settings_table,
                                                 pi_ager_names.spikes_key)))
    except Exception as cx_error:
        cl_fact_logic_messenger().get_instance().handle_exception(cx_error)
Ejemplo n.º 11
0
    translation.install()


def setup_GPIO():
    """
    initialise GPIO's and setting default GPIO's
    """
    pi_ager_gpio_config.setupGPIO()  # GPIO initialisieren
    pi_ager_gpio_config.defaultGPIO()


loopcounter = 0  #  Zaehlt die Durchlaeufe des Mainloops

# Einschalttemperatur
switch_on_cooling_compressor = pi_ager_database.get_table_value(
    pi_ager_names.config_settings_table,
    pi_ager_names.switch_on_cooling_compressor_key)
# Ausschalttemperatur
switch_off_cooling_compressor = pi_ager_database.get_table_value(
    pi_ager_names.config_settings_table,
    pi_ager_names.switch_off_cooling_compressor_key)
# Einschaltfeuchte
switch_on_humidifier = pi_ager_database.get_table_value(
    pi_ager_names.config_settings_table,
    pi_ager_names.switch_on_humidifier_key)
# Ausschaltfeuchte
switch_off_humidifier = pi_ager_database.get_table_value(
    pi_ager_names.config_settings_table,
    pi_ager_names.switch_off_humidifier_key)
# Luftbefeuchtungsverzoegerung
delay_humidify = pi_ager_database.get_table_value(
Ejemplo n.º 12
0
def doAgingtableLoop():
    """
    main function for the agingtable
    """
    global period_settings
    global period_starttime_seconds
    global period_endtime
    global duration_sleep
    global day_in_seconds
    global switch_on_cooling_compressor
    global switch_off_cooling_compressor
    global switch_on_humidifier
    global switch_off_humidifier
    global delay_humidify
    global sensortype

    pi_ager_database.write_start_in_database(
        pi_ager_names.status_agingtable_key)
    status_agingtable = pi_ager_database.get_table_value(
        pi_ager_names.current_values_table,
        pi_ager_names.status_agingtable_key)
    period = pi_ager_database.get_table_value(
        pi_ager_names.current_values_table,
        pi_ager_names.agingtable_period_key)  # setzt periodenzaehler

    period_settings = {}
    # Allgemeingueltige Werte aus Datenbank
    sensortype = pi_ager_database.get_table_value(
        pi_ager_names.config_settings_table, pi_ager_names.sensortype_key)
    language = pi_ager_database.get_table_value(
        pi_ager_names.config_settings_table,
        pi_ager_names.language_key)  # Sprache der Textausgabe
    switch_on_cooling_compressor = pi_ager_database.get_table_value(
        pi_ager_names.config_settings_table,
        pi_ager_names.switch_on_cooling_compressor_key)
    switch_off_cooling_compressor = pi_ager_database.get_table_value(
        pi_ager_names.config_settings_table,
        pi_ager_names.switch_off_cooling_compressor_key)
    switch_on_humidifier = pi_ager_database.get_table_value(
        pi_ager_names.config_settings_table,
        pi_ager_names.switch_on_humidifier_key)
    switch_off_humidifier = pi_ager_database.get_table_value(
        pi_ager_names.config_settings_table,
        pi_ager_names.switch_off_humidifier_key)
    delay_humidify = pi_ager_database.get_table_value(
        pi_ager_names.config_settings_table, pi_ager_names.delay_humidify_key)
    # Reifetabelle aus Datenbank
    agingtable = pi_ager_database.read_agingtable_name_from_config(
    )  # Variable agingtable = Name der Reifetabelle
    agingtable = agingtable.lower()
    finaltime = None
    # bedingte Werte aus Variablen
    # Sensor
    pi_ager_init.set_language()
    # Variablen
    debug_modus = pi_ager_database.get_table_value(
        pi_ager_names.debug_table, pi_ager_names.loglevel_console_key)
    if debug_modus == 10:
        day_in_seconds = pi_ager_database.get_table_value(
            pi_ager_names.debug_table,
            pi_ager_names.agingtable_days_in_seconds_debug_key
        )  # zum testen Wert aus DB holen: ein Tag vergeht in einer Sekunde
    else:
        day_in_seconds = 86400  #Anzahl der Sek. in einem Tag

    # Hauptprogramm

    cl_fact_logger.get_instance().info(pi_ager_names.logspacer)
    logstring = _(
        'the climate values are now controlled by the automatic program'
    ) + ' ' + agingtable
    cl_fact_logger.get_instance().info(logstring)
    rows = pi_ager_database.get_agingtable_as_rows(agingtable)

    row_number = 0  # Setzt Variable row_number auf 0
    total_duration = 0  # Setzt Variable duration auf 0
    dict_agingtable = {}

    for row in rows:
        total_duration += int(row["days"])  # errechnet die Gesamtdauer
        dict_agingtable[row_number] = get_dictionary_out_of_sqliterow(row)

        row_number += 1  # Zeilenanzahl wird hochgezaehlt (fuer Dictionary Nummer und total_periods)

    total_periods = row_number - 1

    cl_fact_logger.get_instance().debug('total duration (days): ' +
                                        str(total_duration))
    cl_fact_logger.get_instance().debug('total periods: ' + str(total_periods))

    # Wenn period = 0 wird die Reifetabelle neu gestartet, ansonsten an der aktuellen period fortgesetzt
    if period == 0:

        # Sprache
        # ####   Set up message catalog access
        # # translation = gettext.translation('pi-ager', '/var/www/locale', fallback=True)
        # # _ = translation.ugettext
        # if language == 1:
        # translation = gettext.translation('pi-ager', '/var/www/locale', languages=['de_DE'], fallback=True)
        # elif language == 2:
        # translation = gettext.translation('pi-ager', '/var/www/locale', languages=['en'], fallback=True)
        # # else:
        # translation.install()
        period_starttime_seconds = 0
        duration_sleep = 0
        actual_dictionary = None  # setzt aktuelles Dictionary zurueck

    elif not continue_after_power_failure(dict_agingtable[period]):

        # To Do: ALARM (Piezo) einfügen
        logstring = 'interruption agingtable' + ' "' + agingtable + '" ' + 'in period ' + str(
            period) + '!!!'
        cl_fact_logger.get_instance().critical(logstring)
        pi_ager_database.write_stop_in_database(
            pi_ager_names.status_agingtable_key)
        status_agingtable = 0
        pi_ager_database.write_current_value(
            pi_ager_names.agingtable_period_key, status_agingtable)

    else:  #Sensorwerte sind im Toleranzbereich, Reifetabelle kann normal fortgesetzt werden
        #eventuell noch Prüfung, ob der Periodenwechsel vor zu langer Zeit hätte stattfinden müssen
        period_starttime_seconds = pi_ager_database.get_table_value(
            pi_ager_names.current_values_table,
            pi_ager_names.agingtable_period_starttime_key)
        actual_dictionary = dict_agingtable[period]
        duration_sleep = get_duration_sleep(int(actual_dictionary['days']))

    while period <= total_periods and status_agingtable == 1:
        time.sleep(1)
        status_agingtable = pi_ager_database.get_table_value(
            pi_ager_names.current_values_table,
            pi_ager_names.status_agingtable_key)
        current_time = pi_ager_database.get_current_time()
        if (period_starttime_seconds == 0 and duration_sleep == 0
                and period == 0
            ) or current_time >= period_starttime_seconds + duration_sleep:
            pi_ager_database.write_current_value(
                pi_ager_names.agingtable_period_key, period)
            cl_fact_logger.get_instance().debug('period' + ': ' + str(period))
            actual_dictionary = dict_agingtable[period]
            if period == 0:
                logstring = _('start values period 1 of') + ' ' + str(
                    total_periods + 1)
                cl_fact_logger.get_instance().info(logstring)
                finaltime = datetime.datetime.now() + datetime.timedelta(
                    days=total_duration
                )  # days = parameter von datetime.timedelta
                read_dictionary_write_settings(actual_dictionary)
                logstring = _(
                    'next change of values') + ': ' + period_endtime.strftime(
                        '%d.%m.%Y  %H:%M')
                cl_fact_logger.get_instance().info(logstring)
                logstring = _('end of program') + ': ' + finaltime.strftime(
                    '%d.%m.%Y  %H:%M')
                cl_fact_logger.get_instance().info(logstring)

            elif period == total_periods:
                logstring = _('new values for period') + ' ' + str(
                    period + 1) + ' ' + _('of') + ' ' + str(total_periods + 1)
                cl_fact_logger.get_instance().info(logstring)
                read_dictionary_write_settings(actual_dictionary)
                logstring = _('Program') + ' "' + agingtable + '" ' + _(
                    'ends the control.') + '\n Pi Ager ' + _(
                        'continues to work with the last values.')
                cl_fact_logger.get_instance().info(logstring)
                # Piezo piepen lassen

            else:
                logstring = _('new values for period') + ' ' + str(
                    period + 1) + ' ' + _('of') + ' ' + str(total_periods + 1)
                cl_fact_logger.get_instance().info(logstring)
                read_dictionary_write_settings(actual_dictionary)
                logstring = _('next change of values') + ': ' + (
                    period_endtime.strftime('%d.%m.%Y  %H:%M'))
                cl_fact_logger.get_instance().info(logstring)

                if finaltime == None:
                    period_starttime = datetime.datetime.fromtimestamp(
                        period_starttime_seconds)
                    finaltime = period_starttime + datetime.timedelta(
                        days=total_duration)
                logstring = _('end of program') + ': ' + finaltime.strftime(
                    '%d.%m.%Y  %H:%M')
                cl_fact_logger.get_instance().info(logstring)
            period += 1
            cl_fact_logger.get_instance().info(pi_ager_names.logspacer)

        elif (period_starttime_seconds + duration_sleep -
              current_time) % 3600 == 0:
            cl_fact_logger.get_instance().info(
                _('in agingtable duration_sleep-loop. duration_sleep left') +
                ': ' +
                str(period_starttime_seconds + duration_sleep - current_time) +
                ' ' + 'seconds')
        else:
            cl_fact_logger.get_instance().debug(
                'in agingtable duration_sleep-loop. duration_sleep left: ' +
                str(period_starttime_seconds + duration_sleep - current_time) +
                ' sec.')

    pi_ager_database.write_stop_in_database(
        pi_ager_names.status_agingtable_key)
    pi_ager_database.write_current_value(pi_ager_names.agingtable_period_key,
                                         0)
    sys.exit(0)
Ejemplo n.º 13
0
def read_dictionary_write_settings(period_dictionary):
    """
    function for writing the settings into the DB
    """
    from sensors.pi_ager_cl_sensor_type import cl_fact_main_sensor_type

    global period_endtime
    global period_starttime_seconds
    global day_in_seconds
    global switch_on_cooling_compressor
    global switch_off_cooling_compressor
    global switch_on_humidifier
    global switch_off_humidifier
    global delay_humidify
    global sensorname
    global sensortype

    cl_fact_logger.get_instance().debug('read_dictionary_write_settings()')

    # Variablen aus Dictionary setzen
    for key, value in iter(period_dictionary.items()):
        if value == None or value == '':  # wenn ein Wert leer ist muss er aus der letzten settings.json ausgelesen  werden
            value = pi_ager_database.get_table_value(
                pi_ager_names.config_settings_table, key)
            period_dictionary[key] = value
        else:
            value = int(value)
            period_dictionary[key] = value

    global duration_sleep
    duration_sleep = get_duration_sleep(
        int(period_dictionary['days'])
    )  # Anzahl der Tage von "column" mit 86400 (Sekunden) multipliziert fuer wartezeit bis zur naechsten Periode

    # Aufbereitung fuer die Lesbarkeit im Logfile und Fuellen der Variablen
    modus = int(
        period_dictionary['modus'] + 0.5
    )  # Rundet auf Ganzzahl, Integer da der Modus immer Integer sein sollte

    #-------Logstring---------
    if modus == 0:
        operating_mode = "\n" + '.................................' + _(
            'operation mode') + ': ' + _('cooling')
    elif modus == 1:
        operating_mode = "\n" + '.................................' + _(
            'operation mode') + ': ' + _('cooling with humidify')
    elif modus == 2:
        operating_mode = "\n" + '.................................' + _(
            'operation mode') + ': ' + _('heating with humidify')
    elif modus == 3:
        operating_mode = "\n" + '.................................' + _(
            'operation mode') + ': ' + _('automatic with humidify')
    elif modus == 4:
        operating_mode = "\n" + '.................................' + _(
            'operation mode') + ': ' + _(
                'automatic with dehumidify and humidify')
    else:
        operating_mode = "\n" + '.................................' + _(
            'operation mode wrong or set incorrectly')

    setpoint_temperature_logstring = "\n" + '.................................' + _(
        'setpoint temperature') + ": " + str(
            period_dictionary['setpoint_temperature']) + " C"
    switch_on_cooling_compressor_logstring = "\n" + '.................................' + _(
        'switch-on value temperature') + ": " + str(
            switch_on_cooling_compressor) + " C"
    switch_off_cooling_compressor_logstring = "\n" + '.................................' + _(
        'switch-off value temperature') + ": " + str(
            switch_off_cooling_compressor) + " C"
    setpoint_humidity_logstring = "\n" + '.................................' + _(
        'setpoint humidity') + ": " + str(
            period_dictionary['setpoint_humidity']) + "%"
    switch_on_humidifier_logstring = "\n" + '.................................' + _(
        'switch-on value humidity') + ": " + str(switch_on_humidifier) + "%"
    switch_off_humidifier_logstring = "\n" + '.................................' + _(
        'switch-off value humidity') + ": " + str(switch_off_humidifier) + "%"
    delay_humidify_logstring = "\n" + '.................................' + _(
        'humidification delay') + ": " + str(delay_humidify) + ' ' + _(
            "minutes")
    circulation_air_period_format = int(
        period_dictionary['circulation_air_period']) / 60
    circulation_air_period_logstring = "\n" + '.................................' + _(
        'timer circulation air period every') + ": " + str(
            circulation_air_period_format) + ' ' + _("minutes")
    circulation_air_duration_format = int(
        period_dictionary['circulation_air_duration']) / 60
    circulation_air_duration_logstring = "\n" + '.................................' + _(
        'timer circulation air') + ": " + str(
            circulation_air_duration_format) + ' ' + _("minutes")
    exhaust_air_period_format = int(
        period_dictionary['exhaust_air_period']) / 60
    exhaust_air_period_logstring = "\n" + '.................................' + _(
        'timer exhaust air period every') + ": " + str(
            exhaust_air_period_format) + ' ' + _("minutes")
    exhaust_air_duration_format = int(
        period_dictionary['exhaust_air_duration']) / 60
    exhaust_air_duration_logstring = "\n" + '.................................' + _(
        'timer exhausting air') + ": " + str(
            exhaust_air_duration_format) + ' ' + _("minutes")
    period_days_logstring = "\n" + '.................................' + _(
        'duration') + ": " + str(period_dictionary['days']) + ' ' + _('days')
    sensor_logstring = '.................................' + _(
        'sensortype') + ": " + cl_fact_main_sensor_type().get_instance(
        )._get_type_ui()

    pi_ager_database.write_settings(
        modus, period_dictionary['setpoint_temperature'],
        period_dictionary['setpoint_humidity'],
        period_dictionary['circulation_air_period'],
        period_dictionary['circulation_air_duration'],
        period_dictionary['exhaust_air_period'],
        period_dictionary['exhaust_air_duration'])

    period_starttime_seconds = pi_ager_database.get_current_time()
    pi_ager_database.write_current_value(
        pi_ager_names.agingtable_period_starttime_key,
        period_starttime_seconds)
    period_endtime = datetime.datetime.now() + datetime.timedelta(
        days=period_dictionary['days']
    )  # days = parameter von datetime.timedelta

    logstring = _(
        'values'
    ) + ': ' + operating_mode + setpoint_temperature_logstring + switch_on_cooling_compressor_logstring + switch_off_cooling_compressor_logstring + "\n" + setpoint_humidity_logstring + switch_on_humidifier_logstring + switch_off_humidifier_logstring + delay_humidify_logstring + "\n" + circulation_air_period_logstring + circulation_air_duration_logstring + "\n" + exhaust_air_period_logstring + exhaust_air_duration_logstring + "\n" + period_days_logstring + "\n" + sensor_logstring + "\n"
    cl_fact_logger.get_instance().info(logstring)
Ejemplo n.º 14
0
def doScaleLoop():

    scale1_settings_table = pi_ager_names.settings_scale1_table
    scale1_table = pi_ager_names.data_scale1_table
    scale2_settings_table = pi_ager_names.settings_scale2_table
    scale2_table = pi_ager_names.data_scale2_table

    scale1_setting_rows = pi_ager_database.get_scale_settings_from_table(
        scale1_settings_table)
    scale2_setting_rows = pi_ager_database.get_scale_settings_from_table(
        scale2_settings_table)

    scale1_settings = get_scale_settings(scale1_setting_rows)
    scale2_settings = get_scale_settings(scale2_setting_rows)

    scale1 = Scale(source=None,
                   samples=int(scale1_settings[pi_ager_names.samples_key]),
                   spikes=int(scale1_settings[pi_ager_names.spikes_key]),
                   sleep=scale1_settings[pi_ager_names.sleep_key],
                   dout=pi_ager_gpio_config.gpio_scale1_data,
                   pd_sck=pi_ager_gpio_config.gpio_scale1_sync,
                   gain=int(scale1_settings[pi_ager_names.gain_key]),
                   bitsToRead=int(
                       scale1_settings[pi_ager_names.bits_to_read_key]))
    scale2 = Scale(source=None,
                   samples=int(scale2_settings[pi_ager_names.samples_key]),
                   spikes=int(scale2_settings[pi_ager_names.spikes_key]),
                   sleep=scale2_settings[pi_ager_names.sleep_key],
                   dout=pi_ager_gpio_config.gpio_scale2_data,
                   pd_sck=pi_ager_gpio_config.gpio_scale2_sync,
                   gain=int(scale2_settings[pi_ager_names.gain_key]),
                   bitsToRead=int(
                       scale2_settings[pi_ager_names.bits_to_read_key]))

    while True:
        try:
            cl_fact_logger.get_instance().debug(
                'doScaleLoop() ' + time.strftime('%H:%M:%S', time.localtime()))
            status_tara_scale1 = pi_ager_database.get_table_value(
                pi_ager_names.current_values_table,
                pi_ager_names.status_tara_scale1_key)
            status_scale1 = pi_ager_database.get_table_value(
                pi_ager_names.current_values_table,
                pi_ager_names.status_scale1_key)
            status_tara_scale2 = pi_ager_database.get_table_value(
                pi_ager_names.current_values_table,
                pi_ager_names.status_tara_scale2_key)
            status_scale2 = pi_ager_database.get_table_value(
                pi_ager_names.current_values_table,
                pi_ager_names.status_scale2_key)
            calibrate_scale1 = pi_ager_database.get_table_value(
                pi_ager_names.current_values_table,
                pi_ager_names.calibrate_scale1_key)
            calibrate_scale2 = pi_ager_database.get_table_value(
                pi_ager_names.current_values_table,
                pi_ager_names.calibrate_scale2_key)
            # scale1.setReferenceUnit(scale1_settings[pi_ager_names.referenceunit_key])
            # scale2.setReferenceUnit(scale2_settings[pi_ager_names.referenceunit_key])

            if status_scale1 == 1 or calibrate_scale1 in [
                    1, 2, 3, 4, 5
            ] or status_tara_scale1 in [1, 2]:

                scale1_measuring_duration = pi_ager_database.get_table_value(
                    pi_ager_names.settings_scale1_table,
                    pi_ager_names.measuring_duration_key)
                saving_period_scale1 = pi_ager_database.get_table_value(
                    pi_ager_names.settings_scale1_table,
                    pi_ager_names.saving_period_key)
                offset_scale1 = pi_ager_database.get_table_value(
                    pi_ager_names.settings_scale1_table,
                    pi_ager_names.offset_scale_key)
                samples_scale1 = int(
                    pi_ager_database.get_table_value(
                        pi_ager_names.settings_scale1_table,
                        pi_ager_names.samples_key))
                spikes_scale1 = int(
                    pi_ager_database.get_table_value(
                        pi_ager_names.settings_scale1_table,
                        pi_ager_names.spikes_key))
                scale1.setReferenceUnit(
                    pi_ager_database.get_table_value(
                        scale1_settings_table,
                        pi_ager_names.referenceunit_key))

                if pi_ager_database.get_table_value(
                        pi_ager_names.debug_table,
                        pi_ager_names.loglevel_console_key) == 10:
                    measuring_interval_scale1 = pi_ager_database.get_table_value(
                        pi_ager_names.debug_table,
                        pi_ager_names.measuring_interval_debug_key)
                else:
                    measuring_interval_scale1 = pi_ager_database.get_table_value(
                        pi_ager_names.settings_scale1_table,
                        pi_ager_names.scale_measuring_interval_key)

                if calibrate_scale1 == 1:
                    first_calibrate_value = get_first_calibrate_measure(
                        scale1, scale1_settings_table,
                        pi_ager_names.calibrate_scale1_key)

                if calibrate_scale1 == 3:
                    calculate_reference_unit(
                        scale1, pi_ager_names.calibrate_scale1_key,
                        pi_ager_names.settings_scale1_table,
                        first_calibrate_value)
                if status_tara_scale1 == 1:
                    tara_scale(scale1, pi_ager_names.status_tara_scale1_key,
                               pi_ager_names.data_scale1_table,
                               pi_ager_names.calibrate_scale1_key,
                               offset_scale1,
                               pi_ager_names.settings_scale1_table)

                if pi_ager_database.get_scale_table_row(scale1_table) != None:
                    last_measure_scale1 = pi_ager_database.get_scale_table_row(
                        scale1_table)[pi_ager_names.last_change_field]
                    time_difference_scale1 = pi_ager_database.get_current_time(
                    ) - last_measure_scale1
                else:
                    time_difference_scale1 = measuring_interval_scale1 + 1
                if time_difference_scale1 >= measuring_interval_scale1:
                    scale1_measuring_endtime = pi_ager_database.get_current_time(
                    ) + scale1_measuring_duration
                    scale_measures(scale1, scale1_measuring_endtime,
                                   pi_ager_names.data_scale1_table,
                                   saving_period_scale1,
                                   pi_ager_names.status_tara_scale1_key,
                                   pi_ager_names.calibrate_scale1_key,
                                   offset_scale1,
                                   pi_ager_names.settings_scale1_table)

            if status_scale2 == 1 or calibrate_scale2 in [
                    1, 2, 3, 4, 5
            ] or status_tara_scale2 in [1, 2]:

                scale2_measuring_duration = pi_ager_database.get_table_value(
                    pi_ager_names.settings_scale2_table,
                    pi_ager_names.measuring_duration_key)
                saving_period_scale2 = pi_ager_database.get_table_value(
                    pi_ager_names.settings_scale2_table,
                    pi_ager_names.saving_period_key)
                offset_scale2 = pi_ager_database.get_table_value(
                    pi_ager_names.settings_scale2_table,
                    pi_ager_names.offset_scale_key)
                samples_scale2 = int(
                    pi_ager_database.get_table_value(
                        pi_ager_names.settings_scale2_table,
                        pi_ager_names.samples_key))
                spikes_scale2 = int(
                    pi_ager_database.get_table_value(
                        pi_ager_names.settings_scale2_table,
                        pi_ager_names.spikes_key))
                scale2.setReferenceUnit(
                    pi_ager_database.get_table_value(
                        scale2_settings_table,
                        pi_ager_names.referenceunit_key))

                if pi_ager_database.get_table_value(
                        pi_ager_names.debug_table,
                        pi_ager_names.loglevel_console_key) == 10:
                    measuring_interval_scale2 = pi_ager_database.get_table_value(
                        pi_ager_names.debug_table,
                        pi_ager_names.measuring_interval_debug_key)
                else:
                    measuring_interval_scale2 = pi_ager_database.get_table_value(
                        pi_ager_names.settings_scale2_table,
                        pi_ager_names.scale_measuring_interval_key)

                if calibrate_scale2 == 1:
                    first_calibrate_value = get_first_calibrate_measure(
                        scale2, scale2_settings_table,
                        pi_ager_names.calibrate_scale2_key)

                if calibrate_scale2 == 3:
                    calculate_reference_unit(
                        scale2, pi_ager_names.calibrate_scale2_key,
                        pi_ager_names.settings_scale2_table,
                        first_calibrate_value)

                if status_tara_scale2 == 1:
                    tara_scale(scale2, pi_ager_names.status_tara_scale2_key,
                               pi_ager_names.data_scale2_table,
                               pi_ager_names.calibrate_scale2_key,
                               offset_scale2,
                               pi_ager_names.settings_scale2_table)

                if pi_ager_database.get_scale_table_row(scale2_table) != None:
                    last_measure_scale2 = pi_ager_database.get_scale_table_row(
                        scale2_table)[pi_ager_names.last_change_field]
                    time_difference_scale2 = pi_ager_database.get_current_time(
                    ) - last_measure_scale2
                else:
                    time_difference_scale2 = measuring_interval_scale2 + 1
                if time_difference_scale2 >= measuring_interval_scale2:
                    scale2_measuring_endtime = pi_ager_database.get_current_time(
                    ) + scale2_measuring_duration
                    scale_measures(scale2, scale2_measuring_endtime,
                                   pi_ager_names.data_scale2_table,
                                   saving_period_scale2,
                                   pi_ager_names.status_tara_scale2_key,
                                   pi_ager_names.calibrate_scale2_key,
                                   offset_scale2,
                                   pi_ager_names.settings_scale2_table)
        except Exception as cx_error:
            cl_fact_logic_messenger().get_instance().handle_exception(cx_error)
            pass

        time.sleep(2)
def get_sensordata(sht_exception_count, humidity_exception_count, temperature_exception_count, sensordata_exception_count):
    """
    try to read sensordata
    """
    global logger
    
    if pi_ager_init.sensorname == 'DHT11' or pi_ager_init.sensorname == 'DHT22':
        sensor_humidity_big, sensor_temperature_big = Adafruit_DHT.read_retry(pi_ager_init.sensor, pi_ager_names.gpio_sensor_data)
        logger.debug("sensor_temperature: " + str(sensor_temperature_big))
        logger.debug("sensor_humidity_big: " + str(sensor_humidity_big))
        # atp = 17.271  ermittelt aus dem Datenblatt DHT11 und DHT22
        # btp = 237.7   ermittelt aus dem Datenblatt DHT11 und DHT22
    
    elif pi_ager_init.sensorname == 'SHT': #SHT
        try:
            sensor_sht = pi_sht1x.SHT1x(pi_ager_names.gpio_sensor_data, pi_ager_names.gpio_sensor_sync, gpio_mode=pi_ager_names.board_mode)
            sensor_sht.read_temperature()
            sensor_sht.read_humidity()
            sensor_temperature_big = sensor_sht.temperature_celsius
            sensor_humidity_big = sensor_sht.humidity
            logger.debug('sensor_temperature_big: ' + str(sensor_temperature_big))
            logger.debug('sensor_humidity_big: ' + str(sensor_humidity_big))
        except SHT1xError:
            if sht_exception_count < 10:
                countup_values = countup('sht_exception', sht_exception_count)
                logstring = countup_values['logstring']
                sht_exception_count = countup_values['counter']
                logger.debug(logstring)
                time.sleep(1)
                recursion = get_sensordata(sht_exception_count, humidity_exception_count, temperature_exception_count, sensordata_exception_count)
                return recursion
            else:
                pass

    if sensor_humidity_big is not None and sensor_temperature_big is not None:
        sensor_temperature = round (sensor_temperature_big,2)
        sensor_humidity = round (sensor_humidity_big,2)
        last_temperature = pi_ager_database.get_table_value(pi_ager_names.current_values_table, pi_ager_names.sensor_temperature_key)
        last_humidity = pi_ager_database.get_table_value(pi_ager_names.current_values_table, pi_ager_names.sensor_humidity_key)
        deviation_temperature = abs((sensor_temperature/last_temperature * 100) - 100)
        deviation_humidity = abs((sensor_humidity/last_humidity * 100) - 100)
        
        if sensor_humidity > 100 or deviation_humidity > 20:
            if humidity_exception_count < 10:
                countup_values = countup('humidity_exception', humidity_exception_count)
                logstring = countup_values['logstring']
                humidity_exception_count = countup_values['counter']
                logger.debug(logstring)
                time.sleep(1)
                recursion = get_sensordata(sht_exception_count, humidity_exception_count, temperature_exception_count, sensordata_exception_count)
                return recursion
            else:
                pass
        if sensor_temperature > 60 or deviation_temperature > 20:
            if temperature_exception_count < 10:
                countup_values = countup('temperature_exception', temperature_exception_count)
                logstring = countup_values['logstring']
                temperature_exception_count = countup_values['counter']
                logger.debug(logstring)
                time.sleep(1)
                recursion = get_sensordata(sht_exception_count, humidity_exception_count, temperature_exception_count, sensordata_exception_count)
                return recursion
            else:
                pass
                
    elif sensordata_exception_count < 10:
        sensor_temperature = None
        sensor_humidity = None
        countup_values = countup('sensordata_exception', sensordata_exception_count)
        logstring = countup_values['logstring']
        sensordata_exception_count = countup_values['counter']
        
        logger.debug(logstring)
        time.sleep(1)
        recursion = get_sensordata(sht_exception_count, humidity_exception_count, temperature_exception_count, sensordata_exception_count)
        return recursion
    
    else:
        sensor_temperature = None
        sensor_humidity = None
        logstring = _('Failed to get sensordata.')
        logger.warning(logstring)
        
    sensordata={}
    sensordata['sensor_temperature'] = sensor_temperature
    sensordata['sensor_humidity'] = sensor_humidity
    
    return sensordata
def doMainLoop():
    """
    mainloop, pi-ager is running
    """
    global circulation_air_duration       #  Umluftdauer
    global circulation_air_period         #  Umluftperiode
    global exhaust_air_duration           #  (Abluft-)luftaustauschdauer
    global exhaust_air_period             #  (Abluft-)luftaustauschperiode
    global sensor_temperature             #  Gemessene Temperatur am Sensor
    global sensor_humidity                #  Gemessene Feuchtigkeit am Sensor
    global switch_on_cooling_compressor   #  Einschalttemperatur
    global switch_off_cooling_compressor  #  Ausschalttemperatur
    global switch_on_humidifier           #  Einschaltfeuchte
    global switch_off_humidifier          #  Ausschaltfeuchte
    global settings
    global status_circulating_air         #  Umluft
    global status_exhaust_air             #  (Abluft-)Luftaustausch
    global status_heater                  #  Heizung
    global status_cooling_compressor      #  Kuehlung
    global status_humidifier              #  Luftbefeuchtung
    #global counter_humidify               #  Zaehler Verzoegerung der Luftbefeuchtung
    #counter_humidify = 0
    global delay_humidify                 #  Luftbefeuchtungsverzoegerung
    global status_exhaust_fan             #  Variable fuer die "Evakuierung" zur Feuchtereduzierung durch (Abluft-)Luftaustausch
    global uv_modus                       #  Modus UV-Licht  (1 = Periode/Dauer; 2= Zeitstempel/Dauer)
    global status_uv                      #  UV-Licht
    global switch_on_uv_hour              #  Stunde wann das UV Licht angeschaltet werden soll
    global switch_on_uv_minute            #  Minute wann das UV Licht ausgeschaltet werden soll
    global uv_duration                    #  Dauer der UV_Belichtung
    global uv_period                      #  Periode für UV_Licht
    global light_modus                    #  ModusLicht  (1 = Periode/Dauer; 2= Zeitstempel/Dauer)
    global status_light                   #  Licht
    global switch_on_light_hour           #  Stunde wann Licht angeschaltet werden soll
    global switch_on_light_minute         #  Minute wann das Licht ausgeschaltet werden soll
    global light_duration                 #  Dauer für Licht
    global light_period                   #  Periode für Licht
    global light_stoptime                 #  Unix-Zeitstempel fuer den Stop des UV-Light
    global dehumidifier_modus             #  Modus Entfeuchter  (1 = über Abluft, 2 = mit Abluft zusammen [unterstützend]; 3 = anstelle von Abluft)
    global status_dehumidifier            #  Entfeuchter
    global status_pi_ager
    global logger

    # Pruefen Sensor, dann Settings einlesen

    pi_ager_database.write_start_in_database(pi_ager_names.status_pi_ager_key)
    status_pi_ager = 1
    count_continuing_emergency_loops = 0
    humidify_delay_switch = False
    
    logger.debug('doMainLoop()')

    while status_pi_ager == 1:
        check_and_set_light()
        check_status_agingtable()
        status_pi_ager = pi_ager_database.get_table_value(pi_ager_names.current_values_table, pi_ager_names.status_pi_ager_key)

#Settings
        #Sensor
        sht_exception_count = 0
        humidity_exception_count = 0
        sensordata_exception_count = 0
        temperature_exception_count = 0
        sensortype = int(pi_ager_init.sensortype)
        sensordata = get_sensordata(sht_exception_count, humidity_exception_count, temperature_exception_count, sensordata_exception_count)
        sensor_temperature = sensordata['sensor_temperature']
        sensor_humidity = sensordata['sensor_humidity']

        # Prüfen, ob Sensordaten empfangen wurden und falls nicht, auf Notfallmodus wechseln
        if sensor_temperature != None and sensor_humidity != None:
            count_continuing_emergency_loops = 0
            #weitere Settings
            modus = pi_ager_database.get_table_value(pi_ager_names.config_settings_table, pi_ager_names.modus_key)
            setpoint_temperature = int(pi_ager_database.get_table_value(pi_ager_names.config_settings_table, pi_ager_names.setpoint_temperature_key))
            setpoint_humidity = int(pi_ager_database.get_table_value(pi_ager_names.config_settings_table, pi_ager_names.setpoint_humidity_key))
            circulation_air_period = int(pi_ager_database.get_table_value(pi_ager_names.config_settings_table, pi_ager_names.circulation_air_period_key))
            logger.debug("circulation_air_period = " + str(circulation_air_period))
            circulation_air_duration = int(pi_ager_database.get_table_value(pi_ager_names.config_settings_table, pi_ager_names.circulation_air_duration_key))
            logger.debug("circulation_air_duration = "+ str(circulation_air_duration))
            exhaust_air_period = int(pi_ager_database.get_table_value(pi_ager_names.config_settings_table, pi_ager_names.exhaust_air_period_key))
            exhaust_air_duration = int(pi_ager_database.get_table_value(pi_ager_names.config_settings_table, pi_ager_names.exhaust_air_duration_key))
            switch_on_cooling_compressor = int(pi_ager_database.get_table_value(pi_ager_names.config_settings_table, pi_ager_names.switch_on_cooling_compressor_key))
            switch_off_cooling_compressor = int(pi_ager_database.get_table_value(pi_ager_names.config_settings_table, pi_ager_names.switch_off_cooling_compressor_key))
            switch_on_humidifier = int(pi_ager_database.get_table_value(pi_ager_names.config_settings_table, pi_ager_names.switch_on_humidifier_key))
            switch_off_humidifier = int(pi_ager_database.get_table_value(pi_ager_names.config_settings_table, pi_ager_names.switch_off_humidifier_key))
            delay_humidify = int(pi_ager_database.get_table_value(pi_ager_names.config_settings_table, pi_ager_names.delay_humidify_key))
            delay_humidify = delay_humidify * 60
            uv_modus = int(pi_ager_database.get_table_value(pi_ager_names.config_settings_table, pi_ager_names.uv_modus_key))
            switch_on_uv_hour = int(pi_ager_database.get_table_value(pi_ager_names.config_settings_table, pi_ager_names.switch_on_uv_hour_key))
            switch_on_uv_minute = int(pi_ager_database.get_table_value(pi_ager_names.config_settings_table, pi_ager_names.switch_on_uv_minute_key))
            uv_duration = float(pi_ager_database.get_table_value(pi_ager_names.config_settings_table, pi_ager_names.uv_duration_key))
            uv_period = float(pi_ager_database.get_table_value(pi_ager_names.config_settings_table, pi_ager_names.uv_period_key))
            light_modus = int(pi_ager_database.get_table_value(pi_ager_names.config_settings_table, pi_ager_names.light_modus_key))
            switch_on_light_hour = int(pi_ager_database.get_table_value(pi_ager_names.config_settings_table, pi_ager_names.switch_on_light_hour_key))
            switch_on_light_minute = int(pi_ager_database.get_table_value(pi_ager_names.config_settings_table, pi_ager_names.switch_on_light_minute_key))
            light_duration = float(pi_ager_database.get_table_value(pi_ager_names.config_settings_table, pi_ager_names.light_duration_key))
            light_period = float(pi_ager_database.get_table_value(pi_ager_names.config_settings_table, pi_ager_names.light_period_key))
            dehumidifier_modus = int(pi_ager_database.get_table_value(pi_ager_names.config_settings_table, pi_ager_names.dehumidifier_modus_key))

            # An dieser Stelle sind alle settings eingelesen, Ausgabe auf Konsole
            os.system('clear') # Clears the terminal
            current_time = pi_ager_database.get_current_time()
            # logger.info(pi_ager_names.logspacer)
            logstring = ' \n ' + pi_ager_names.logspacer
            logstring = logstring + ' \n ' + 'Main loop/Unix-Timestamp: (' + str(current_time)+ ')'
            # logger.info(logstring)
            logstring = logstring + ' \n ' + pi_ager_names.logspacer2
            # logger.info(pi_ager_names.logspacer2)
            logstring = logstring + ' \n ' + _('target temperature') + ': ' + str(setpoint_temperature) + ' C'
            # logger.info(logstring)
            logstring = logstring + ' \n ' +  _('actual temperature') + ': ' + str(sensor_temperature) + ' C'
            # logger.info(logstring)
            # logger.info(pi_ager_names.logspacer2)
            logstring = logstring + ' \n ' + pi_ager_names.logspacer2
            logstring = logstring + ' \n ' +  _('target humidity') + ': ' + str(setpoint_humidity) + '%'
            # logger.info(logstring)
            logstring = logstring + ' \n ' +  _('actual humidity') + ': ' + str(sensor_humidity) + '%'
            # logger.info(logstring)
            # logger.info(pi_ager_names.logspacer2)
            logstring = logstring + ' \n ' + pi_ager_names.logspacer2
            logstring = logstring + ' \n ' +  _('selected sensor') + ': ' + str(pi_ager_init.sensorname)
            # logger.info(logstring)
            # logstring = _('value in database') + ': ' + str(sensortype)
            logger.debug(_('value in database') + ': ' + str(sensortype))
            logstring = logstring + ' \n ' + pi_ager_names.logspacer2
            # logger.info(pi_ager_names.logspacer2)

            # gpio.setmode(pi_ager_names.board_mode)
            
            # Durch den folgenden Timer laeuft der Ventilator in den vorgegebenen Intervallen zusaetzlich zur generellen Umluft bei aktivem Heizen, Kuehlen oder Befeuchten
            # Timer fuer Luftumwaelzung-Ventilator
            if circulation_air_period == 0:                          # gleich 0 ist an,  Dauer-Timer
                status_circulation_air = True
            if circulation_air_duration == 0:                        # gleich 0 ist aus, kein Timer
                status_circulation_air = False
            if circulation_air_duration > 0:
                if current_time < pi_ager_init.circulation_air_start + circulation_air_period:
                    status_circulation_air = False                       # Umluft - Ventilator aus
                    logstring = logstring + ' \n ' +  _('circulation air timer active') + ' (' + _('fan off') +')'
                    # logger.info(logstring)
                if current_time >= pi_ager_init.circulation_air_start + circulation_air_period:
                    status_circulation_air = True                      # Umluft - Ventilator an
                    logstring = logstring + ' \n ' +  _('circulation air timer active') + ' (' + _('fan on') +')'
                    # logger.info(logstring)
                if current_time >= pi_ager_init.circulation_air_start + circulation_air_period + circulation_air_duration:
                    pi_ager_init.circulation_air_start = int(time.time())    # Timer-Timestamp aktualisiert
            # Timer fuer (Abluft-)Luftaustausch-Ventilator
            if exhaust_air_period == 0:                      # gleich 0 ist an,  Dauer-Timer
                status_exhaust_air = True
            if exhaust_air_duration == 0:                        # gleich 0 ist aus, kein Timer
                status_exhaust_air = False
            if exhaust_air_duration > 0:                        # gleich 0 ist aus, kein Timer
                if current_time < pi_ager_init.exhaust_air_start + exhaust_air_period:
                    status_exhaust_air = False                      # (Abluft-)Luftaustausch-Ventilator aus
                    logstring = logstring + ' \n ' +  _('exhaust air timer active') + ' (' + _('fan off') +')'
                    # logger.info(logstring)
                if current_time >= pi_ager_init.exhaust_air_start + exhaust_air_period:
                    status_exhaust_air = True                     # (Abluft-)Luftaustausch-Ventilator an
                    logstring = logstring + ' \n ' +  _('exhaust air timer active') + ' (' + _('fan on') +')'
                    # logger.info(logstring)
                if current_time >= pi_ager_init.exhaust_air_start + exhaust_air_period + exhaust_air_duration:
                    pi_ager_init.exhaust_air_start = int(time.time())   # Timer-Timestamp aktualisiert
            # Timer fuer UV-Licht
            if uv_modus == 0:                         # Modus 0 UV-Licht aus
                status_uv = False                      # UV-Licht aus
                logstring = logstring + ' \n ' +  _('modus uv-light') + ': ' + _('off')
                # logger.info(logstring)
            
            if uv_modus == 1:                            # Modus 1 = Periode/Dauer
                if uv_period == 0:                      # gleich 0 ist an,  Dauer-Timer
                    status_uv = True
                if uv_duration == 0:                        # gleich 0 ist aus, kein Timer
                    status_uv = False
                if uv_duration > 0:                        # gleich 0 ist aus, kein Timer                
                    if pi_ager_init.uv_stoptime == pi_ager_init.system_starttime:
                        pi_ager_init.uv_stoptime = pi_ager_init.uv_starttime + uv_duration
                        status_uv = True
                    if current_time >= pi_ager_init.uv_starttime and current_time <= pi_ager_init.uv_stoptime:
                        status_uv = True                     # UV-Licht an
                        logstring = logstring + ' \n ' +  _('uv-light timer active') + ' (' + _('uv-light on') +')'
                        # logger.info(logstring)
                        logger.debug('UV-Licht Startzeit: ' + str(pi_ager_init.uv_starttime))
                        logger.debug('UV-Licht Stoppzeit: ' + str(pi_ager_init.uv_stoptime))
                        logger.debug('UV-Licht duration: ' + str(uv_duration))
                    else: 
                        status_uv = False                      # UV-Licht aus
                        logstring = logstring + ' \n ' +  _('uv-light timer active') + ' (' + _('uv-light off') +')'
                        # logger.info(logstring)
                        logger.debug('UV-Licht Stoppzeit: ' + str(pi_ager_init.uv_stoptime))
                        logger.debug('UV-Licht Startzeit: ' + str(pi_ager_init.uv_starttime))
                        logger.debug('UV-Licht period: ' + str(uv_period))

                    if current_time > pi_ager_init.uv_stoptime:
                        pi_ager_init.uv_starttime = int(time.time()) + uv_period  # Timer-Timestamp aktualisiert
                        pi_ager_init.uv_stoptime = pi_ager_init.uv_starttime + uv_duration

            if uv_modus == 2:                         # Modus 2 Zeitstempel/Dauer
                now = datetime.datetime.now()
                year_now = now.year
                month_now = now.month
                day_now = now.day

                pi_ager_init.uv_starttime = datetime.datetime(year_now, month_now, day_now, switch_on_uv_hour, switch_on_uv_minute, 0, 0)
                pi_ager_init.uv_stoptime = pi_ager_init.uv_starttime + datetime.timedelta(0, uv_duration)
                logger.debug(pi_ager_init.uv_starttime)
                logger.debug(pi_ager_init.uv_stoptime)

                if now >= pi_ager_init.uv_starttime and now <= pi_ager_init.uv_stoptime:
                    status_uv = True                     # UV-Licht an
                    logstring = logstring + ' \n ' +  _('uv-light timestamp active') + ' (' + _('uv-light on') +')'
                    # logger.info(logstring)
                else: 
                    status_uv = False                      # UV-Licht aus
                    logstring = logstring + ' \n ' +  _('uv-light timestamp active') + ' (' + _('uv-light off') +')'
                    # logger.info(logstring)

            # Timer fuer Licht
            if light_modus == 0:                         # Modus 0 Licht aus
                status_light = False                      # Licht aus
                logstring = logstring + ' \n ' +  _('modus light') + ': ' + _('off')
                # logger.info(logstring)
            
            if light_modus == 1:                            # Modus 1 = Periode/Dauer
                if light_period == 0:                      # gleich 0 ist an,  Dauer-Timer
                    status_light = True
                if light_duration == 0:                        # gleich 0 ist aus, kein Timer
                    status_light = False
                if light_duration > 0:                        # es ist eine Dauer eingetragen                
                    if pi_ager_init.light_stoptime == pi_ager_init.system_starttime:
                        pi_ager_init.light_stoptime = pi_ager_init.light_starttime + light_duration
                        status_light = True
                    if current_time >= pi_ager_init.light_starttime and current_time <= pi_ager_init.light_stoptime:
                        if not status_light == True:
                            status_light = True                     # Licht an
                        logstring = logstring + ' \n ' +  _('light timer active') + ' (' + _('light on') +')'
                        # logger.info(logstring)
                        logger.debug('Licht Startzeit: ' + str(pi_ager_init.light_starttime))
                        logger.debug('Licht Stoppzeit: ' + str(pi_ager_init.light_stoptime))
                        logger.debug('Licht duration: ' + str(light_duration))
                    else: 
                        status_light = False                      # Licht aus
                        logstring = logstring + ' \n ' +  _('light timer active') + ' (' + _('light off') +')'
                        # logger.info(logstring)
                        logger.debug('Licht Stoppzeit: ' + str(pi_ager_init.light_stoptime))
                        logger.debug('Licht Startzeit: ' + str(pi_ager_init.light_starttime))
                        logger.debug('Licht period: ' + str(light_period))

                    if current_time > pi_ager_init.light_stoptime:
                        pi_ager_init.light_starttime = int(time.time()) + light_period  # Timer-Timestamp aktualisiert
                        pi_ager_init.light_stoptime = pi_ager_init.light_starttime + light_duration

            if light_modus == 2:                         # Modus 2 Zeitstempel/Dauer
                now = datetime.datetime.now()
                year_now = now.year
                month_now = now.month
                day_now = now.day

                pi_ager_init.light_starttime = datetime.datetime(year_now, month_now, day_now, switch_on_light_hour, switch_on_light_minute, 0, 0)
                pi_ager_init.light_stoptime = pi_ager_init.light_starttime + datetime.timedelta(0, light_duration)

                if now >= pi_ager_init.light_starttime and now <= pi_ager_init.light_stoptime:
                        status_light = True                     # Licht an
                        logstring = logstring + ' \n ' +  _('light timestamp active') + ' (' + _('light on') +')'
                        # logger.info(logstring)
                else: 
                    status_light = False                      # Licht aus
                    logstring = logstring + ' \n ' +  _('light timestamp active') + ' (' + _('light off') +')'
                    # logger.info(logstring)

            # Kuehlen
            if modus == 0:
                status_exhaust_fan = False                              # Feuchtereduzierung Abluft aus
                status_dehumidifier = False        # Entfeuchter aus
                gpio.output(pi_ager_names.gpio_heater, pi_ager_names.relay_off)                     # Heizung aus
                gpio.output(pi_ager_names.gpio_humidifier, pi_ager_names.relay_off)                 # Befeuchtung aus
                if sensor_temperature >= setpoint_temperature + switch_on_cooling_compressor:
                    gpio.output(pi_ager_names.gpio_cooling_compressor, pi_ager_names.relay_on)      # Kuehlung ein
                if sensor_temperature <= setpoint_temperature + switch_off_cooling_compressor :
                    gpio.output(pi_ager_names.gpio_cooling_compressor, pi_ager_names.relay_off)     # Kuehlung aus
            
            # Kuehlen mit Befeuchtung
            if modus == 1:
                status_exhaust_fan = False                     # Feuchtereduzierung Abluft aus
                status_dehumidifier = False        # Entfeuchter aus
                gpio.output(pi_ager_names.gpio_heater, pi_ager_names.relay_off)      # Heizung aus
                if sensor_temperature >= setpoint_temperature + switch_on_cooling_compressor:
                    gpio.output(pi_ager_names.gpio_cooling_compressor, pi_ager_names.relay_on)     # Kuehlung ein
                if sensor_temperature <= setpoint_temperature + switch_off_cooling_compressor :
                    gpio.output(pi_ager_names.gpio_cooling_compressor, pi_ager_names.relay_off)    # Kuehlung aus
                if sensor_humidity <= setpoint_humidity - switch_on_humidifier:
                    gpio.output(pi_ager_names.gpio_humidifier, pi_ager_names.relay_on)      # Befeuchtung ein
                if sensor_humidity >= setpoint_humidity - switch_off_humidifier:
                    gpio.output(pi_ager_names.gpio_humidifier, pi_ager_names.relay_off)     # Befeuchtung aus
            
            # Heizen mit Befeuchtung
            if modus == 2:
                status_exhaust_fan = False                     # Feuchtereduzierung Abluft aus
                status_dehumidifier = False        # Entfeuchter aus
                gpio.output(pi_ager_names.gpio_cooling_compressor, pi_ager_names.relay_off)        # Kuehlung aus
                if sensor_temperature <= setpoint_temperature - switch_on_cooling_compressor:
                    gpio.output(pi_ager_names.gpio_heater, pi_ager_names.relay_on)   # Heizung ein
                if sensor_temperature >= setpoint_temperature - switch_off_cooling_compressor:
                    gpio.output(pi_ager_names.gpio_heater, pi_ager_names.relay_off)  # Heizung aus
                if sensor_humidity <= setpoint_humidity - switch_on_humidifier:
                    gpio.output(pi_ager_names.gpio_humidifier, pi_ager_names.relay_on)      # Befeuchtung ein
                if sensor_humidity >= setpoint_humidity - switch_off_humidifier:
                    gpio.output(pi_ager_names.gpio_humidifier, pi_ager_names.relay_off)     # Befeuchtung aus
            
            # Automatiktemperatur mit Befeuchtung
            if modus == 3:
                status_exhaust_fan = False                     # Feuchtereduzierung Abluft aus
                status_dehumidifier = False        # Entfeuchter aus
                if sensor_temperature >= setpoint_temperature + switch_on_cooling_compressor:
                    gpio.output(pi_ager_names.gpio_cooling_compressor, pi_ager_names.relay_on)     # Kuehlung ein
                if sensor_temperature <= setpoint_temperature + switch_off_cooling_compressor:
                    gpio.output(pi_ager_names.gpio_cooling_compressor, pi_ager_names.relay_off)    # Kuehlung aus
                if sensor_temperature <= setpoint_temperature - switch_on_cooling_compressor:
                    gpio.output(pi_ager_names.gpio_heater, pi_ager_names.relay_on)   # Heizung ein
                if sensor_temperature >= setpoint_temperature - switch_off_cooling_compressor:
                    gpio.output(pi_ager_names.gpio_heater, pi_ager_names.relay_off)  # Heizung aus
                if sensor_humidity <= setpoint_humidity - switch_on_humidifier:
                    gpio.output(pi_ager_names.gpio_humidifier, pi_ager_names.relay_on)      # Befeuchtung ein
                if sensor_humidity >= setpoint_humidity - switch_off_humidifier:
                    gpio.output(pi_ager_names.gpio_humidifier, pi_ager_names.relay_off)     # Befeuchtung aus
                # logger.info(_('dehumidifier_modus') + ': ' + str(dehumidifier_modus))
                # logger.info(_('sensor_humidity') + ': ' + str(sensor_humidity))
                # logger.info(_('setpoint_humidity') + ': ' + str(setpoint_humidity))
                # logger.info(_('switch_on_humidifier') + ': ' + str(switch_on_humidifier))
                # logger.info(_('status_dehumidifier') + ': ' + str(status_dehumidifier))

            # Automatik mit Befeuchtung und Entfeuchtung durch (Abluft-)Luftaustausch
            if modus == 4:
                database_value_status_exhaust_fan = int(pi_ager_database.get_table_value(pi_ager_names.current_values_table, pi_ager_names.status_exhaust_air_key))
                if database_value_status_exhaust_fan == 0:
                    status_exhaust_fan = False                                   # Abluft ist aktuell aus
                else:
                    status_exhaust_fan = True                                   # Abluft ist aktuell an
                if sensor_temperature >= setpoint_temperature + switch_on_cooling_compressor:
                    gpio.output(pi_ager_names.gpio_cooling_compressor, pi_ager_names.relay_on)     # Kuehlung ein
                if sensor_temperature <= setpoint_temperature - switch_on_cooling_compressor:
                    gpio.output(pi_ager_names.gpio_heater, pi_ager_names.relay_on)   # Heizung ein
                if sensor_temperature <= setpoint_temperature + switch_off_cooling_compressor:
                    gpio.output(pi_ager_names.gpio_cooling_compressor, pi_ager_names.relay_off)    # Kuehlung aus
                if sensor_temperature >= setpoint_temperature - switch_off_cooling_compressor:
                    gpio.output(pi_ager_names.gpio_heater, pi_ager_names.relay_off)  # Heizung aus
                if sensor_humidity <= setpoint_humidity - switch_on_humidifier:
                    if not humidify_delay_switch:
                        humidify_delay_switch = True
                        humidify_delay_starttime = pi_ager_database.get_current_time()
                    # counter_humidify = counter_humidify + 1
                    if pi_ager_database.get_current_time() >= humidify_delay_starttime + delay_humidify:      # Verzoegerung der Luftbefeuchtung
                    #if counter_humidify >= delay_humidify:               # Verzoegerung der Luftbefeuchtung
                        gpio.output(pi_ager_names.gpio_humidifier, pi_ager_names.relay_on)  # Luftbefeuchter ein
                if sensor_humidity >= setpoint_humidity - switch_off_humidifier:
                    gpio.output(pi_ager_names.gpio_humidifier, pi_ager_names.relay_off)     # Luftbefeuchter aus
                    # counter_humidify = 0
                    humidify_delay_switch = False
                if sensor_humidity >= setpoint_humidity + switch_on_humidifier:
                    if dehumidifier_modus == 1 or dehumidifier_modus == 2:  # entweder nur über Abluft oder mit unterstützung von Entfeuchter
                        status_exhaust_fan = True                           # Feuchtereduzierung Abluft-Ventilator ein
                        if dehumidifier_modus == 2:                         # Entfeuchter zur Unterstützung
                            status_dehumidifier = True                      # Entfeuchter unterstützend ein
                        else:
                            status_dehumidifier = False                     # Entfeuchter aus
                    if dehumidifier_modus == 3:                             # rein über entfeuchtung
                        status_exhaust_fan = False                          # Abluft aus
                        status_dehumidifier = True                          # Entfeuchter ein
                if sensor_humidity <= setpoint_humidity + switch_off_humidifier:
                    if dehumidifier_modus == 1 or dehumidifier_modus == 2:
                        status_exhaust_fan = False         # Feuchtereduzierung Abluft-Ventilator aus
                        status_dehumidifier = False        # Entfeuchter aus
                    else:
                        status_dehumidifier = False        # Entfeuchter aus
            
            # Schalten des Umluft - Ventilators
            if gpio.input(pi_ager_names.gpio_heater) or gpio.input(pi_ager_names.gpio_cooling_compressor) or gpio.input(pi_ager_names.gpio_humidifier) or status_circulation_air == True:
                gpio.output(pi_ager_names.gpio_circulating_air, pi_ager_names.relay_on)               # Umluft - Ventilator an
            if gpio.input(pi_ager_names.gpio_heater) and gpio.input(pi_ager_names.gpio_cooling_compressor) and gpio.input(pi_ager_names.gpio_humidifier) and status_circulation_air == False:
                gpio.output(pi_ager_names.gpio_circulating_air, pi_ager_names.relay_off)             # Umluft - Ventilator aus
            
            # Schalten des Entfeuchters
            if status_dehumidifier == True:
                gpio.output(pi_ager_names.gpio_dehumidifier, pi_ager_names.relay_on)
            if status_dehumidifier == False:
                gpio.output(pi_ager_names.gpio_dehumidifier, pi_ager_names.relay_off)
            
            # Schalten des (Abluft-)Luftaustausch-Ventilator
            if status_exhaust_air == True or status_exhaust_fan == True:
                gpio.output(pi_ager_names.gpio_exhausting_air, pi_ager_names.relay_on)
            if status_exhaust_air == False and status_exhaust_fan == False:
                gpio.output(pi_ager_names.gpio_exhausting_air, pi_ager_names.relay_off)
            
            # Schalten des UV_Licht
            if status_uv == True and pi_ager_database.get_status_uv_manual() == 1:
                gpio.output(pi_ager_names.gpio_uv, pi_ager_names.relay_on)

            if status_uv == False or pi_ager_database.get_status_uv_manual() == 0:
                gpio.output(pi_ager_names.gpio_uv, pi_ager_names.relay_off)
            
            # Schalten des Licht
            if status_light == True:
                switch_light(pi_ager_names.relay_on)
                # gpio.output(pi_ager_names.gpio_light, pi_ager_names.relay_on)
            if status_light == False and pi_ager_database.get_status_light_manual() == 0:
                switch_light(pi_ager_names.relay_off)
                # gpio.output(pi_ager_names.gpio_light, pi_ager_names.relay_off)
            
            # Lesen der Scales Daten
            scale1_row = pi_ager_database.get_scale_table_row(pi_ager_names.data_scale1_table)
            if scale1_row == None:
                scale1_data = 0
            else:
                scale1_value = scale1_row[pi_ager_names.value_field]
                scale1_last_change = scale1_row[pi_ager_names.last_change_field]
                timediff_scale1 = pi_ager_database.get_current_time() - scale1_last_change
                if timediff_scale1 < pi_ager_database.get_table_value(pi_ager_names.settings_scale1_table,pi_ager_names.scale_measuring_interval_key):
                    scale1_data = scale1_value
                else:
                    scale1_data = 0

            scale2_row = pi_ager_database.get_scale_table_row(pi_ager_names.data_scale2_table)
            if scale2_row == None:
                scale2_data = 0
            else:
                scale2_value = scale2_row[pi_ager_names.value_field]
                scale2_last_change = scale2_row[pi_ager_names.last_change_field]
                timediff_scale2 = pi_ager_database.get_current_time() - scale2_last_change
                if timediff_scale2 < pi_ager_database.get_table_value(pi_ager_names.settings_scale2_table,pi_ager_names.scale_measuring_interval_key):
                    scale2_data = scale2_value
                else:
                    scale2_data = 0
            
            # Ausgabe der Werte auf der Konsole
            # logger.info(pi_ager_names.logspacer2)
            logstring = logstring + ' \n ' + pi_ager_names.logspacer2
            if gpio.input(pi_ager_names.gpio_heater) == False:
                logstring = logstring + ' \n ' +  _('heater') + ' ' + _('on')
                # logger.info(logstring)
                status_heater = 1
            else:
                logstring = logstring + ' \n ' +  _('heater') + ' ' + _('off')
                # logger.info(logstring)
                status_heater = 0
            if gpio.input(pi_ager_names.gpio_cooling_compressor) == False:
                logstring = logstring + ' \n ' +  _('cooling compressor') + ' ' + _('on')
                # logger.info(logstring)
                status_cooling_compressor = 1
            else:
                logstring = logstring + ' \n ' +  _('cooling compressor') + ' ' + _('off')
                # logger.info(logstring)
                status_cooling_compressor = 0
            if gpio.input(pi_ager_names.gpio_humidifier) == False:
                logstring = logstring + ' \n ' +  _('humidifier') + ' ' + _('on')
                # logger.info(logstring)
                status_humidifier = 1
            else:
                logstring = logstring + ' \n ' +  _('humidifier') + ' ' + _('off')
                # logger.info(logstring)
                status_humidifier = 0
            if gpio.input(pi_ager_names.gpio_circulating_air) == False:
                logstring = logstring + ' \n ' +  _('circulation air') + ' ' + _('on')
                # logger.info(logstring)
                status_circulating_air = 1
            else:
                logstring = logstring + ' \n ' +  _('circulation air') + ' ' + _('off')
                # logger.info(logstring)
                status_circulating_air = 0
            if gpio.input(pi_ager_names.gpio_exhausting_air) == False:
                logstring = logstring + ' \n ' +  _('exhaust air') + ' ' + _('on')
                # logger.info(logstring)
                status_exhaust_air = 1
            else:
                logstring = logstring + ' \n ' +  _('exhaust air') + ' ' + _('off')
                # logger.info(logstring)
                status_exhaust_air = 0
            if gpio.input(pi_ager_names.gpio_dehumidifier) == False:
                logstring = logstring + ' \n ' +  _('dehumidifier') + ' ' + _('on')
                # logger.info(logstring)
                status_dehumidifier = 1
            else:
                logstring = logstring + ' \n ' +  _('dehumidifier') + ' ' + _('off')
                # logger.info(logstring)
                status_dehumidifier = 0
            if get_gpio_value(pi_ager_names.gpio_light) == False:
                logstring = logstring + ' \n ' +  _('light') + ' ' + _('on')
                # logger.info(logstring)
                status_light = 1
            else:
                logstring = logstring + ' \n ' +  _('light') + ' ' + _('off')
                # logger.info(logstring)
                status_light = 0
            if gpio.input(pi_ager_names.gpio_uv) == False:
                logstring = logstring + ' \n ' +  _('uv-light') + ' ' + _('on')
                # logger.info(logstring)
                status_uv= 1
            else:
                logstring = logstring + ' \n ' +  _('uv-light') + ' ' + _('off')
                # logger.info(logstring)
                status_uv = 0
            if scale1_data > 0:
                logstring = logstring + ' \n ' +  _('weight scale') + ' 1: ' + str(scale1_data)
                # logger.info(logstring)
            if scale2_data > 0:
                logstring = logstring + ' \n ' +  _('weight scale') + ' 2: ' + str(scale2_data)
                # logger.info(logstring)

            # logger.info(pi_ager_names.logspacer2)
            logstring = logstring + ' \n ' + pi_ager_names.logspacer2

            if status_value_has_changed():
                logger.info(logstring)
            
            # Messwerte in die RRD-Datei schreiben
            # Schreiben der aktuellen Status-Werte
            pi_ager_database.write_current(pi_ager_init.loopcounter, sensor_temperature, status_heater, status_exhaust_air, status_cooling_compressor, status_circulating_air, sensor_humidity, status_uv, status_light, status_humidifier, status_dehumidifier)

            logger.debug('writing current values in database performed')
        
        else:
            count_continuing_emergency_loops += 1
            logger.debug('loopnumber: ' + str(pi_ager_init.loopcounter) + ' without sensordata!!')
            logger.warning('loopnumber: ' + str(pi_ager_init.loopcounter) + ' is loop ' + str(count_continuing_emergency_loops) + ' without sensor response!')
            if count_continuing_emergency_loops == 10:
                logger.info('Because of ' + str(count_continuing_emergency_loops) + ' loops without sensordata the system will be rebooted now!')
                os.system('sudo /var/sudowebscript.sh reboot')
        
        logger.debug('loopnumber: ' + str(pi_ager_init.loopcounter))

        # time.sleep(1)  
        
        # Logfile auf Rechte prüfen und evtl. neu setzen
        
        # filepermission = oct(os.stat(pi_ager_paths.logfile_txt_file)[stat.ST_MODE])[-3:]
        # if (filepermission != '666'):
            # os.chmod(pi_ager_paths.get_path_logfile_txt_file(), stat.S_IWOTH|stat.S_IWGRP|stat.S_IWUSR|stat.S_IROTH|stat.S_IRGRP|stat.S_IRUSR)
        pi_ager_logging.check_website_logfile()
        
        # Mainloop fertig
        logger.debug('loop complete')
        pi_ager_init.loopcounter += 1
        
        
        
# Ende While-Schleife
    logger.debug('status!= 1')
    pi_ager_gpio_config.defaultGPIO()