Dr. Arne Jachens

Set up the Raspberry Pi

no warranty for any of the provided information

Keine Erläuterungen gefunden.

from datetime import  datetime
from HvcTables import  *

"""
Dr. Arne Jachens
2020-06-19
"""
class HvcControl:
    def  __init__(self):
        self.operationMode = {}
        self.parameters = {}
        pass

    def  solar(self,sensors,actuators,hour,minutes):
        """
        Solar control, enable pump, when solar collector is warmer then tank bottom.
        In vacation mode, engage pump at night to cool tank.
        """
        HvcTables = HvcControl.HvcTables
        operationMode = self.operationMode
        
        if operationMode['solar']=="off":
            actuators['solar']=0
        elif operationMode['solar']=="on":
            actuators['solar']=1
        else: #auto
            solarMode = "operate"
            if operationMode['opMod']=="vacation":
                # cool down at night, if storage is too hot
                now = datetime.now()
                hour = int(now.strftime("%H"))
                night=True;
                if int(hour)>6:  night=False
                if int(hour)>20: night=True
                if night and sensors['THot']>60 and sensors['TAmb']<sensors['TLow']:
                    solarMode = "coolDown"
            elif  operationMode['opMod']=="winter":
#                if sensors['coll']>sensors['TLow']+self.parameters["DeltaTKollektor"] and int(hour)<self.parameters["hourSolarOff"]:
                    #let circulation cool down, when effciency gets bad in the afternoon
#                    actuators['solar']=1
                DeltaT = sensors['coll'] - sensors['TLow']
                actuators['solar'] = HvcTables.interpol( DeltaT, "solarLevel", "saturate" )
                    #let circulation cool down, when effciency gets bad in the afternoon
                if int(hour)>=self.parameters["hourSolarOff"]:
                    actuators['solar'] = 0
            elif  operationMode['opMod']=="summer":
#                if sensors['coll']>sensors['TLow']+self.parameters["DeltaTKollektor"]:
#                    actuators['solar']=1
                DeltaT = sensors['coll'] - sensors['TLow']
                actuators['solar'] = HvcTables.interpol( DeltaT, "solarLevel", "saturate" )

            if solarMode == "coolDown":
                actuators['solar']=0.2
#                    minute = int(now.strftime("%M"))
#                    if (minute % 2) == 0:
#                        actuators['solar']=1
#                    else:
#                        actuators['solar']=0
            else:
                #standart operation of solar heating
                if sensors['coll']<sensors['TLow']+10:
                    actuators['solar']=0
                    
        return actuators['solar']

    def  oven(self,sensors,actuators,hour,minutes):
        """
        Oven control, engage oven, when tank top gets too cold,
        stop oven, when tank reaches upper target Temperature.
        In summer mode, tolerate lower tank Temperature in the morning,
        if sun is expected to shine today :-)
        """
        operationMode = self.operationMode
        if operationMode['oven']=="off":
            actuators['oven']=0
        elif operationMode['oven']=="on":
            actuators['oven']=1
        else: #auto
            if sensors['THot']<self.parameters["TOfenAn"] and operationMode['opMod']=="winter":
                actuators['oven']=1
            elif sensors['THot']<self.parameters["TOfenAn"] and operationMode['opMod']=="summer" and hour>=14:
                actuators['oven']=1
            if sensors['THot']>self.parameters["TOfenAus"]:
                actuators['oven']=0

        return actuators['oven']

    def  pump(self,sensors,actuators):
        """
        Pump control, engage circulation to heat air, when house gets too cold,
        stop pump, when house Temperature is above target.
        In summer mode, keep pump = off
        In winter mode, pump operates as  long as  the oven is on, to make use of the heat when it is produced.
        """
        operationMode = self.operationMode
        if operationMode['pump']=="on":
            actuators['pump']=1
        elif operationMode['pump']=="off":
            actuators['pump']=0
        elif operationMode['opMod']=="winter":
            if actuators['oven']>0.9 and sensors['fire']>25:
                actuators['pump']=1
            elif sensors['haus']<self.parameters["THausSoll"]:
                actuators['pump']=1
            elif sensors['haus']>self.parameters["THausSoll"]+0.5:
                actuators['pump']=0
        else:
            actuators['pump']=0
                
        return actuators['pump']

    def  vent(self,sensors,actuators,hour,minutes):
        """
        Ventilation is generally set to normal.
        A few times per day, it is set to maximum to vent the house.
        In winter mode, maximum is choosen, when oven = on, to bring the heat into the house.
        """
        operationMode = self.operationMode
        if operationMode['vent']=="off":
            actuators['vent']=0                                 #0xff
        elif operationMode['vent']=="minimal":
            actuators['vent']=self.parameters["ventMinimal"]    #0xbb
        elif operationMode['vent']=="normal":
            actuators['vent']=self.parameters["ventNormal"]     #0x99
        elif operationMode['vent']=="maximal":
            actuators['vent']=1.00                              #0x00
        elif operationMode['vent']=="auto":
            if actuators['oven']>0.9 and sensors['fire']>25:
                actuators['vent']=1.00
            #elif operationMode['opMod']=="summer":
                #time controlled
            else:
                actuators['vent']=self.parameters["ventNormal"]
            
        return actuators['vent']

    def  byPs(self,sensors,actuators):
        """
        ByPass is open in summer to have maximal cooling,
        in winter mode it is shut to recover the heat from ventilation.
        """
        operationMode = self.operationMode
        if operationMode['byPs']=="shut":
            actuators['byPs']=0 #                               t.b.d
        elif operationMode['byPs']=="open":
            actuators['byPs']=0 #                               t.b.d
            
        return actuators['byPs']

    
    def  execute(self,operationMode,sensors,actuators,parameters,hour,minutes):
        """
        Container to execute all sub-controls, 
        each sets its actuator new.
        Comment line out to disable any control
        """
        self.operationMode = operationMode
        self.parameters    = parameters
        actuators['solar'] = HvcControl.solar(self,sensors,actuators,hour,minutes)
        actuators['oven']  = HvcControl.oven(self,sensors,actuators,hour,minutes)
        actuators['pump']  = HvcControl.pump(self,sensors,actuators)
        actuators['vent']  = HvcControl.vent(self,sensors,actuators,hour,minutes)
        #actuators['byPs']  = HvcControl.byPs(self,sensors,actuators)

        return actuators


#persistant variables
HvcControl.downCounter=0
HvcControl.HvcTables = HvcTables()    
        
if __name__ == "__main__":
    operationMode = {} # { on / off / auto / (1,2,3) / (open/shut) }
    operationMode['solar']= "off"
    operationMode['oven'] = "off"
    operationMode['pump'] = "off"
    operationMode['vent'] = "off"
    operationMode['byPs'] = "shut"
    operationMode['opMod'] = 'winter'
    sensors   = {'coll': 44.22, 'TLow': 26.58, 'THot': 42.60, 'flow': 21.6, 'ret': 21.15, 'fire': 23.0, 'haus': 23.35, 'erde': 17.8, 'zulu': 40.27, 'ablu': 19.05, 'posBp': 252.0}
    actuators = {'solar': 0, 'oven': 0, 'pump': 0}
    hour = 00
    minutes = 00
    parameters={}
    parameters['hourSolarOff'] = 16
    hvc = HvcControl()
    print("Test: solar = off, manual")
    sensors['THot']=42
    sensors['coll']=100
    hvc.execute(operationMode,sensors,actuators,parameters,hour,minutes)
    print(actuators)
    print("=============================")
    print("Test: solar = on, manual")
    sensors['THot']=42
    sensors['coll']=42
    operationMode['solar']= "on"
    hvc.execute(operationMode,sensors,actuators,parameters,hour,minutes)
    print(actuators)
    print("=============================")
    print("Test: solar = on, auto")
    sensors['THot']=42
    sensors['coll']=100
    operationMode['solar']= "auto"
    hvc.execute(operationMode,sensors,actuators,parameters,hour,minutes)
    print(actuators)
    print("=============================")
    print("Test: solar = off, auto")
    sensors['THot']=42
    sensors['coll']=00
    operationMode['solar']= "auto"
    hvc.execute(operationMode,sensors,actuators,parameters,hour,minutes)
    print(actuators)

    

python

1HvcControl.py
2HvcHCSR04ultrasonic.py
3HvcMain.py
4HvcMotorDriver.py
5HvcOneWire.py
6HvcOperationMode.py
7HvcRaw2phys.py
8HvcReadSPI.py
9HvcSendI2C.py
10HvcSetGPIO.py
11HvcTables.py
12HvcWeather.py
13makeDoc.py

php

1HV_Admin_Login.php
2HV_colorMap.php
3HV_composeH2Oplot.php
4HV_config.php
5HV_H2Olevel.php
6HV_readOperationState.php
7HV_restart.php
8HV_serviceLog.php
9HV_setParameters.php
10HV_showHouse.php
11HV_showLog.php
12HV_showWeatherForecast.php
13HV_TempCal.php
14index.php
15readFilenames.php
16readNamedData.php

Der gesamte Sourcecode darf gemäß GNU General Public License weiterverbreitet werden.