Hamburger Hamburger

Heating and Ventilation Control

/HvcLightControl

Keine Erläuterungen gefunden.

import  datetime
from suntime import  Sun

class HvcLightControl:
    def  __init__(self, debug=False):
        self.debug = debug
        self.latitude  = 53 + 10.0/60.0 +  7.0/3600.0
        self.longitude =  8 + 37.0/60.0 + 30.0/3600.0


    def  getSunSet(self):
        timeZone = datetime.datetime.now()
        sun = Sun(self.latitude, self.longitude)
        sunRise = sun.get_local_sunrise_time(timeZone)
        sunSet = sun.get_local_sunset_time(timeZone)
        srH = sunRise.strftime('%H')
        srM = sunRise.strftime('%M')
        self.sunRise = sunRise.strftime('%H:%M')
        ssH = sunSet.strftime('%H')
        ssM = sunSet.strftime('%M')
        self.sunSet = sunSet.strftime('%H:%M')
        self.sunRiseTime = float(srH) + float(srM)/60.0
        self.sunSetTime  = float(ssH) + float(ssM)/60.0
        if self.debug:
            print("timeZone", timeZone)
            print("sunRise", sunRise)
            print("sunSet", sunSet)
            print("sunRiseTime", self.sunRiseTime)
            print("sunSetTime", self.sunSetTime)

            
        return
        
    def  exteriorLight(self, OM, switches, myTime=-1):
        opMod     = OM.operationMode
        parameter = OM.parameters
        switchOld = switches['LC1']
        anyChange = False
        if opMod["extLight"]=="on":
            switches['LC1'] = 1
        elif opMod["extLight"]=="off":
            switches['LC1'] = 0
        else:
            now   = datetime.datetime.now()
            #year  = now.strftime("%Y")
            #mon   = now.strftime("%m")
            #day   = now.strftime("%d")
            hour   = now.strftime("%H")
            minute = now.strftime("%M")
            if myTime < 0:
                myTime = float(hour) + float(minute)/60.0
            
            offTime = parameter['extLightOffTime']
            anyChange = False
            if self.debug:
                print("times", myTime, self.sunSetTime)
                print(ot,offTime,parameter['sunSetOffset'])
                print("switch old", switchOld  )
            
            if myTime > self.sunSetTime + parameter['sunSetOffset']:
                switches['LC1'] = 1
            
            if (myTime < self.sunSetTime and myTime > offTime) or myTime == offTime:
                switches['LC1'] = 0

        if abs(switches['LC1']-switchOld)>0:
            anyChange = True

        if self.debug:
            print("switch new", switches['LC1'] )
            
        return switches, anyChange


if __name__ == "__main__":
    from HvcOperationMode import   HvcOperationMode
    #parameter = {}
    #OM.parameter['sunSetOffset'] = 0.5 #h
    #OM.parameter['extLightOffTime'] = "01:00"
    
    OM = HvcOperationMode()
    newOm,parameter,changed = OM.read()
    OM.operationMode['extLight'] = 'auto'
    
    myWRactual = {}
    myWRactual['LC1'] = 0
    
    myEL = HvcLightControl(True)
    myEL.getSunSet()
    print("-------------- now")
    myWRactual, anyChange = myEL.exteriorLight(OM,myWRactual)
    print(myWRactual)
    if anyChange:
        print("some change")
    print("-------------- switch on?")
    myWRactual, anyChange = myEL.exteriorLight(OM,myWRactual,23.5)
    print(myWRactual)
    if anyChange:
        print("some change")
    print("-------------- nach Mitternacht")
    myWRactual, anyChange = myEL.exteriorLight(OM,myWRactual,0.5)
    print(myWRactual)
    if anyChange:
        print("some change")
    print("-------------- mittags")
    myWRactual, anyChange = myEL.exteriorLight(OM,myWRactual,12.5)
    print(myWRactual)
    if anyChange:
        print("some change")
    print("-------------- OM = on")
    OM.operationMode['extLight'] = 'on'
    myWRactual, anyChange = myEL.exteriorLight(OM,myWRactual,12.5)
    print('manual on',myWRactual)
    if anyChange:
        print("some change")
    print("-------------- OM off")
    OM.operationMode['extLight'] = 'off'
    myWRactual, anyChange = myEL.exteriorLight(OM,myWRactual,12.5)
    print('manual off',myWRactual)
    if anyChange:
        print("some change")

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.