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)
Exemplo n.º 2
0
 def execute(self, module, input):
     if getItemState("pOther_Presence_State").intValue() == PresenceHelper.STATE_AWAY and itemLastChangeOlderThen("pOther_Presence_State", ZonedDateTime.now().minusMinutes(60)) \
             and getItemState("pIndoor_Roomba_auto") == ON \
             and getItemState("pIndoor_Roomba_status").toString() == "Charging" \
             and getItemState("pIndoor_Roomba_batPct").intValue() >= 100 \
             and getItemState("pIndoor_Roomba_error") == OFF \
             and getItemState("pIndoor_Roomba_full") == OFF \
             and itemLastChangeOlderThen("pIndoor_Roomba_cleaning_state", ZonedDateTime.now().minusMinutes(360)):
         sendCommand("pIndoor_Roomba_command", "start")
Exemplo n.º 3
0
    def execute(self, module, input):
        if getItemState("pOther_Automatic_State_Outdoorlights") != ON:
            return

        if input["event"].getItemName(
        ) == "pGF_Corridor_Openingcontact_Door_State":
            if itemLastChangeOlderThen("pGF_Corridor_Motiondetector_State",
                                       ZonedDateTime.now().minusMinutes(10)):
                sendCommandIfChanged("pGF_Corridor_Light_Ceiling_Powered", ON)
        elif input["event"].getItemState().intValue(
        ) == PresenceHelper.STATE_AWAY and input["oldState"].intValue(
        ) == PresenceHelper.STATE_MAYBE_PRESENT:
            sendCommandIfChanged("pGF_Corridor_Light_Ceiling_Powered", OFF)
    def execute(self, module, input):
        if 'event' in input.keys() and input['event'].getItemName(
        ) == "pGF_Utilityroom_Ventilation_Fan_Level":
            if self.autoChangeInProgress:
                self.autoChangeInProgress = False
            else:
                postUpdate("pGF_Utilityroom_Ventilation_Auto_Mode", OFF)
            return

        if getItemState("pGF_Utilityroom_Ventilation_Auto_Mode") == OFF:
            return

        if isinstance(
                getItemState("pGF_Utilityroom_Ventilation_Fan_Level"),
                UnDefType) or isinstance(
                    getItemState(
                        "pGF_Utilityroom_Ventilation_Comfort_Temperature"),
                    UnDefType):
            return

        currentLevel = getItemState(
            "pGF_Utilityroom_Ventilation_Fan_Level").intValue()
        if self.activeLevel == -1:
            self.activeLevel = currentLevel

        raumTemperatur = getItemState(
            "pGF_Livingroom_Air_Sensor_Temperature_Value").doubleValue()
        zielTemperatur = getItemState(
            "pGF_Utilityroom_Ventilation_Comfort_Temperature").doubleValue

        presenceState = getItemState("pOther_Presence_State").intValue()

        isTooWarm = raumTemperatur >= zielTemperatur

        outdoorTemperatureItemName = getItemState(
            "pOutdoor_WeatherStation_Temperature_Item_Name").toString()
        coolingPossible = getItemState(
            outdoorTemperatureItemName).doubleValue() < raumTemperatur

        # Sleep
        if presenceState in [
                PresenceHelper.STATE_MAYBE_SLEEPING,
                PresenceHelper.STATE_SLEEPING
        ]:
            reducedLevel = 2  # Level 1
            defaultLevel = 2  # Level 1
            coolingLevel = 2  # Level 1
        # Away since 60 minutes
        elif presenceState == [
                PresenceHelper.STATE_AWAY, PresenceHelper.STATE_MAYBE_PRESENT
        ] and itemLastChangeOlderThen("pOther_Presence_State",
                                      ZonedDateTime.now().minusMinutes(60)):
            reducedLevel = 1  # Level A
            defaultLevel = 2  # Level 1
            coolingLevel = 3  # Level 2
        else:
            reducedLevel = 2  # Level 1
            defaultLevel = 3  # Level 2
            coolingLevel = 3  # Level 2

        # reducedLevel if it is too warm inside and also outside
        # coolingLevel if it is too warm inside but outside colder then inside
        newLevel = (coolingLevel if coolingPossible else
                    reducedLevel) if isTooWarm else defaultLevel

        if newLevel != currentLevel:
            # Wenn der aktuelle Level Stufe 'A' (also 1) ist, sollte vor einem erneuten umschalten gewartet werden damit ein
            # hin und herschalten vermieden wird. z.B. bei kurzzeitigen Temperaturschwankungen
            if currentLevel == 1:
                waitBeforeChange = 15
            else:
                # must be > 1. Otherwise changedSince does not work properly
                waitBeforeChange = 2

            # 1. self.activeLevel != currentLevel means last try was not successful
            # 2. 'event' in input.keys() is an presence or auto mode change
            # 3. is cron triggered event
            if self.activeLevel != currentLevel or 'event' in input.keys(
            ) or itemLastChangeOlderThen(
                    "pGF_Utilityroom_Ventilation_Fan_Level",
                    ZonedDateTime.now().minusMinutes(waitBeforeChange)):
                self.autoChangeInProgress = True

                sendCommand("pGF_Utilityroom_Ventilation_Fan_Level", newLevel)
                self.activeLevel = newLevel
Exemplo n.º 5
0
    def execute(self, module, input):

        now = ZonedDateTime.now()

        currentACPower = getItemState(
            "pGF_Garage_Solar_Inverter_AC_Power").intValue()

        currentPowerLimitation = getItemStateWithFallback(
            "pGF_Garage_Solar_Inverter_Power_Limitation",
            DecimalType(0)).intValue()

        currentConsumptionValue = getItemState(
            "pGF_Utilityroom_Electricity_Current_Consumption").intValue()
        # must be called to fill history stack
        avgConsumptionValue = self.getAvgConsumption(now,
                                                     currentConsumptionValue)

        if currentACPower > 0:
            possiblePowerLimitation = self.getPossibleLimitation(
                currentConsumptionValue)
            possibleAvgPowerLimitation = self.getPossibleLimitation(
                avgConsumptionValue)

            self.log.info(
                u"currentLimit: {}%, currentConsumption: {}W, avgConsumption: {}W, possibleLimit: {}%, possibleAvgLimit: {}%, stack: {}, li: {}"
                .format(
                    currentPowerLimitation, currentConsumptionValue,
                    avgConsumptionValue, possiblePowerLimitation,
                    possibleAvgPowerLimitation, len(self.stack),
                    ChronoUnit.MILLIS.between(self.lastLimitationIncrease,
                                              now)))

            if possiblePowerLimitation >= currentPowerLimitation:
                self.lastLimitationIncrease = now
                if possiblePowerLimitation > currentPowerLimitation:
                    sendCommand("pGF_Garage_Solar_Inverter_Power_Limitation",
                                possiblePowerLimitation)
                    self.log.info(
                        u"Increase power limitation from {}% to {}%".format(
                            currentPowerLimitation, possiblePowerLimitation))
                    return
            elif ChronoUnit.MILLIS.between(self.lastLimitationIncrease,
                                           now) > maxTimeSlot:
                if possibleAvgPowerLimitation < currentPowerLimitation:
                    sendCommand("pGF_Garage_Solar_Inverter_Power_Limitation",
                                possibleAvgPowerLimitation)
                    self.log.info(
                        u"Decrease power limitation from {}% to {}%".format(
                            currentPowerLimitation,
                            possibleAvgPowerLimitation))
                    return

            if len(input) == 0 and itemLastChangeOlderThen(
                    "pGF_Garage_Solar_Inverter_Power_Limitation",
                    ZonedDateTime.now().minusMinutes(4)):
                sendCommand("pGF_Garage_Solar_Inverter_Power_Limitation",
                            currentPowerLimitation)
                self.log.info(u"Refresh power limitation of {}%".format(
                    currentPowerLimitation))
        elif currentPowerLimitation != 100:
            postUpdate("pGF_Garage_Solar_Inverter_Power_Limitation", 100)
            self.log.info(u"Shutdown power limitation")