Example #1
0
    def execute(self, module, input):
        global ruleTimeouts
        now = getNow().getMillis()
        last = ruleTimeouts.get("Motiondetector_Outdoor_Main_Switch", 0)

        if now - last > 1000:
            itemState = input["event"].getItemState()

            if itemState == ON:
                ruleTimeouts["Light_Outdoor"] = now

                sendCommandIfChanged("Light_Outdoor_Garage_Streedside", OFF)
                sendCommandIfChanged("Light_Outdoor_Frontdoor", OFF)
                sendCommandIfChanged("Light_Outdoor_Carport", OFF)
                sendCommandIfChanged("Light_Outdoor_Terrace", 0)
                sendCommandIfChanged("Light_Outdoor_Garage_Gardenside", OFF)

            #ruleTimeouts["Motiondetector_Outdoor_Individual_Switches"] = now
            postUpdateIfChanged(
                "Motiondetector_Outdoor_Garage_Streetside_Switch", itemState)
            postUpdateIfChanged("Motiondetector_Outdoor_Frontdoor_Switch",
                                itemState)
            postUpdateIfChanged("Motiondetector_Outdoor_Carport_Switch",
                                itemState)
            postUpdateIfChanged("Motiondetector_Outdoor_Terrace_Switch",
                                itemState)
            postUpdateIfChanged(
                "Motiondetector_Outdoor_Garage_Gardenside_Switch", itemState)
Example #2
0
    def execute(self, module, input):
        #self.log.info(u"{}".format(input))

        global ruleTimeouts
        now = getNow().getMillis()
        last = ruleTimeouts.get("Light_Outdoor", 0)

        # No Motion Detector related events
        if now - last > 1000:
            itemName = input['event'].getItemName()

            global timerMappings
            timer = timerMappings.get(itemName)
            if timer is not None:
                timer.cancel()

            for i, entry in enumerate(manualMappings):
                if entry[0] == itemName:
                    #ruleTimeouts["Motiondetector_Outdoor_Individual_Switches"] = now
                    if postUpdateIfChanged(entry[1], OFF):
                        ruleTimeouts[
                            "Motiondetector_Outdoor_Main_Switch"] = now

                        # must be a command to inform physical knx switch
                        sendCommandIfChanged("Motiondetector_Outdoor_Switch",
                                             OFF)
                    #self.log.info(u"{} {}".format(itemName,now-last))
                    break
Example #3
0
    def execute(self, module, input):
        now = getNow()
        for room in filter( lambda room: room.getHeatingVolume() != None and room.getName() in controllableRooms,Heating.getRooms()):
            circuiteItem = Heating.getHeatingCircuitItem(room)
            maintainanceModeActive = room in maintenanceMode

            if maintainanceModeActive or itemLastUpdateOlderThen(circuiteItem,now.minusHours(24)):
                hour = now.getHourOfDay()
                if hour == 2 or getItemState(circuiteItem) == OFF:
                    postUpdateIfChanged(circuiteItem,ON)
                else:
                    postUpdateIfChanged(circuiteItem,OFF)
                    
                if room.hasAdditionalRadiator():
                    hkItem = Heating.getHeatingHKItem(room)
                    if hour == 2 or getItemState(hkItem) == OFF:
                        sendCommandIfChanged(hkItem,ON)
                    else:
                        sendCommandIfChanged(hkItem,OFF)
                
                if hour == 2:
                    del maintenanceMode[room]
                elif not maintainanceModeActive:
                    maintenanceMode[room] = True
Example #4
0
    def execute(self, module, input):
        global ruleTimeouts
        now = getNow().getMillis()

        #last = ruleTimeouts.get("Motiondetector_Outdoor_Individual_Switches",0)
        #if now - last > 1000:
        ruleTimeouts["Motiondetector_Outdoor_Main_Switch"] = now
        ruleTimeouts["Light_Outdoor"] = now

        itemName = input['event'].getItemName()
        itemCommand = input['event'].getItemCommand()

        switchState = ON
        for i, entry in enumerate(manualMappings):
            if entry[1] == itemName:
                sendCommandIfChanged(entry[0], OFF)
                if itemCommand == OFF:
                    switchState = OFF
            else:
                if getItemState(entry[1]) == OFF:
                    switchState = OFF

        # must be a command to inform physical knx switch
        sendCommandIfChanged("Motiondetector_Outdoor_Switch", switchState)
Example #5
0
    def execute(self, module, input):
        self.log.info(u"--------: >>>" )

        now = getNow()
        autoModeEnabled = getItemState("Heating_Auto_Mode").intValue() == 1
        currentOperatingMode = getItemState("Heating_Operating_Mode").intValue()
        currentHeatingDemand = getItemState("Heating_Demand")

        heating = Heating(self.log)
        cr, hhs = heating.calculate(currentHeatingDemand == ON)    
        
        if autoModeEnabled:
            heatingRequested = hhs.isHeatingRequested()
            
            # *** CHECK OPEN WINDOWS AND MIN HEATING VOLUME ***
            disabledHeatingDemandCount = 0
            requestedPossibleHeatingVolume = 0.0
            for room in filter( lambda room: room.getHeatingVolume() != None,Heating.getRooms()):
            
                rs = cr.getRoomState(room.getName())
                rhs = hhs.getHeatingState(room.getName())

                # *** CHECKED HEATING DEMAND ***
                if rhs.hasLongOpenWindow():
                    disabledHeatingDemandCount = disabledHeatingDemandCount + 1
            
                if rhs.getHeatingDemandTime() != None and rhs.getHeatingDemandTime() > 0.0:
                    requestedPossibleHeatingVolume = requestedPossibleHeatingVolume + rs.getPossibleHeatingVolume()
                
            if heatingRequested:
                # *** FORCED HEATING OFF ***
                if disabledHeatingDemandCount >= 3:
                    heatingRequested = False
                    self.log.info(u"        : ---")
                    self.log.info(u"        : Heating OFF • too many open windows")
                    
                # *** FORCED HEATING OFF IF ONLY 20%***
                if requestedPossibleHeatingVolume < Heating.totalHeatingVolume * 0.2:
                    heatingRequested = False
                    activeHeatingVolume = round(requestedPossibleHeatingVolume / 1000.0,3)
                    possibleHeatingVolume = round(Heating.totalHeatingVolume / 1000.0,3)
                    self.log.info(u"        : ---")
                    self.log.info(u"        : Heating OFF • only {}m² of {}m² active".format(activeHeatingVolume,possibleHeatingVolume))
                # *************************************************


            # *** PERSIST AND CIRCUITS ************************
            longestRuntime = 0
            lastCircuitOpenedAt = None
            for room in filter( lambda room: room.getHeatingVolume() != None,Heating.getRooms()):
                
                rs = cr.getRoomState(room.getName())
                rhs = hhs.getHeatingState(room.getName())
                
                # *** PERSIST HEATING CHARGE LEVEL ***
                totalChargeLevel = rs.getChargedBuffer()
                postUpdateIfChanged( Heating.getHeatingBufferItem(room), totalChargeLevel )
                
                # *** PERSIST HEATING TARGET TEMPERATURE ***
                postUpdateIfChanged(Heating.getHeatingTargetTemperatureItem(room), rhs.getHeatingTargetTemperature() )
                
                if heatingRequested and rhs.getHeatingDemandTime() > longestRuntime:
                    longestRuntime = rhs.getHeatingDemandTime()

                # *** PERSIST HEATING DEMAND ***
                if heatingRequested and (rhs.getHeatingDemandTime() > 0 or room.getName() not in controllableRooms):
                    postUpdateIfChanged(Heating.getHeatingDemandItem(room),ON)
                else:
                    postUpdateIfChanged(Heating.getHeatingDemandItem(room),OFF)
                    
                # *** CONTROL CIRCUITS AND HK ***
                if room.getName() in controllableRooms and room not in maintenanceMode:
                    circuitItem = Heating.getHeatingCircuitItem(room)
                    if heatingRequested and rhs.getHeatingDemandTime() > 0:
                        #self.log.info("ON")
                        if sendCommandIfChanged(circuitItem,ON):
                            circuitLastChange = now
                        else:
                            circuitLastChange = getItemLastUpdate(circuitItem)
                            
                        if lastCircuitOpenedAt == None or lastCircuitOpenedAt.getMillis() < circuitLastChange.getMillis():
                            lastCircuitOpenedAt = circuitLastChange                            
                    else:
                        #self.log.info("OFF")
                        sendCommandIfChanged(circuitItem,OFF)
                        
                    # wall radiator
                    if room.hasAdditionalRadiator():
                        # additional radiator should only be enabled in case of CF heating
                        if heatingRequested and rhs.getForcedInfo() == 'CF':
                            sendCommandIfChanged(Heating.getHeatingHKItem(room),ON)
                        else:
                            sendCommandIfChanged(Heating.getHeatingHKItem(room),OFF)
            # *************************************************
            
            
            self.log.info(u"        : ---" )
            
            # a heating ciruit was opened less then 5 minutes ago.
            # delay heating request to give circuit some time to open
            if currentHeatingDemand == OFF and lastCircuitOpenedAt != None and now.getMillis() - lastCircuitOpenedAt.getMillis() < 5 * 60 * 1000:
                #self.log.info(u"{}".format(lastCircuitOpenedAt))
                openedBeforeInMinutes = int( round( ( now.getMillis() - lastCircuitOpenedAt.getMillis() ) / 1000.0 / 60.0 ) )
                self.log.info(u"Demand  : DELAYED • circuit was opened {} min. ago".format(openedBeforeInMinutes))
            else:
                heatingDemand = ON if heatingRequested else OFF
                postUpdateIfChanged("Heating_Demand", heatingDemand )
            
                endMsg = u" • {} min. to go".format(Heating.visualizeHeatingDemandTime(longestRuntime)) if longestRuntime > 0 else u""
                lastHeatingDemandChange = getItemLastUpdate("Heating_Demand")
                lastUpdateBeforeInMinutes = int( round( ( now.getMillis() - lastHeatingDemandChange.getMillis() ) / 1000.0 / 60.0 ) )
                lastHeatingChangeFormatted = OFFSET_FORMATTER.print(lastHeatingDemandChange)
                lastUpdateBeforeFormatted = lastUpdateBeforeInMinutes if lastUpdateBeforeInMinutes < 60 else '{:02d}:{:02d}'.format(*divmod(lastUpdateBeforeInMinutes, 60));
                self.log.info(u"Demand  : {} since {} • {} min. ago{}".format(heatingDemand, lastHeatingChangeFormatted, lastUpdateBeforeFormatted,endMsg) )
                
                self.controlHeating(now,currentOperatingMode,heatingRequested)  
        else:
            self.log.info(u"Demand  : SKIPPED • MANUAL MODE ACTIVE")

        self.setSunStates(cr,hhs)
        
        self.log.info(u"--------: <<<" )
 def execute(self, module, input):
     sendCommandIfChanged("Lights_Indoor", OFF)
     sendCommandIfChanged("Motiondetector_Outdoor_Switch", ON)
     sendCommandIfChanged("Socket_Livingroom_Fireplace", OFF)