Beispiel #1
0
 def getwatt(self, uberschuss, uberschussoffset):
     self.prewatt(uberschuss, uberschussoffset)
     argumentList = [
         'python3', self._prefixpy + 'viessmann/watt.py',
         str(self.device_nummer),
         str(self._device_ip),
         str(self.devuberschuss)
     ]
     try:
         self.proc = subprocess.Popen(argumentList)
         self.proc.communicate()
         self.f1 = open(
             self._basePath + '/ramdisk/smarthome_device_ret' +
             str(self.device_nummer), 'r')
         self.answerj = json.load(self.f1)
         self.f1.close()
         self.answer = json.loads(self.answerj)
         self.newwatt = int(self.answer['power'])
         self.newwattk = int(self.answer['powerc'])
         self.relais = int(self.answer['on'])
     except Exception as e1:
         log.warning("(" + str(self.device_nummer) +
                     ") Leistungsmessung %s %d %s Fehlermeldung: %s " %
                     ('viessmann', self.device_nummer, str(self._device_ip),
                      str(e1)))
     self.postwatt()
Beispiel #2
0
 def pbon(self):
     if (self.led == 1):
         return
     try:
         urllib.request.urlopen("http://" + str(self._device_pbip) +
                                "/settings?led_status_disable=false",
                                timeout=3)
         log.info("Shelly button led on (%d) %s"
                  % (self.device_nummer, self._device_pbip))
     except Exception as e1:
         log.warning("Shelly button on (%d) %s Fehlermeldung: %s "
                     % (self.device_nummer, self._device_pbip, str(e1)))
     self.led = 1
Beispiel #3
0
def checkbootdone():
    global resetmaxeinschaltdauer
    resetmaxeinschaltdauer = 0
    try:
        with open(bp + '/ramdisk/bootinprogress', 'r') as value:
            bootinprogress = int(value.read())
    except Exception as e:
        bootinprogress = 1
        log.warning("Ramdisk not set up. Maybe we are still" +
                    "booting (bootinprogress)." + str(e))
        time.sleep(30)
        return 0
    try:
        with open(bp + '/ramdisk/updateinprogress', 'r') as value:
            updateinprogress = int(value.read())
    except Exception as e:
        updateinprogress = 1
        log.warning("Ramdisk not set up. Maybe we are still" +
                    " booting (updateinprogress)." + str(e))
        time.sleep(30)
        return 0
    if (updateinprogress == 1):
        log.warning("Update in progress.")
        time.sleep(30)
        return 0
    if (bootinprogress == 1):
        log.warning("Boot in progress.")
        time.sleep(30)
        return 0
    return 1
Beispiel #4
0
 def updatepar(self, input_param):
     super().updatepar(input_param)
     self._smart_paramadd = input_param.copy()
     self.device_nummer = int(self._smart_paramadd.get('device_nummer',
                                                       '0'))
     for key, value in self._smart_paramadd.items():
         if (key == 'device_nummer'):
             pass
         elif (key == 'device_acthortype'):
             self._device_acthortype = value
         elif (key == 'device_acthorpower'):
             self._device_acthorpower = value
         else:
             log.warning("(" + str(self.device_nummer) + ") " +
                         __class__.__name__ + " überlesen " + key +
                         " " + value)
Beispiel #5
0
 def sepwattread(self):
     argumentList = [
         'python3', self._prefixpy + 'json/watt.py',
         str(self.device_nummer), self._device_measurejsonurl,
         self._device_measurejsonpower, self._device_measurejsoncounter
     ]
     try:
         proc = subprocess.Popen(argumentList)
         proc.communicate()
         answer = self.readret()
         self.newwatt = int(answer['power'])
         self.newwattk = int(answer['powerc'])
     except Exception as e1:
         log.warning("Leistungsmessung %s %s Fehlermeldung: %s " %
                     ('json ', self.device_nummer, str(e1)))
     return self.newwatt, self.newwattk
Beispiel #6
0
 def _watt(self, ip):
     argumentList = [
         'python3', self._prefixpy + 'tasmota/watt.py',
         str(self.device_nummer),
         str(ip), '0'
     ]
     try:
         proc = subprocess.Popen(argumentList)
         proc.communicate()
         answer = self.readret()
         self.newwatt = int(answer['power'])
         self.newwattk = int(answer['powerc'])
         self.relais = int(answer['on'])
     except Exception as e1:
         log.warning("Leistungsmessung %s %d %s Fehlermeldung: %s " %
                     ('Tasmota', self.device_nummer, ip, str(e1)))
Beispiel #7
0
 def turndevicerelais(self, zustand, ueberschussberechnung, updatecnt):
     self.preturn(zustand, ueberschussberechnung, updatecnt)
     if (zustand == 1):
         pname = "/on.py"
     else:
         pname = "/off.py"
     argumentList = ['python3', self._prefixpy + 'vampair' + pname,
                     str(self.device_nummer), str(self._device_ip),
                     str(self.devuberschuss)]
     try:
         self.proc = subprocess.Popen(argumentList)
         self.proc.communicate()
     except Exception as e1:
         log.warning("(" + str(self.device_nummer) +
                     ") on / off  %s %d %s Fehlermeldung: %s "
                     % ('vampair', self.device_nummer,
                        str(self._device_ip), str(e1)))
Beispiel #8
0
 def getwatt(self, uberschuss, uberschussoffset):
     self.prewatt(uberschuss, uberschussoffset)
     argumentList = ['python3', self._prefixpy + 'vampair/watt.py',
                     str(self.device_nummer), str(self._device_ip),
                     str(self.devuberschuss)]
     try:
         self.proc = subprocess.Popen(argumentList)
         self.proc.communicate()
         self.answer = self.readret()
         self.newwatt = int(self.answer['power'])
         self.newwattk = int(self.answer['powerc'])
         self.relais = int(self.answer['on'])
     except Exception as e1:
         log.warning("(" + str(self.device_nummer) +
                     ") Leistungsmessung %s %d %s Fehlermeldung: %s "
                     % ('vampair', self.device_nummer,
                        str(self._device_ip), str(e1)))
     self.postwatt()
Beispiel #9
0
 def _watt(self, url, urlc, urls):
     argumentList = [
         'python3', self._prefixpy + 'http/watt.py',
         str(self.device_nummer), '0',
         str(self.devuberschuss), url, urlc, '0', '0', urls
     ]
     proc = subprocess.Popen(argumentList)
     proc.communicate()
     try:
         proc = subprocess.Popen(argumentList)
         proc.communicate()
         answer = self.readret()
         self.newwatt = int(answer['power'])
         self.newwattk = int(answer['powerc'])
         self.relais = int(answer['on'])
     except Exception as e1:
         log.warning("Leistungsmessung %s %d Fehlermeldung: %s " %
                     ('http', self.device_nummer, str(e1)))
Beispiel #10
0
 def sepwattread(self):
     argumentList = [
         'python3', self._prefixpy + 'sdm120/sdm120.py',
         str(self.device_nummer),
         str(self._device_measureip),
         str(self._device_measureid),
         str(self._device_measureportsdm)
     ]
     try:
         proc = subprocess.Popen(argumentList)
         proc.communicate()
         answer = self.readret()
         self.newwatt = int(answer['power'])
         self.newwattk = int(answer['powerc'])
     except Exception as e1:
         log.warning("Leistungsmessung %s %d %s Fehlermeldung: %s " %
                     ('Sdm120 ', self.device_nummer,
                      str(self._device_measureip), str(e1)))
     return self.newwatt, self.newwattk
Beispiel #11
0
 def _watt(self, ip, chan):
     argumentList = [
         'python3', self._prefixpy + 'shelly/watt.py',
         str(self.device_nummer),
         str(ip), '0',
         str(chan)
     ]
     try:
         proc = subprocess.Popen(argumentList)
         proc.communicate()
         answer = self.readret()
         self.newwatt = int(answer['power'])
         self.newwattk = int(answer['powerc'])
         self.relais = int(answer['on'])
         if (self.device_temperatur_configured > 0):
             self.temp0 = str(answer['temp0'])
             with open(
                     self._basePath + '/ramdisk/device' +
                     str(self.device_nummer) + '_temp0', 'w') as f:
                 f.write(str(self.temp0))
         else:
             self.temp0 = '300'
         if (self.device_temperatur_configured > 1):
             self.temp1 = str(answer['temp1'])
             with open(
                     self._basePath + '/ramdisk/device' +
                     str(self.device_nummer) + '_temp1', 'w') as f:
                 f.write(str(self.temp1))
         else:
             self.temp1 = '300'
         if (self.device_temperatur_configured > 2):
             self.temp2 = str(answer['temp2'])
             with open(
                     self._basePath + '/ramdisk/device' +
                     str(self.device_nummer) + '_temp2', 'w') as f:
                 f.write(str(self.temp2))
         else:
             self.temp2 = '300'
     except Exception as e1:
         log.warning("Leistungsmessung %s %d %s Fehlermeldung: %s " %
                     ('Shelly', self.device_nummer, ip, str(e1)))
Beispiel #12
0
 def checkbut(self, manual, relais, manual_control):
     newmanual = manual
     newmanual_control = manual_control
     try:
         at = str(urllib.request.urlopen("http://" +
                                         str(self._device_pbip)
                                         + "/status",
                                         timeout=3).read().decode("utf-8"))
     except Exception as e1:
         log.warning("Shelly button ch (%d) %s Fehlermeldung: %s "
                     % (self.device_nummer, self._device_pbip, str(e1)))
         return newmanual, newmanual_control
     a = json.loads(at)
     with open(self._basePath+'/ramdisk/smarthome_device_ret' +
               str(self.device_nummer) + '_shelly_bp', 'w') as f:
         f.write(str(a))
     self.oldevent_cnt = self.event_cnt
     self.oldevent = self.event
     self.event_cnt = int(a['inputs'][0]['event_cnt'])
     self.event = str(a['inputs'][0]['event'])
     if (self.oldevent == 'none'):
         return newmanual, newmanual_control
     if ((self.event == self.oldevent) and
        (self.event_cnt == self.oldevent_cnt)):
         return newmanual, newmanual_control
     log.info("Shelly button pressed (%d) %s %s"
              % (self.device_nummer, self._device_pbip, self.event))
     # im automatic modus -> ein mal Drücken wechselen auf manual
     if (manual == 0):
         newmanual = 1
         return newmanual, newmanual_control
     # im manual modus  -> ein mal Drücken wechselen  zwischen on und off
     if (self.event == 'S'):
         if (manual_control == 1):
             newmanual_control = 0
         else:
             newmanual_control = 1
         return newmanual, newmanual_control
     # im manual modus  -> mehrmals drücken wechselen auf automat
     newmanual = 0
     return newmanual, newmanual_control
Beispiel #13
0
def loadregelvars():
    global uberschuss
    global uberschussoffset
    global speicherleistung
    global speichersoc
    global speichervorhanden
    global wattbezug
    global numberOfSupportedDevices
    global maxspeicher
    global mydevices
    try:
        with open(bp + '/ramdisk/speichervorhanden', 'r') as value:
            speichervorhanden = int(value.read())
        if (speichervorhanden == 1):
            with open(bp + '/ramdisk/speicherleistung', 'r') as value:
                speicherleistung = int(float(value.read()))
            with open(bp + '/ramdisk/speichersoc', 'r') as value:
                speichersoc = int(float(value.read()))
        else:
            speicherleistung = 0
            speichersoc = 100
    except Exception as e:
        log.warning("Fehler beim Auslesen der Ramdisk " +
                    "(speichervorhanden,speicherleistung,speichersoc): " +
                    str(e))
        speichervorhanden = 0
        speicherleistung = 0
        speichersoc = 100
    try:
        with open(bp + '/ramdisk/wattbezug', 'r') as value:
            wattbezug = int(float(value.read())) * -1
    except Exception as e:
        log.warning("Fehler beim Auslesen der Ramdisk (wattbezug):" + str(e))
        wattbezug = 0
    uberschuss = wattbezug + speicherleistung
    try:
        with open(bp + '/ramdisk/smarthomehandlermaxbatterypower',
                  'r') as value:
            maxspeicher = int(value.read())
    except Exception as e:
        log.warning("Fehler beim Auslesen der Ramdisk " +
                    "(smarthomehandlermaxbatterypower): " + str(e))
        maxspeicher = 0
    uberschussoffset = wattbezug + speicherleistung - maxspeicher
    log.info("EVU Bezug(-)/Einspeisung(+): " + str(wattbezug) +
             " max Speicherladung: " + str(maxspeicher))
    log.info("Uberschuss: " + str(uberschuss) + " Uberschuss mit Offset: " +
             str(uberschussoffset))
    log.info("Speicher Entladung(-)/Ladung(+): " + str(speicherleistung) +
             " SpeicherSoC: " + str(speichersoc))
    reread = 0
    try:
        with open(bp + '/ramdisk/rereadsmarthomedevices', 'r') as value:
            reread = int(value.read())
    except Exception:
        reread = 1
    if (reread == 1):
        with open(bp + '/ramdisk/rereadsmarthomedevices', 'w') as f:
            f.write(str(0))
        readmq()

    for i in range(1, (numberOfSupportedDevices + 1)):
        try:
            with open(bp + '/ramdisk/smarthome_device_manual_' + str(i),
                      'r') as value:
                for mydevice in mydevices:
                    if (str(i) == str(mydevice.device_nummer)):
                        mydevice.device_manual = int(value.read())
        except Exception:
            pass
        try:
            with open(
                    bp + '/ramdisk/smarthome_device_manual_control_' + str(i),
                    'r') as value:
                for mydevice in mydevices:
                    if (str(i) == str(mydevice.device_nummer)):
                        mydevice.device_manual_control = int(value.read())
        except Exception:
            pass