def execute(self, module, input): if input['event'].getItemName( ) == "pGF_Utilityroom_Washer_RemainingProgramTimeState": runtime = input['event'].getItemState() if runtime != NULL and runtime != UNDEF and runtime.intValue( ) > 0 and self.checkTimer != None: # refresh timer with additional 10 min delay as a fallback self.checkTimer = startTimer(self.log, runtime.intValue() + 600, self.notify, args=[False], oldTimer=self.checkTimer) else: prevMode = input['event'].getOldItemState().toString() if prevMode != NULL and prevMode != UNDEF: currentMode = input['event'].getItemState().toString() if currentMode == "Run": # start timer with initial 15 min delay as a fallback self.checkTimer = startTimer(self.log, 900, self.notify, args=[False], oldTimer=self.checkTimer) elif currentMode == "Finished" and self.checkTimer != None: self.checkTimer.cancel() self.notify(True)
def execute(self, module, input): if self.fallbackTimer != None: self.fallbackTimer.cancel() self.fallbackTimer = None presenceState = getItemState("pOther_Presence_State").intValue() if input['event'].getItemName( ) == "pGF_Corridor_Openingcontact_Door_State": if self.confirmTimer != None: self.confirmTimer.cancel() self.confirmTimer = None self.isConfirmed = False if input['event'].getItemState() == OPEN: if presenceState == PresenceHelper.STATE_AWAY: postUpdate("pOther_Presence_State", PresenceHelper.STATE_MAYBE_PRESENT) sendNotification(u"System", u"Unbekannter Gast gekommen") else: if presenceState == PresenceHelper.STATE_MAYBE_PRESENT: # check in 15 seconds again if there was any move events self.confirmTimer = startTimer(self.log, 15, self.confirmArriving) else: # move events during sleep, check function will be called during presence state update cycle if presenceState == PresenceHelper.STATE_SLEEPING: postUpdate("pOther_Presence_State", PresenceHelper.STATE_MAYBE_SLEEPING) elif presenceState == PresenceHelper.STATE_MAYBE_SLEEPING: self.delayedSleepingCheck() elif presenceState == PresenceHelper.STATE_MAYBE_PRESENT and self.isConfirmed: self.delayedAwayCheck()
def callbackProgress(self): if self.progressTimer is not None and self.currentProgressMsg != getItemState( "pOutdoor_Watering_Logic_Program_State").toString(): self.log.info("Cancel Watering Progress Zombie Timer") self.cleanProgressTimer() return msg, remaining = self.findStep() if remaining <= 0: self.cleanProgressTimer() return remainingInMinutes = int(math.floor(remaining / 60.0)) if remainingInMinutes > 0: msg = u"{} noch {} min".format(msg, remainingInMinutes) else: msg = u"{} gleich fertig".format(msg) self.currentProgressMsg = msg postUpdate("pOutdoor_Watering_Logic_Program_State", self.currentProgressMsg) self.progressTimer = startTimer(self.log, 60.0, self.callbackProgress)
def execute(self, module, input): if getItemState("pOther_Manual_State_Auto_Rollershutter") != ON: return if self.awayTimer != None: self.awayTimer.cancel() self.awayTimer = None if getItemState("pOther_Automatic_State_Rollershutter").intValue() in [ SunProtectionHelper.STATE_ROLLERSHUTTER_DOWN, SunProtectionHelper.STATE_ROLLERSHUTTER_MAYBE_UP ]: return if input['event'].getItemState().intValue( ) == PresenceHelper.STATE_AWAY: self.presenceTimer = startTimer(self.log, 1800, self.updateCallback, args=[DOWN]) elif input['event'].getItemState().intValue( ) == PresenceHelper.STATE_PRESENT and input['event'].getOldItemState( ).intValue() in [ PresenceHelper.STATE_AWAY, PresenceHelper.STATE_MAYBE_PRESENT ]: self.updateCallback(UP)
def execute(self, module, input): itemName = input['event'].getItemName() # was it a raw trigger? if itemName in self.rawMappings: rawItemName = self.rawMappings[itemName] entry = rawItems[rawItemName] if not self.processRawValue( rawItemName, input['event'].getItemState(), entry[1], entry[2]): return data = infoConfig[self.triggerMappings[itemName]] #self.log.info(u">>>trigger: {} ".format(data[0])) # group 2 value updates into one message update # we have to delay 4 seconds, because sensor delay between 2 values is 3 seconds self.updateTimer[data[0]] = startTimer( self.log, 4, self.updateInfoMessage, args=[data[0], data[1], data[2], data[3], data[4]], oldTimer=self.updateTimer[data[0]], groupCount=2)
def execute(self, module, input): itemName = input['event'].getItemName() itemState = input['event'].getItemState() # sometimes, phones are losing wifi connections because of their sleep mode if itemState == OFF: if itemLastChangeOlderThen( "pGF_Corridor_Openingcontact_Door_State", ZonedDateTime.now().minusMinutes(30)): self.skippedTimer[itemName] = startTimer( self.log, 7200, self.process, args=[itemName, itemState]) # 1 hour sendNotification( u"System", u"Delayed presence processing {} for {}".format( itemState, itemName), recipients=['bot_holger']) return else: if itemName in self.skippedTimer: self.skippedTimer[itemName].cancel() del self.skippedTimer[itemName] sendNotification( u"System", u"Cancel presence processing {} for {}".format( itemState, itemName), recipients=['bot_holger']) return self.process(itemName, itemState)
def execute(self, module, input): # we don't want do be notified if getItemState("pOther_Manual_State_Air_Thoroughly_Notify") != ON: return if 'event' in input: if self.timer != None: self.timer.cancel() self.timer = None if input['event'].getItemState().intValue( ) == PresenceHelper.STATE_PRESENT and input[ 'event'].getOldItemState().intValue() in [ PresenceHelper.STATE_AWAY, PresenceHelper.STATE_MAYBE_PRESENT ]: # delayed notification to give all devices the chance to be detected as present self.timer = startTimer( self.log, 60, self.process, args=[PresenceHelper.getPresentRecipients()]) # 1 min else: # we are away if getItemState("pOther_Presence_State").intValue() in [ PresenceHelper.STATE_AWAY, PresenceHelper.STATE_MAYBE_PRESENT ]: return # recipients will be selected only if there are state changes recipients = None self.process(recipients)
def delayedSleepingCheck(self): presenceState = getItemState("pOther_Presence_State").intValue() if presenceState != PresenceHelper.STATE_MAYBE_SLEEPING: return if self.fallbackTimer == None or getItemState("gIndoor_Lights") == ON: self.fallbackTimer = startTimer( self.log, 600, self.delayedSleepingCheck) # 10 min else: lastUpdateDiff = ChronoUnit.SECONDS.between( getItemLastUpdate("gIndoor_Lights"), ZonedDateTime.now()) if lastUpdateDiff >= 600: self.setSleeping() else: self.fallbackTimer = startTimer( self.log, 600 - lastUpdateDiff, self.delayedSleepingCheck) # 10 min
def execute(self, module, input): if input['event'].getItemName( ) == "pOutdoor_Weather_Forecast_Temperature_4h": self.delayUpdate() else: self.updateTimer = startTimer(self.log, DELAYED_UPDATE_TIMEOUT, self.delayUpdate, oldTimer=self.updateTimer, groupCount=len(self.triggers) - 1)
def callbackFaded(self, step, data): if getItemState("pOther_Manual_State_Lightprogram").intValue() == 0: return color1, color2, color3, color4, color5 = data if step == self.fadingSteps: newColor1 = color2 newColor2 = color3 newColor3 = color4 newColor4 = color5 newColor5 = color1 else: currentColor1, currentColor2, currentColor3, currentColor4, currentColor5 = self._getCurrentColors( ) newColor1 = self._fade(step, color1, color2, currentColor1) newColor2 = self._fade(step, color2, color3, currentColor2) newColor3 = self._fade(step, color3, color4, currentColor3) newColor4 = self._fade(step, color4, color5, currentColor4) newColor5 = self._fade(step, color5, color1, currentColor5) self.log.info(u"{} - 1 {}, from {} => {}".format( step, newColor1, color1, color2)) self.log.info(u"{} - 2 {}, from {} => {}".format( step, newColor2, color2, color3)) self.log.info(u"{} - 3 {}, from {} => {}".format( step, newColor3, color3, color4)) self.log.info(u"{} - 4 {}, from {} => {}".format( step, newColor4, color4, color5)) self.log.info(u"{} - 5 {}, from {} => {}".format( step, newColor5, color5, color1)) self._setCurrentColors( [newColor1, newColor2, newColor3, newColor4, newColor5]) if step < self.fadingSteps: self.timer = startTimer(self.log, self.timeout, self.callbackFaded, [step + 1, data]) else: self.timer = startTimer(self.log, self.timeout, self.callbackFaded, [1, self._getCurrentColors()])
def execute(self, module, input): if self.timer != None: self.timer.cancel() self.timer = None if self.orgColors != None: self._setCurrentColors(self.orgColors) self.orgColors = None itemState = input["event"].getItemState().intValue() if itemState > 0: self.orgColors = self._getCurrentColors() if itemState == 1: self.timer = startTimer(self.log, 1, self.callback) elif itemState == 2: self.timer = startTimer(self.log, 1, self.callbackFaded, [1, self.orgColors])
def execute(self, module, input): if self.timer is not None: self.timer.cancel() self.timer = None #self.log.info("{}".format(input["newState"])) if input["newState"] == ON: sendCommand("pOutdoor_Streedside_Gardendoor_Opener_Powered", ON) self.timer = startTimer(self.log, 3.0, self.callback) else: sendCommandIfChanged( "pOutdoor_Streedside_Gardendoor_Opener_Powered", OFF)
def execute(self, module, input): if self.timer != None: self.timer.cancel() self.timer = None if input['event'].getItemState().intValue() in [ PresenceHelper.STATE_AWAY, PresenceHelper.STATE_SLEEPING ]: self.sleep() else: self.wakeup() if input['event'].getItemState().intValue( ) != PresenceHelper.STATE_PRESENT: self.timer = startTimer(self.log, 600, self.delayedSleep) # 10 min
def execute(self, module, input): # only possible if we are sleeping if getItemState("pOther_Presence_State").intValue() in [ PresenceHelper.STATE_MAYBE_SLEEPING, PresenceHelper.STATE_SLEEPING ]: # sometimes the "gGF_Lights" state switches back and forth for a couple of milliseconds when set "gGF_Lights" state to OFF #if itemLastChangeOlderThen("pOther_Presence_State",ZonedDateTime.now().minusSeconds(5)): if input['event'].getItemName() == "gGF_Shutters": if self.checkTimer != None: self.checkTimer.cancel() self.checkTimer = None self.wakeup() else: self.checkTimer = startTimer(self.log, 30, self.delayedWakeup, args=[0], oldTimer=self.checkTimer)
def execute(self, module, input): itemName = input['event'].getItemName() entry = manualMappings[self.triggerMappings[itemName]] if getItemState("pOther_Automatic_State_Outdoorlights" ) == ON and getItemState(entry[1]) == ON: timerMappings[entry[0]] = startTimer(self.log, timerDuration, self.callback, [entry], oldTimer=timerMappings.get( entry[0])) global ruleTimeouts ruleTimeouts["Light_Outdoor"] = ZonedDateTime.now() self.log.info(u"MotionDetectorRule: execute for {} => {}".format( entry[0], ruleTimeouts["Light_Outdoor"])) sendCommand(entry[0], 100 if getItem(entry[0]).getType() == "Dimmer" else ON)
def callback(self, entry): global timerMappings if getItemState(entry[1]) == ON: for motionDetectorItem in entry[2]: if getItemState(motionDetectorItem) == OPEN: timerMappings[entry[0]] = startTimer( self.log, timerDuration, self.callback, [entry]) return global ruleTimeouts ruleTimeouts["Light_Outdoor"] = ZonedDateTime.now() self.log.info(u"MotionDetectorRule: callback for {} => {}".format( entry[0], ruleTimeouts["Light_Outdoor"])) sendCommand(entry[0], 0 if getItem(entry[0]).getType() == "Dimmer" else OFF) timerMappings[entry[0]] = None else: timerMappings[entry[0]] = None
def callback(self): if getItemState("pOther_Manual_State_Lightprogram").intValue() == 0: return color1 = getItemState("pGF_Livingroom_Light_Hue1_Color") color2 = getItemState("pGF_Livingroom_Light_Hue2_Color") color3 = getItemState("pGF_Livingroom_Light_Hue3_Color") color4 = getItemState("pGF_Livingroom_Light_Hue4_Color") color5 = getItemState("pGF_Livingroom_Light_Hue5_Color") global ruleTimeouts ruleTimeouts["Livingroom_Hue_Color_Backward"] = ZonedDateTime.now() sendCommand("pGF_Livingroom_Light_Hue1_Color", color2) sendCommand("pGF_Livingroom_Light_Hue2_Color", color3) sendCommand("pGF_Livingroom_Light_Hue3_Color", color4) sendCommand("pGF_Livingroom_Light_Hue4_Color", color5) sendCommand("pGF_Livingroom_Light_Hue5_Color", color1) self.timer = startTimer(self.log, self.timeout, self.callback)
def delayedWakeup(self, checkCounter): if getItemState("gGF_Lights") == ON: if getItemState("pOther_Presence_State").intValue() in [ PresenceHelper.STATE_MAYBE_SLEEPING, PresenceHelper.STATE_SLEEPING ]: lightCount = 0 for child in getGroupMember("gGF_Lights"): if child.getStateAs(OnOffType) == ON: lightCount = lightCount + 1 # Signs (in first floor) for wake up are # - a light is ON for more then 10 minutes # - or more then 2 lights in total are ON if checkCounter == 20 or lightCount > 2: self.checkTimer = None self.wakeup() else: self.checkTimer = startTimer(self.log, 30, self.delayedWakeup, args=[checkCounter + 1], oldTimer=self.checkTimer) else: self.checkTimer = None
def execute(self, module, input): self.updateTimer = startTimer(self.log, DELAYED_UPDATE_TIMEOUT, self.delayUpdate, oldTimer=self.updateTimer, groupCount=len(self.triggers))
def delayedAwayCheck(self): self.fallbackTimer = startTimer(self.log, 7200, self.setAway, args=[True]) # 1 hour