Hamburger Hamburger

Heating and Ventilation Control

/HvcControl

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
            DeltaT = sensors['coll'] - sensors['TLow']
            actuators['solar'] = HvcTables.interpol( DeltaT, "solarLevel", "saturate" )
            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 night and sensors['THot']<55:
                    solarMode = "operate"
                elif not night:
                    solarMode = "operate"

            if  operationMode['opMod']=="winter":
                #let circulation cool down, when effciency gets bad in the afternoon
                if int(hour)>=self.parameters["hourSolarOff"]:
                    actuators['solar'] = 0

            elif solarMode == "coolDown":
                actuators['solar']=0.3
#                    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":
            #haus2 ist Marens Zimmer, haus3 Arnes, haus1 das Wohnzimmer
            if sensors['haus2']>self.parameters["THausSoll"]+0.5:
                actuators['pump']=0
            elif sensors['haus2']<self.parameters["THausSoll"]:
                actuators['pump']=1
            #print('pump',actuators['oven'],sensors['fire'])
            if actuators['oven']>0.5 and sensors['THot']>40:
                actuators['pump']=1
        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":
            #print('vent',actuators['oven'],sensors['fire'])
            #if actuators['oven']>0.5 and sensors['fire']>30:
            if actuators['oven']>0.5 and sensors['THot']>40:
                actuators['vent']=1.00
            #elif operationMode['opMod']=="summer":
                #time controlled
            elif actuators['pump']>0.5:
                actuators['vent']=self.parameters["ventNormal"]
            else:
                actuators['vent']=self.parameters["ventMinimal"]
            
        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, 'vent':'off'}
    hour = 00
    minutes = 00
    parameters = {'THausSoll': 22.8, 'TOfenAn': 35.0, 'TOfenAus': 60.0, 'DeltaTKollektor': 15.0, 'hourSolarOff': 15.0, 'ventMinimal': 0.27, 'ventNormal': 0.6, 'debug': 0.0}
    
    
    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)
    print("=============================")
    print("Test: vent if oven on")
    sensors['THot']=10
    sensors['fire']=60
    actuators['oven']=1.0
    operationMode['opMod']= "winter"
    operationMode['oven']= "auto"
    operationMode['pump']= "auto"
    operationMode['vent']= "auto"
    hvc.execute(operationMode,sensors,actuators,parameters,hour,minutes)
    print(actuators)

    

python

1/HvcLightControl.py
2/HvcHCSR04ultrasonic.py
3/HvcPV.py
4/HvcMotorDriver.py
5/HvcRollerShutter.py
6/manGenMqttMap.py
7/HvcReadSPI.py
8/HvcMqtt.py
9/HvcTables.py
10/HvcMain.py
11/HvcSetGPIO.py
12/HvcWifiRelay.py
13/HvcOperationMode.py
14/HvcControl.py
15/HvcRaw2phys.py
16/HvcWeather.py
17/HvcOneWire.py
18/makeDoc.py
19/HvcFronius.py
20/EnergyManager.py
21/HvcSendI2C.py

php

1/HV_colorMap.php
2/HV_Admin_Login.php
3/HV_readOperationState.php
4/HV_setParameters.php
5/HV_config.php
6/EM_handleJSON.php
7/index.php
8/readFilenames.php
9/HV_restart.php
10/HV_moveGate.php
11/HV_showLog.php
12/HV_RollerShutter.php
13/EM_editParameter.php
14/HV_serviceLog.php
15/HV_H2Olevel.php
16/HV_TempCal.php
17/HV_Fronius.php
18/EM_plot.php
19/readNamedData.php
20/HV_composeH2Oplot.php
21/HVdoc.php
22/HV_showWeatherForecast.php
23/HV_showHouse.php

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