def execute(self, module, input):
     global ruleTimeouts
     now = getNow().getMillis()
     last = ruleTimeouts.get("Livingroom_Hue_Color_Backward",0)
     
     if now - last > 1000:
         sendCommand("State_Lightprogram", 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"].getItemCommand()

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

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

            #ruleTimeouts["Motiondetector_Outdoor_Individual_Switches"] = now
            postUpdate("Motiondetector_Outdoor_Garage_Streetside_Switch",
                       itemState)
            postUpdate("Motiondetector_Outdoor_Frontdoor_Switch", itemState)
            postUpdate("Motiondetector_Outdoor_Carport_Switch", itemState)
            postUpdate("Motiondetector_Outdoor_Terrace_Switch", itemState)
            postUpdate("Motiondetector_Outdoor_Garage_Gardenside_Switch",
                       itemState)
    def execute(self, module, input):
        sendCommand("Motiondetector_Outdoor_Carport_Switch", OFF)
        sendCommand("Motiondetector_Outdoor_Frontdoor_Switch", OFF)
        sendCommand("Motiondetector_Outdoor_Terrace_Switch", OFF)
        sendCommand("Motiondetector_Outdoor_Garage_Streetside_Switch", OFF)
        sendCommand("Motiondetector_Outdoor_Garage_Gardenside_Switch", ON)

        postUpdate("Scene5", OFF)
    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("Scene6", OFF)
 def _setCurrentColors(self,data):
     global ruleTimeouts
     ruleTimeouts["Livingroom_Hue_Color_Backward"] = getNow().getMillis()
     
     sendCommand("Light_FF_Livingroom_Hue_Color1",u"{},{},{}".format(data[0][0],data[0][1],data[0][2]))
     sendCommand("Light_FF_Livingroom_Hue_Color2",u"{},{},{}".format(data[1][0],data[1][1],data[1][2]))
     sendCommand("Light_FF_Livingroom_Hue_Color3",u"{},{},{}".format(data[2][0],data[2][1],data[2][2]))
     sendCommand("Light_FF_Livingroom_Hue_Color4",u"{},{},{}".format(data[3][0],data[3][1],data[3][2]))
     sendCommand("Light_FF_Livingroom_Hue_Color5",u"{},{},{}".format(data[4][0],data[4][1],data[4][2]))
 def execute(self, module, input):
     if getItemState("State_Presence").intValue() == 0 \
             and getItemState("roomba_auto") == ON \
             and getItemState("roomba_status").toString() == "Charging" \
             and getItemState("roomba_batPct").intValue() >= 100 \
             and getItemState("roomba_error") == OFF \
             and getItemState("roomba_full") == OFF:
         if itemLastUpdateOlderThen("roomba_cleaning_state", getNow().minusMinutes(360)) \
                 and itemLastUpdateOlderThen("State_Presence", getNow().minusMinutes(60)):
             sendCommand("roomba_command", "start")
示例#7
0
    def execute(self, module, input):
        if input["event"].getItemName() == "Solar_AC_Power":
            self.updateConsumption(input['event'].getItemState().intValue())
        else:
            if input["event"].getItemName() == "Power_Demand_Active":
                self.powerDemand = input["event"].getItemState().intValue()
                self.powerSupply = getItemState(
                    "Power_Supply_Active").intValue()

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

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

            self.currentDemand = self.powerDemand - self.powerSupply

            if getItemState("State_Solar") == ON:
                # solar value update was not successful for a while
                #solarActive = getItemState("State_Solar") == ON
                #if itemLastUpdateOlderThen("Solar_Total_Yield", getNow().minusHours(5) if solarActive else getNow().minusHours(14)):
                if itemLastUpdateOlderThen("Solar_Total_Yield",
                                           getNow().minusHours(24)):
                    self.log.info(
                        u"Solar: ERROR • Values not updated. Fallback to '0' values."
                    )
                    postUpdate("Solar_AC_Power", 0)
                    postUpdateIfChanged("Solar_DC_Power", 0)
                    postUpdateIfChanged("Solar_DC_Current", 0)
                    postUpdateIfChanged("Solar_DC_Voltage", 0)
                    postUpdateIfChanged("Solar_Daily_Yield", 0)

                # triggers solar value update
                sendCommand("Solar_AC_Power", REFRESH)
            else:
                self.updateConsumption(0)

            postUpdateIfChanged("Electricity_Current_Demand",
                                self.currentDemand)
    def execute(self, module, input):
        sendCommand("Light_FF_Floor_Ceiling", ON)
        sendCommand("Light_SF_Bathroom_Ceiling", ON)
        sendCommand("Light_SF_Bathroom_Mirror", ON)
        sendCommand("Light_SF_Bedroom_Ceiling", ON)

        postUpdate("Scene2", OFF)
    def execute(self, module, input):
        if getItemState("State_Outdoorlights") == ON and getItemState(
                "Motiondetector_Outdoor_Terrace_Switch") == ON:
            global timerMappings
            if timerMappings.get("Light_Outdoor_Terrace") is not None:
                timerMappings["Light_Outdoor_Terrace"].cancel()
            timerMappings["Light_Outdoor_Terrace"] = createTimer(
                timerDuration, self.callback)
            timerMappings["Light_Outdoor_Terrace"].start()

            global ruleTimeouts
            ruleTimeouts["Light_Outdoor"] = getNow().getMillis()

            sendCommand("Light_Outdoor_Terrace", 100)
 def execute(self, module, input):
     if input["event"].getItemName() == "Door_FF_Floor":
         if self.isArriving:
             if getItemState("State_Outdoorlights") == ON:
                 sendCommand("Light_FF_Floor_Ceiling", ON)
             self.isArriving = False
     # 10 minutes matches the max time ranges used by presence detection to ping phones => see pingdevice thing configuration
     # it can happen that State_Presence changes after Door_FF_Floor was opened
     elif itemLastUpdateOlderThen("Door_FF_Floor",
                                  getNow().minusMinutes(10)):
         self.isArriving = input["event"].getItemState().intValue(
         ) == 1 and input["oldState"].intValue() == 0
         if self.isArriving:
             self.arrivingTimer = createTimer(60, self.arrivingCallback)
             self.arrivingTimer.start()
    def callback(self, entry):
        global timerMappings
        if getItemState(entry[1]) == ON:
            if getItemState(entry[2]) == OPEN:
                timerMappings[entry[0]] = createTimer(timerDuration,
                                                      self.callback, [entry])
                timerMappings[entry[0]].start()
            else:
                global ruleTimeouts
                ruleTimeouts["Light_Outdoor"] = getNow().getMillis()

                sendCommand(entry[0], OFF)
                timerMappings[entry[0]] = None
        else:
            timerMappings[entry[0]] = None
    def execute(self, module, input):
        itemName = input['event'].getItemName()

        entry = manualMappings[self.triggerMappings[itemName]]
        if getItemState("State_Outdoorlights") == ON and getItemState(
                entry[1]) == ON:
            if timerMappings.get(entry[0]) is not None:
                timerMappings[entry[0]].cancel()
            timerMappings[entry[0]] = createTimer(timerDuration, self.callback,
                                                  [entry])
            timerMappings[entry[0]].start()

            global ruleTimeouts
            ruleTimeouts["Light_Outdoor"] = getNow().getMillis()

            sendCommand(entry[0], ON)
示例#13
0
    def execute(self, module, input):
        if getItemState("Ventilation_Auto_Mode").intValue() != 1:
            return

        currentLevel = getItemState("Ventilation_Fan_Level").intValue()

        raumTemperatur = getItemState("Temperature_FF_Livingroom").doubleValue()
        zielTemperatur = getItemState("Ventilation_Comfort_Temperature").doubleValue
        
        presenceSate = getItemState("State_Presence").intValue()
        
        isTooWarm = raumTemperatur >= zielTemperatur
        coolingPossible = getItemState("Temperature_Garden").doubleValue() < raumTemperatur

        # Sleep
        if presenceSate == 2:
            reducedLevel = 2    # Level 1
            defaultLevel = 2    # Level 1
            coolingLevel = 2    # Level 1
        # Away since 30 minutes
        elif presenceSate == 0 and itemLastUpdateOlderThen("State_Presence", getNow().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 cangedSince dows not work propperly
                waitBeforeChange = 2

            if itemLastUpdateOlderThen("Ventilation_Fan_Level", getNow().minusMinutes(waitBeforeChange)):
                global autoChangeInProgress
                autoChangeInProgress = True

                sendCommand("Ventilation_Fan_Level", newLevel)
    def callback(self):
        global timerMappings
        if getItemState("Motiondetector_Outdoor_Terrace_Switch") == ON:
            if getItemState(
                    "Motiondetector_Outdoor_Terrace1") == OPEN or getItemState(
                        "Motiondetector_Outdoor_Terrace2") == OPEN:
                timerMappings["Light_Outdoor_Terrace"] = createTimer(
                    timerDuration, self.callback)
                timerMappings["Light_Outdoor_Terrace"].start()
            else:
                global ruleTimeouts
                ruleTimeouts["Light_Outdoor"] = getNow().getMillis()

                sendCommand("Light_Outdoor_Terrace", 0)
                timerMappings["Light_Outdoor_Terrace"] = None
        else:
            timerMappings["Light_Outdoor_Terrace"] = None
 def callback(self):
     if getItemState("State_Lightprogram").intValue() == 0:
         return
     
     color1 = getItemState("Light_FF_Livingroom_Hue_Color1")
     color2 = getItemState("Light_FF_Livingroom_Hue_Color2")
     color3 = getItemState("Light_FF_Livingroom_Hue_Color3")
     color4 = getItemState("Light_FF_Livingroom_Hue_Color4")
     color5 = getItemState("Light_FF_Livingroom_Hue_Color5")
         
     global ruleTimeouts
     ruleTimeouts["Livingroom_Hue_Color_Backward"] = getNow().getMillis()
 
     sendCommand("Light_FF_Livingroom_Hue_Color1",color2)
     sendCommand("Light_FF_Livingroom_Hue_Color2",color3)
     sendCommand("Light_FF_Livingroom_Hue_Color3",color4)
     sendCommand("Light_FF_Livingroom_Hue_Color4",color5)
     sendCommand("Light_FF_Livingroom_Hue_Color5",color1)
                 
     self.timer = createTimer(self.timeout, self.callback )
     self.timer.start()
    def execute(self, module, input):
        hour = getNow().getHourOfDay()

        state = getItemState("Auto_Attic_Light").intValue()

        if state == 2:
            if hour == 5:
                sendCommand("Socket_Attic", ON)
            elif hour == 23:
                sendCommand("Socket_Attic", OFF)
        elif state == 3:
            if hour == 8:
                sendCommand("Socket_Attic", ON)
            elif hour == 20:
                sendCommand("Socket_Attic", OFF)
示例#17
0
    def execute(self, module, input):

        now = getNow().getMillis()

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

        currentPowerLimitation = getItemState(
            "Solar_Power_Limitation").intValue()

        currentConsumptionValue = getItemState(
            "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), (now - self.lastLimitationIncrease)))

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

            if len(input) == 0 and itemLastUpdateOlderThen(
                    "Solar_Power_Limitation",
                    getNow().minusMinutes(4)):
                sendCommand("Solar_Power_Limitation", currentPowerLimitation)
                self.log.info(u"Refresh power limitation of {}%".format(
                    currentPowerLimitation))
        elif currentPowerLimitation != 100:
            postUpdate("Solar_Power_Limitation", 100)
            self.log.info(u"Shutdown power limitation")
示例#18
0
    def execute(self, module, input):
        sendCommand("Light_FF_Livingroom_Hue_Brightness", 60)

        states = [OFF, PercentType.ZERO]

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

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

        postUpdate("Scene1", OFF)
    def findStep(self):
        duration = getItemState(
            "Watering_Program_Duration").intValue() * 60.0 * 1000.0

        remaining = 0
        activeStep = None

        if getItemState("Watering_Circuits") == OFF:
            for loop in circuits:
                #self.log.info("start " + loop[0][0])
                sendCommand(loop[0][0], ON)
            activeStep = circuits[0][0]
            remaining = (duration * activeStep[2])
        else:
            activeIndex = -1
            for i in range(len(circuits[0])):
                step = circuits[0][i]
                if getItemState(step[0]) == ON:
                    activeIndex = i
                    activeStep = step
                    break

            if activeStep != None:
                runtime = getNow().getMillis() - getItemLastUpdate(
                    activeStep[0]).getMillis()

                remaining = (duration * activeStep[2]) - runtime

                if remaining <= 0:
                    activeIndex += 1
                    if activeIndex < len(circuits[0]):
                        #self.log.info("next " + circuits[0][activeIndex][0])
                        sendCommand(circuits[0][activeIndex][0], ON)
                        sendCommand(activeStep[0], OFF)
                        activeStep = circuits[0][activeIndex]
                        remaining = (duration * activeStep[2])
                    else:
                        activeStep = None
                        #self.log.info("finish")
                        self.disableAllCircuits()
                        postUpdate("Watering_Program_Start", OFF)

        return [activeStep[1] if activeStep != None else u"", remaining]
示例#20
0
 def execute(self, module, input):
     if getItemState("Auto_Sunprotection") == ON and getItemState("State_Presence").intValue() == 0:
         if getItemState("State_Sunprotection_Livingroom") == ON:
             sendCommand("Shutters_FF_Kitchen", DOWN)
             sendCommand("Shutters_FF_Livingroom_Couch", DOWN)
             if getItemState("Window_FF_Livingroom_Terrace") == CLOSED:
                 sendCommand("Shutters_FF_Livingroom_Terrace", DOWN)
         else:
             sendCommand("Shutters_FF_Kitchen", UP)
             sendCommand("Shutters_FF_Livingroom_Couch", UP)
             sendCommand("Shutters_FF_Livingroom_Terrace", UP)
示例#21
0
 def execute(self, module, input):
     if getItemState("Auto_Sunprotection") == ON:
         if getItemState("State_Sunprotection_Bedroom") == ON:
             sendCommand("Shutters_SF_Bedroom", DOWN)
         else:
             sendCommand("Shutters_SF_Bedroom", UP)
示例#22
0
    def execute(self, module, input):
        if getItemState("Auto_Rollershutter") == ON:
            if getItemState("State_Rollershutter") == ON:
                if getItemState("Window_FF_Livingroom_Terrace") == CLOSED: sendCommand("Shutters_FF_Livingroom_Terrace", DOWN)
                if getItemState("Window_FF_Livingroom_Couch") == CLOSED: sendCommand("Shutters_FF_Livingroom_Couch", DOWN)
                if getItemState("Window_FF_Kitchen") == CLOSED: sendCommand("Shutters_FF_Kitchen", DOWN)
                if getItemState("Window_FF_Guestroom") == CLOSED: sendCommand("Shutters_FF_Guestroom", DOWN)
                if getItemState("Window_FF_GuestWC") == CLOSED: sendCommand("Shutters_FF_GuestWC", DOWN)

                if getItemState("Window_SF_Bedroom") == CLOSED: sendCommand("Shutters_SF_Bedroom", DOWN)
                if getItemState("Window_SF_Dressingroom") == CLOSED: sendCommand("Shutters_SF_Dressingroom", DOWN)
                if getItemState("Window_SF_Child1") == CLOSED: sendCommand("Shutters_SF_Child1", DOWN)
                if getItemState("Window_SF_Child2") == CLOSED: sendCommand("Shutters_SF_Child2", DOWN)
                if getItemState("Window_SF_Bathroom") == CLOSED: sendCommand("Shutters_SF_Bathroom", DOWN)
                if getItemState("Window_SF_Attic") == CLOSED: sendCommand("Shutters_SF_Attic", DOWN)
            elif getItemState("State_Presence").intValue() == 0:
                sendCommand("Shutters", UP)
 def disableAllCircuits(self):
     for child in getGroupMember("Watering_Circuits"):
         sendCommand(child, OFF)
     postUpdate("Watering_Program_State", u"läuft nicht")
    def execute(self, module, input):
        state = getItemState("roomba_passes").toString()

        if state == "auto":
            sendCommand("roomba_noAutoPasses", OFF)
            time.sleep(2)
            sendCommand("roomba_twoPass", OFF)
        elif state == "one":
            sendCommand("roomba_noAutoPasses", ON)
            time.sleep(2)
            sendCommand("roomba_twoPass", OFF)
        elif state == "two":
            sendCommand("roomba_noAutoPasses", OFF)
            time.sleep(2)
            sendCommand("roomba_twoPass", ON)
示例#25
0
    def execute(self, module, input):
        sendCommand("Light_FF_Floor_Hue_Brightness", 60)
        sendCommand("Light_SF_Bathroom_Ceiling", ON)
        sendCommand("Light_SF_Bathroom_Mirror", ON)
        sendCommand("Light_SF_Bedroom_Right", ON)

        states = [OFF, PercentType.ZERO]

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

        #for child in getItem("Lights_SF").getAllMembers():
        #    if child.getState() not in states and child.getName() not in ["Light_SF_Bathroom_Mirror", "Light_SF_Bedroom_Right"]:
        #        sendCommand(child, OFF)

        sendCommand("Scene6", ON)
        postUpdate("Scene3", OFF)
    def execute(self, module, input):
        state = getItemState("roomba_boost").toString()

        if state == "eco":
            sendCommand("roomba_carpetBoost", OFF)
            time.sleep(2)
            sendCommand("roomba_vacHigh", OFF)
        elif state == "auto":
            sendCommand("roomba_carpetBoost", ON)
            time.sleep(2)
            sendCommand("roomba_vacHigh", OFF)
        elif state == "performance":
            sendCommand("roomba_carpetBoost", OFF)
            time.sleep(2)
            sendCommand("roomba_vacHigh", ON)
示例#27
0
 def execute(self, module, input):
     if getItemState(
             "Light_SF_Bedroom_Right_Hue_Brightness").intValue() == 0:
         sendCommand("Light_SF_Bedroom_Right_Hue_Brightness", 100)
     else:
         sendCommand("Light_SF_Bedroom_Right_Hue_Brightness", 0)
示例#28
0
 def execute(self, module, input):
     sendCommand("Scene4", ON)
示例#29
0
    from org.openhab.core.types import TypeParser

from core.osgi.events import OsgiEventTrigger
from core.utils import validate_uid
from core.log import logging, LOG_PREFIX

from org.quartz.CronExpression import isValidExpression

#from core.log import logging
from core.triggers import ItemStateUpdateTrigger, ItemStateChangeTrigger

from org.slf4j import LoggerFactory

from marvin.helper import log, sendCommand

sendCommand("Solar_Power_Limitation", 10)

#import time

#from org.openhab.core.automation import Rule as SmarthomeRule
#from marvin.helper import log, getGroupMember, sendCommand
#from core.jsr223 import scope
#from core.triggers import CronTrigger, ItemStateUpdateTrigger, ItemStateChangeTrigger

#member = getGroupMember("FF_Livingroom")

#for item in member:
#    log.info(u"{}".format(item))

#@rule("_test.py")
#class EventMonitorRule1:
示例#30
0
 def execute(self, module, input):
     if getItemState("State_Solar") == ON:
         # triggers solar value update
         sendCommand("Solar_Total_Yield", REFRESH)