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()
Example #2
0
    def execute(self, module, input):
        moverStatus = getItemState("pOutdoor_Mower_Status").toString()

        if itemLastUpdateOlderThen("pOutdoor_Mower_WlanSignal",
                                   ZonedDateTime.now().minusMinutes(60)):
            if moverStatus != "98":
                postUpdate("pOutdoor_Mower_Status", 98)
                postUpdate(
                    "pOutdoor_Mower_StatusFormatted",
                    Transformation.transform("MAP", "robonect_status.map",
                                             "98"))
        else:
            seconds = getItemState("pOutdoor_Mower_Duration").intValue()
            hours = seconds / (60 * 60)
            seconds = seconds % (60 * 60)
            minutes = seconds / 60
            #seconds = seconds % 60

            msg = u"{} seit ".format(
                Transformation.transform("MAP", "robonect_status.map",
                                         moverStatus))
            if hours < 10: msg = u"{}0".format(msg)
            msg = u"{}{}:".format(msg, hours)
            if minutes < 10: msg = u"{}0".format(msg)
            msg = u"{}{}:".format(msg, minutes)

            postUpdateIfChanged("pOutdoor_Mower_StatusFormatted", msg)
Example #3
0
    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)
Example #4
0
    def execute(self, module, input):
        sendCommand("pGF_Corridor_Light_Ceiling_Powered", ON)
        sendCommand("pFF_Bathroom_Light_Ceiling_Powered", ON)
        sendCommand("pFF_Bathroom_Light_Mirror_Powered", ON)
        sendCommand("pFF_Bedroom_Light_Ceiling_Powered", ON)

        postUpdate("pOther_Scene2", OFF)
Example #5
0
    def execute(self, module, input):
        sendCommand("pOutdoor_Carport_Automatic_Switch", OFF)
        sendCommand("pOutdoor_Streedside_Frontdoor_Automatic_Switch", OFF)
        sendCommand("pOutdoor_Terrace_Automatic_Switch", OFF)
        sendCommand("pOutdoor_Streedside_Garage_Automatic_Switch", OFF)
        sendCommand("pOutdoor_Garden_Garage_Automatic_Switch", ON)

        postUpdate("pOther_Scene5", OFF)
Example #6
0
    def execute(self, module, input):
        global ruleTimeouts
        now = ZonedDateTime.now()
        last = ruleTimeouts.get("Livingroom_Hue_Color_Backward", now)

        if ChronoUnit.SECONDS.between(last, now) > 1:
            postUpdate("pGF_Livingroom_Light_Hue_Scene", "")
            sendCommand("pOther_Manual_State_Lightprogram", 0)
    def execute(self, module, input):
        if itemStateOlderThen(
                "pOutdoor_Streedside_Gardendoor_Bell_Last_Change",
                ZonedDateTime.now().minusSeconds(30)):
            sendNotification("Klingel", "Es klingelt",
                             "https://smartmarvin.de/cameraStrasseImage")

        postUpdate("pOutdoor_Streedside_Gardendoor_Bell_Last_Change",
                   DateTimeType())
Example #8
0
    def execute(self, module, input):
        if getItemState("TV_Online") == ON:
            if input["command"] == OFF:
                sendCommand("TV_Online", OFF)
        else:
            if input["command"] == ON:
                sendCommand("TV_Online", ON)

        postUpdate("pOther_Scene6", OFF)
    def execute(self, module, input):
        # only possible if we are present
        if getItemState("pOther_Presence_State").intValue() in [
                PresenceHelper.STATE_MAYBE_PRESENT,
                PresenceHelper.STATE_PRESENT,
                PresenceHelper.STATE_MAYBE_SLEEPING
        ]:
            postUpdate("pOther_Presence_State", PresenceHelper.STATE_SLEEPING)

        postUpdate("pOther_Scene4", OFF)
Example #10
0
 def execute(self, module, input):
     state = input['event'].getItemState()
     # self.log.info(u"tel 0: {}".format(state.getValue(0)))
     # self.log.info(u"tel 1: {}".format(state.getValue(1)))
     if type(state) is StringListType and itemStateOlderThen(
             "Gardendoor_Bell_Last_Change",
             getNow().minusSeconds(30)) and state.getValue(1) == '99999999':
         sendNotification("Klingel", "Es klingelt",
                          "https://bolle.haus/cameraStrasseImage")
         postUpdate("Gardendoor_Bell_Last_Change", DateTimeType())
Example #11
0
    def findStep(self):
        duration = getItemState(
            "pOutdoor_Watering_Logic_Program_Duration").intValue() * 60.0

        remaining = 0
        info = u""

        # detect current active index
        activeIndex = -1
        for i in range(len(circuits)):
            group = circuits[i]
            if getItemState(group[2][0] + "_Powered") == ON:
                activeIndex = i
                runtime = ChronoUnit.SECONDS.between(
                    getItemLastChange(group[2][0] + "_Powered"),
                    ZonedDateTime.now())
                remaining = (duration * group[0]) - runtime
                break

        if remaining <= 0:
            nextIndex = -1

            # detect next index
            for i in range(len(circuits)):
                if activeIndex != -1 and i <= activeIndex:
                    continue
                group = circuits[i]
                for circuit in group[2]:
                    if getItemState(circuit + "_Auto") == ON:
                        nextIndex = i
                        break
                if nextIndex != -1:
                    break

            if nextIndex == -1:
                self.disableAllCircuits()
                postUpdate("pOutdoor_Watering_Logic_Program_Start", OFF)
            else:
                for circuit in circuits[nextIndex][2]:
                    if getItemState(circuit + "_Auto") == ON:
                        sendCommand(circuit + "_Powered", ON)

                nextGroup = circuits[nextIndex]

                remaining = (duration * nextGroup[0])
                info = nextGroup[1]

                # deactivate current index
                if activeIndex != -1:
                    for circuit in circuits[activeIndex][2]:
                        sendCommand(circuit + "_Powered", OFF)
        else:
            info = circuits[activeIndex][1]

        return [info, remaining]
Example #12
0
    def execute(self, module, input):
        now = ZonedDateTime.now()

        supplyCurrent = getItemState(
            "pGF_Utilityroom_Energy_Supply_Active").intValue() / 1000.0
        zaehlerStandCurrent = (startEnergyTotalSupplyValue + supplyCurrent)
        postUpdateIfChanged("pGF_Utilityroom_Electricity_Total_Supply",
                            zaehlerStandCurrent)

        postUpdateIfChanged(
            "pGF_Utilityroom_Electricity_Meter_Supply",
            zaehlerStandCurrent - startElectricityMeterSupplyValue)

        # *** Tageslieferung ***
        zaehlerStandOld = getHistoricItemState(
            "pGF_Utilityroom_Electricity_Total_Supply",
            now.toLocalDate().atStartOfDay(now.getZone())).doubleValue()
        currentSupply = zaehlerStandCurrent - zaehlerStandOld

        postUpdateIfChanged("pGF_Utilityroom_Electricity_Current_Daily_Supply",
                            currentSupply)
        # *** Jahreslieferung ***

        refDay = now.withYear(now.getYear()).withMonth(1).withDayOfMonth(1)
        zaehlerStandOld = getHistoricItemState(
            "pGF_Utilityroom_Electricity_Total_Supply",
            refDay.toLocalDate().atStartOfDay(refDay.getZone())).doubleValue()
        currentSupply = zaehlerStandCurrent - zaehlerStandOld

        if postUpdateIfChanged(
                "pGF_Utilityroom_Electricity_Current_Annual_Supply",
                currentSupply):
            # Hochrechnung
            zaehlerStandCurrentOneYearBefore = getHistoricItemState(
                "pGF_Utilityroom_Electricity_Total_Supply",
                now.minusYears(1)).doubleValue()
            forecastSupply = zaehlerStandOld - zaehlerStandCurrentOneYearBefore

            refDay = now.withYear(now.getYear() -
                                  1).withMonth(1).withDayOfMonth(1)
            zaehlerStandOldOneYearBefore = getHistoricItemState(
                "pGF_Utilityroom_Electricity_Total_Supply",
                refDay.toLocalDate().atStartOfDay(
                    refDay.getZone())).doubleValue()

            hochrechnungSupply = int(round(currentSupply + forecastSupply))
            vorjahresSupply = int(
                round(zaehlerStandOld - zaehlerStandOldOneYearBefore))
            msg = u"{}kWh, {} kWh".format(hochrechnungSupply, vorjahresSupply)
            postUpdate(
                "pGF_Utilityroom_Electricity_Current_Annual_Supply_Forecast",
                msg)
Example #13
0
    def execute(self, module, input):
        reference_duration = getItemState(
            "pOutdoor_Watering_Logic_Program_Duration").intValue()

        for i in range(len(circuits)):
            for circuit in circuits[i][2]:
                if getItemState(circuit + "_Auto") == ON:
                    duration = (circuits[i][0] * reference_duration)
                    duration = int(math.floor(duration))

                    postUpdate(circuit + "_Info", u"{} min.".format(duration))
                else:
                    postUpdate(circuit + "_Info", u"inaktiv")
 def execute(self, module, input):
     refDay = ZonedDateTime.now()
     start = getHistoricItemState(
         "pGF_Utilityroom_Heating_Solar_Power",
         refDay.toLocalDate().atStartOfDay(refDay.getZone())).intValue()
     aktuell = getItemState(
         "pGF_Utilityroom_Heating_Solar_Power").intValue()
     if start > 0 and aktuell > 0:
         differenz = aktuell - start
         postUpdate("pGF_Utilityroom_Heating_Solar_Power_Current_Daily",
                    differenz)
         msg = u"{} KW, {} KW".format(differenz, aktuell)
         postUpdateIfChanged("pGF_Utilityroom_Heating_Solar_Power_Message",
                             msg)
Example #15
0
    def execute(self, module, input):
        sendCommand("gGF_Livingroom_Light_Hue_Color", 60)

        states = [OFF, PercentType.ZERO]

        for child in getItem("gGF_Lights").getAllMembers():
            if child.getState() not in states and child.getName(
            ) != "gGF_Livingroom_Light_Hue_Color":
                sendCommand(child, OFF)

        for child in getItem("gFF_Lights").getAllMembers():
            if child.getState() not in states:
                sendCommand(child, OFF)

        postUpdate("pOther_Scene1", OFF)
    def process(self, itemName, itemState):
        presenceState = getItemState("pOther_Presence_State").intValue()

        #sendNotificationToAllAdmins(u"{}".format(itemName), u"{}".format(itemState))

        holgerPhone = itemState if itemName == "pOther_Presence_Holger_State" else getItemState(
            "pOther_Presence_Holger_State")
        sandraPhone = itemState if itemName == "pOther_Presence_Sandra_State" else getItemState(
            "pOther_Presence_Sandra_State")

        bot = PresenceHelper.getRecipientByStateItem(itemName)

        if holgerPhone == ON or sandraPhone == ON:
            # only possible if we are away
            if presenceState in [
                    PresenceHelper.STATE_AWAY,
                    PresenceHelper.STATE_MAYBE_PRESENT
            ]:
                postUpdate("pOther_Presence_State",
                           PresenceHelper.STATE_PRESENT)
        else:
            # only possible if we are present and not sleeping
            if presenceState in [
                    PresenceHelper.STATE_MAYBE_PRESENT,
                    PresenceHelper.STATE_PRESENT
            ]:
                postUpdate("pOther_Presence_State", PresenceHelper.STATE_AWAY)

        if itemState == ON:
            sendNotification(u"System", u"Willkommen", recipients=[bot])
        else:
            if holgerPhone == OFF and sandraPhone == OFF:
                lightMsg = u" - LICHT an" if getItemState(
                    "gIndoor_Lights") != OFF else u""
                windowMsg = u" - FENSTER offen" if getItemState(
                    "gOpeningcontacts") != CLOSED else u""
                sendNotification(u"System",
                                 u"Auf Wiedersehen{}{}".format(
                                     lightMsg, windowMsg),
                                 recipients=[bot])
            else:
                sendNotification(u"System",
                                 u"Auf Wiedersehen",
                                 recipients=[bot])
Example #17
0
    def execute(self, module, input):
        sendCommand("pGF_Corridor_Light_Hue_Color", 60)
        sendCommand("pFF_Bathroom_Light_Ceiling_Powered", ON)
        sendCommand("pFF_Bathroom_Light_Mirror_Powered", ON)
        sendCommand("pFF_Bedroom_Light_Hue_Right_Switch", ON)

        states = [OFF, PercentType.ZERO]

        for child in getItem("gGF_Lights").getAllMembers():
            if child.getState() not in states and child.getName(
            ) != "pGF_Corridor_Light_Hue_Color":
                sendCommand(child, OFF)

        #for child in getItem("gFF_Lights").getAllMembers():
        #    if child.getState() not in states and child.getName() not in ["pFF_Bathroom_Light_Mirror_Powered", "pFF_Bedroom_Light_Hue_Right_Switch"]:
        #        sendCommand(child, OFF)

        sendCommand("pOther_Scene6", ON)
        postUpdate("pOther_Scene3", OFF)
Example #18
0
    def execute(self, module, input):
        global ruleTimeouts
        ruleTimeouts["Livingroom_Hue_Color_Backward"] = ZonedDateTime.now()

        command = input['event'].getItemCommand()

        #colors = command.toString().split(",")

        #red = round(float(colors[0]))
        #green = round(float(colors[1]))
        #blue = round(float(colors[1]))

        #command = u"{},{},{}".format(red,green,blue)

        sendCommand("pGF_Livingroom_Light_Hue1_Color", command)
        sendCommand("pGF_Livingroom_Light_Hue2_Color", command)
        sendCommand("pGF_Livingroom_Light_Hue3_Color", command)
        sendCommand("pGF_Livingroom_Light_Hue4_Color", command)
        sendCommand("pGF_Livingroom_Light_Hue5_Color", command)

        postUpdate("pGF_Livingroom_Light_Hue_Scene", "")
        sendCommand("pOther_Manual_State_Lightprogram", 0)
    def execute(self, module, input):
        if 'event' not in input:
            self.processor = CommandProcessor(self.log, ir)
            Tests.process(self.processor, self.log, ir)
            #self.log.info(u"{}".format(input))
        else:
            postUpdate("VoiceMessage", "")

            voice_command, client_id = self.processor.parseData(
                input['event'].getItemState().toString())
            fallback_location_name = AlexaDevices[
                client_id] if client_id in AlexaDevices else None

            self.log.info(u"Process: '{}', Location: '{}'".format(
                voice_command, client_id
                if fallback_location_name is None else fallback_location_name))

            actions = self.processor.process(voice_command,
                                             fallback_location_name)

            msg, is_valid = self.processor.applyActions(
                actions, voice_command, False)

            postUpdate("VoiceMessage", msg)
Example #20
0
 def disableAllCircuits(self):
     for child in getGroupMember("gOutdoor_Watering_Circuits"):
         sendCommand(child, OFF)
     postUpdate("pOutdoor_Watering_Logic_Program_State", u"läuft nicht")
Example #21
0
 def execute(self, module, input):
     #sendCommand("pOther_Helper_HabpanelViewer_Control_Cmd", "RELOAD")
     urllib2.urlopen("http://192.168.0.40:5000/reload").read()
     postUpdate("pOther_Scene7", OFF)
 def wakeup(self):
     postUpdate("pOther_Presence_State", PresenceHelper.STATE_PRESENT)
     sendNotification(u"System", u"Guten Morgen")
Example #23
0
 def execute(self, module, input):
     postUpdate("pGF_Livingroom_Television_KeyPOWER", ON if input["event"].getStatusInfo().getStatus().toString() == "ONLINE" else OFF )
Example #24
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")
    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
Example #26
0
 def callback(self):
     self.timer = None
     postUpdate("pOutdoor_Streedside_Gardendoor_Opener_Timer", OFF)
     sendCommandIfChanged("pOutdoor_Streedside_Gardendoor_Opener_Powered",
                          OFF)
Example #27
0
 def execute(self, module, input):
     postUpdate("pOther_Manual_State_Auto_Sunprotection", OFF)
    def execute(self, module, input):
        now = ZonedDateTime.now()

        # pOutdoor_Astro_Dawn_Time
        # pOutdoor_Astro_Sunrise_Time
        # pOutdoor_Astro_Sunset_Time
        # pOutdoor_Astro_Dusk_Time

        cloudCover = getItemState(
            "pOutdoor_Weather_Current_Cloud_Cover").intValue()

        lightLevel = getItemState(
            "pOutdoor_WeatherStation_Light_Level").intValue() if getItemState(
                "pOutdoor_WeatherStation_Is_Working") == ON else 1000

        #self.log.info(str(cloudCover))

        automaticRollershutterState = getItemState(
            "pOther_Automatic_State_Rollershutter").intValue()

        if automaticRollershutterState != SunProtectionHelper.STATE_ROLLERSHUTTER_UP:
            _upTime = getItemState(
                "pOutdoor_Astro_Sunrise_Time").getZonedDateTime()
            _upTime = _upTime.plusSeconds(int((cloudCover * 30.0 / 9.0) * 60))

            if now.getHour() < 12 and now.toLocalDate().isEqual(
                    _upTime.toLocalDate()):
                if now.isAfter(_upTime) or now.isEqual(_upTime):
                    postUpdate("pOther_Automatic_State_Rollershutter",
                               SunProtectionHelper.STATE_ROLLERSHUTTER_UP)
                elif lightLevel > 0 and automaticRollershutterState != SunProtectionHelper.STATE_ROLLERSHUTTER_MAYBE_UP:
                    _upTime = getItemState(
                        "pOutdoor_Astro_Dawn_Time").getZonedDateTime()
                    if now.isAfter(_upTime) or now.isEqual(_upTime):
                        postUpdate(
                            "pOther_Automatic_State_Rollershutter",
                            SunProtectionHelper.STATE_ROLLERSHUTTER_MAYBE_UP)

            postUpdateIfChanged("pOther_Automatic_State_Rollershutter_Up",
                                _upTime.toString())
        else:
            _downTime = getItemState(
                "pOutdoor_Astro_Dusk_Time").getZonedDateTime()
            _downTime = _downTime.minusSeconds(
                int((cloudCover * 30.0 / 9.0) * 60))

            if now.isAfter(_downTime) or now.isEqual(_downTime):
                postUpdate("pOther_Automatic_State_Rollershutter",
                           SunProtectionHelper.STATE_ROLLERSHUTTER_DOWN)
            elif lightLevel <= 0:
                _downTime = getItemState(
                    "pOutdoor_Astro_Sunset_Time").getZonedDateTime()
                if now.isAfter(_downTime) or now.isEqual(_downTime):
                    postUpdate("pOther_Automatic_State_Rollershutter",
                               SunProtectionHelper.STATE_ROLLERSHUTTER_DOWN)

            postUpdateIfChanged("pOther_Automatic_State_Rollershutter_Down",
                                _downTime.toString())

        if lightLevel <= 0 or itemStateOlderThen(
                "pOutdoor_Astro_Sunset_Time", now) or itemStateNewerThen(
                    "pOutdoor_Astro_Sunrise_Time", now):
            postUpdateIfChanged("pOther_Automatic_State_Outdoorlights", ON)
        else:
            postUpdateIfChanged("pOther_Automatic_State_Outdoorlights", OFF)

        if itemStateOlderThen("pOutdoor_Astro_Dusk_Time",
                              now) or itemStateNewerThen(
                                  "pOutdoor_Astro_Dawn_Time", now):
            postUpdateIfChanged("pOther_Automatic_State_Solar", OFF)
        else:
            postUpdateIfChanged("pOther_Automatic_State_Solar", ON)
Example #29
0
    def execute(self, module, input):
        if input["event"].getItemName(
        ) == "pGF_Garage_Solar_Inverter_AC_Power":
            self.updateConsumption(input['event'].getItemState().intValue())
        else:
            if input["event"].getItemName(
            ) == "pGF_Utilityroom_Power_Demand_Active":
                self.powerDemand = input["event"].getItemState().intValue()
                self.powerSupply = getItemState(
                    "pGF_Utilityroom_Power_Supply_Active").intValue()

                if self.powerDemand != getItemState(
                        "pGF_Utilityroom_Power_Demand_Active").intValue():
                    self.log.error(
                        "Item demand state differences: {}, item state: {}".
                        format(
                            self.powerDemand,
                            getItemState("pGF_Utilityroom_Power_Demand_Active"
                                         ).intValue()))
            else:
                self.powerDemand = getItemState(
                    "pGF_Utilityroom_Power_Demand_Active").intValue()
                self.powerSupply = input["event"].getItemState().intValue()

                if self.powerSupply != getItemState(
                        "pGF_Utilityroom_Power_Supply_Active").intValue():
                    self.log.error(
                        "Item supply state differences: {}, item state: {}".
                        format(
                            self.powerSupply,
                            getItemState("pGF_Utilityroom_Power_Supply_Active"
                                         ).intValue()))

            self.currentDemand = self.powerDemand - self.powerSupply

            #self.log.info(u"{}".format(itemLastUpdateOlderThen("pGF_Garage_Solar_Inverter_Total_Yield", ZonedDateTime.now().minusMinutes(15))))

            if getItemState("pOther_Automatic_State_Solar") == ON:
                if itemLastUpdateOlderThen(
                        "pOther_Automatic_State_Solar",
                        ZonedDateTime.now().minusMinutes(60)):
                    # solar value update was not successful for a while
                    #solarActive = getItemState("pOther_Automatic_State_Solar") == ON
                    #if itemLastUpdateOlderThen("pGF_Garage_Solar_Inverter_Total_Yield", ZonedDateTime.now().minusHours(5) if solarActive else ZonedDateTime.now().minusHours(14)):
                    if (itemLastUpdateOlderThen(
                            "pGF_Garage_Solar_Inverter_Total_Yield",
                            ZonedDateTime.now().minusMinutes(15)) or
                        (itemLastUpdateOlderThen(
                            "pGF_Garage_Solar_Inverter_AC_Power",
                            ZonedDateTime.now().minusMinutes(60))
                         and getItemState("pGF_Garage_Solar_Inverter_AC_Power"
                                          ).intValue() > 0)):
                        #  and
                        #(itemLastUpdateOlderThen("pGF_Garage_Solar_Inverter_AC_Power", ZonedDateTime.now().minusMinutes(15)) or getItemState("pGF_Garage_Solar_Inverter_AC_Power").intValue() == 0)):
                        if postUpdateIfChanged(
                                "pGF_Garage_Solar_Inverter_Is_Working", OFF):
                            postUpdate("pGF_Garage_Solar_Inverter_AC_Power", 0)
                            postUpdateIfChanged(
                                "pGF_Garage_Solar_Inverter_DC_Power", 0)
                            postUpdateIfChanged(
                                "pGF_Garage_Solar_Inverter_DC_Current", 0)
                            postUpdateIfChanged(
                                "pGF_Garage_Solar_Inverter_DC_Voltage", 0)
                            postUpdateIfChanged(
                                "pGF_Garage_Solar_Inverter_Daily_Yield", 0)
                    else:
                        postUpdateIfChanged(
                            "pGF_Garage_Solar_Inverter_Is_Working", ON)

                # triggers solar value update
                sendCommand("pGF_Garage_Solar_Inverter_AC_Power", REFRESH)
            else:
                self.updateConsumption(0)
                postUpdateIfChanged("pGF_Garage_Solar_Inverter_Is_Working", ON)
            postUpdateIfChanged("pGF_Utilityroom_Electricity_Current_Demand",
                                self.currentDemand)
Example #30
0
    def execute(self, module, input):
        now = ZonedDateTime.now()
        Aktuell_End = getItemState(
            "pGF_Utilityroom_Gas_Meter_Pulse_Counter").doubleValue()

        # Aktueller Zählerstand
        zaehlerStandCurrent = startGasMeterValue + (
            (Aktuell_End - startGasImpulseCounter) * 0.01)

        zaehlerStandSaved = getItemStateWithFallback(
            "pGF_Utilityroom_Gas_Meter_Current_Count",
            DecimalType(0.0)).doubleValue()

        #self.log.info("{}".format(zaehlerStandCurrent))

        if zaehlerStandCurrent < zaehlerStandSaved:
            self.log.error("Consumption: Calculation is wrong {} {}".format(
                zaehlerStandCurrent, zaehlerStandSaved))
            return

        if zaehlerStandCurrent > zaehlerStandSaved:
            # Aktueller Zählerstand
            postUpdate("pGF_Utilityroom_Gas_Meter_Current_Count",
                       zaehlerStandCurrent)

        # *** Aktueller Tagesverbrauch ***
        zaehlerStandOld = getHistoricItemState(
            "pGF_Utilityroom_Gas_Meter_Current_Count",
            now.toLocalDate().atStartOfDay(now.getZone())).doubleValue()
        currentConsumption = zaehlerStandCurrent - zaehlerStandOld
        if currentConsumption < 0:
            currentConsumption = 0

        postUpdateIfChanged("pGF_Utilityroom_Gas_Current_Daily_Consumption",
                            currentConsumption)

        # *** Jahresverbrauch ***
        refDay = now.withYear(now.getYear()).withMonth(1).withDayOfMonth(1)
        zaehlerStandOld = getHistoricItemState(
            "pGF_Utilityroom_Gas_Meter_Current_Count",
            refDay.toLocalDate().atStartOfDay(refDay.getZone())).doubleValue()
        currentConsumption = zaehlerStandCurrent - zaehlerStandOld
        if currentConsumption < 0:
            currentConsumption = 0

        if postUpdateIfChanged("pGF_Utilityroom_Gas_Annual_Consumption",
                               currentConsumption):
            # Hochrechnung
            zaehlerStandCurrentOneYearBefore = getHistoricItemState(
                "pGF_Utilityroom_Gas_Meter_Current_Count",
                now.minusYears(1)).doubleValue()
            forecastConsumtion = zaehlerStandOld - zaehlerStandCurrentOneYearBefore

            refDay = now.withYear(now.getYear() -
                                  1).withMonth(1).withDayOfMonth(1)
            zaehlerStandOldOneYearBefore = getHistoricItemState(
                "pGF_Utilityroom_Gas_Meter_Current_Count",
                refDay.toLocalDate().atStartOfDay(
                    refDay.getZone())).doubleValue()

            hochrechnungVerbrauch = round(currentConsumption +
                                          forecastConsumtion)

            msg = u"{} m³, {} m³".format(
                hochrechnungVerbrauch,
                int(round(zaehlerStandOld - zaehlerStandOldOneYearBefore)))
            postUpdate("pGF_Utilityroom_Gas_Forecast", msg)