예제 #1
0
def zbRouterAvail(event):
    zbRouterAvail.log.debug("== zbRouterAvail::")
    LogAction.logDebug("zbRouterAvail", "==xxxccc Item {} received update: {}",
                       event.itemName, event.itemState)
    events.postUpdate("ZbRouter_01_Reachable", "Online")
    #log.debug("Battery charging monitor: {}: start".format(event.itemState))
    global zbRouterTimer
    if zbRouterTimer is not None and not zbRouterTimer.hasTerminated():
        zbRouterTimer.cancel()
    zbRouterTimer = ScriptExecution.createTimer(
        DateTime.now().plusSeconds(routerTimeout),
        lambda: events.postUpdate("ZbRouter_01_Reachable", "Offline"))
    zbRouterAvail.log.debug("==== zbRouterAvail timer started!!!!!!!!!!!::")
예제 #2
0
def bgAvail(event):
    LogAction.logDebug(
        "gBG_socket_maxworktime_updates",
        "!!!! gBG_socket_maxworktime_updates  Item {} received  update: {}",
        event.itemName, event.itemState)
    # create the 'reachable' item name e.g bg_wifisocket_4_maxworktime to bg_wifisocket_4_reachable
    newname = event.itemName[:event.itemName.rfind('_') + 1] + "reachable"
    events.postUpdate(
        newname, "Online")  # use reachable not triggering event cos its temp
    bgAvail.log.debug("== BG sockets Online/Offline status marked  ONLINE::")

    if event.itemName not in timers or timers[event.itemName].hasTerminated():
        timers[event.itemName] = ScriptExecution.createTimer(
            DateTime.now().plusSeconds(timeoutSeconds),
            lambda: events.postUpdate(newname, "Offline"))
    else:
        timers[event.itemName].reschedule(
            DateTime.now().plusSeconds(timeoutSeconds))
예제 #3
0
def Rule_KeyThingStatusUpdate(event):
    global logTitle
    global keyThingsDict
    logPrefix = "Rule_KeyThingStatusUpdate(): "
    LogAction.logDebug(logTitle, logPrefix + "event = " + pp.pformat(event))

    keyThings = []
    if event:
        keyThings.append(str(event.thingUID))
    else:
        for k in keyThingsDict.keys():
            keyThings.append(k)

    for k in keyThings:
        keyItemInfo = keyThingsDict[k]
        keyStatusItem = keyItemInfo.get("status_item")
        keyStatusItemThingName = keyItemInfo.get("thing_name")
        bindingRestartInfo = keyItemInfo.get("restart_info")
        nodeName = k.split(":")[-1]
        # thing state is not available in event if rule triggered by cron:
        if event:
            nodeState = str(event.statusInfo)
            LogAction.logInfo(logTitle, logPrefix+"Thing {} ({}, status item {}) status changed to {}".format(nodeName, keyStatusItemThingName, keyStatusItem, nodeState))
        else:
            nodeState = things.get(ThingUID(k)).status
        events.postUpdate(keyStatusItem, str(nodeState))

        # Restart some bindings if needed
        if bindingRestartInfo:
            LogAction.logDebug(logTitle, logPrefix+u"Restart {} (URI {}) if offline; current status is {}".format(keyStatusItemThingName, bindingRestartInfo.get("binding_uri"), nodeState))
            # Note: schedule_binding_restart() takes care of managing the Thing status
            schedule_binding_restart(
                bindingRestartInfo.get("binding_uri"),
                keyStatusItemThingName,
                k,
                bindingRestartInfo.get("wait_time"),
                reschedule_timer_on_update=bindingRestartInfo.get("reschedule_timer_on_update", False),
                notify_restart=bindingRestartInfo.get("notify_restart", False)
            )
예제 #4
0
파일: pir.py 프로젝트: chrispab/AutoHome
def pir02_off_body():
    # pir_light_off.log.error("pir02_occupancy_off body : KT_light_2_Power: OFF ")
    LogAction.logDebug("pir02_occupancy_off",
                       "pir02_occupancy_off body : KT_light_2_Power: OFF ")
    events.sendCommand("KT_light_2_Power", "OFF")
    events.sendCommand("KT_light_3_Power", "OFF")
예제 #5
0
def checkIfHeatersNeedUpdating(event):
    checkIfHeatersNeedUpdating.log.debug(
        "HHH HeatingMode, Setpoint or Temperature updated")

    # get prefix eg FR, CT etc
    prefix = event.itemName[:event.itemName.rfind('_')]
    LogAction.logDebug(
        "Check if Heaters need changing",
        "HHH Check if Heaters need changing etc due to Item: {}, received  update: {}",
        event.itemName, event.itemState)

    HeatingMode = ir.getItem(prefix + "_HeatingMode")
    LogAction.logDebug("Check if Heaters need changing",
                       "HHH HeatingMode {} : {}", prefix, HeatingMode.state)

    TSetpoint = ir.getItem(prefix + "_TemperatureSetpoint")
    LogAction.logDebug("Check if Heaters need changing",
                       "HHH Setpoint    {} : {}", prefix, TSetpoint.state)

    Temperature = ir.getItem(prefix + "_Temperature")
    LogAction.logDebug("Check if Heaters need changing",
                       "HHH Temperature {} : {}", prefix, Temperature.state)

    Heater = ir.getItem(prefix + "_Heater")
    LogAction.logDebug("Check if Heaters need changing",
                       "HHH Heater      {} : {}", prefix, Heater.state)

    Reachable = ir.getItem(prefix + "_RTVReachable")
    LogAction.logDebug("Check if Heaters need changing",
                       "HHH Reachable   {} : {}", prefix, Reachable.state)

    #!handle an offline TRV
    if Reachable.state.toString() != "Online":  # is the trv actually online??
        LogAction.logError(
            "Check if Heaters need changing",
            "HHH ZZZZ---ZZZZ Reachable-Offline - sending OFF, leaving!!!!!   prefix: {} ",
            prefix)
        #turn this one off
        events.sendCommand(Heater, "OFF")
        return  #dont continue on and update the bolier control if this RTV is Offline

    LogAction.logDebug(
        "Check if Heaters need changing",
        "HHH current HeatingMode.state: {}  masterHeatingMode.state: {}",
        HeatingMode.state,
        ir.getItem("masterHeatingMode").state)

    if (HeatingMode.state.toString()
            == "off") or (ir.getItem("masterHeatingMode").state.toString()
                          == "off"):
        if (ir.getItem("masterHeatingMode").state.toString() == "off"):
            LogAction.logDebug("Check if Heaters need changing",
                               "HHH Master Heating Mode is OFF")

        LogAction.logDebug(
            "Check if Heaters need changing",
            "HHH Turn heater OFF for {}  cos its Heating Mode is {}", prefix,
            HeatingMode.state)
        events.sendCommand(Heater, "OFF")

    elif (HeatingMode.state.toString()
          == "auto") or (HeatingMode.state.toString() == "manual"):
        LogAction.logDebug("Check if Heaters need changing",
                           "HHH mode is auto or manual")
        LogAction.logDebug("Check if Heaters need changing",
                           "HHH Heater.itemName: {}", Heater)

        setpoint = TSetpoint.state
        turnOnTemp = setpoint  # - 0.2// calculate the turn on/off temperatures
        turnOffTemp = setpoint  # + 0.1
        temp = Temperature.state  # get the current temperature

        if temp >= turnOffTemp:  # {  // determine whether we need to turn on/off the heater
            LogAction.logDebug("Check if Heaters need changing",
                               "HHH SendCommand to {}, Heater OFF", prefix)
            events.sendCommand(Heater, "OFF")
        elif temp < turnOnTemp:
            LogAction.logDebug("Check if Heaters need changing",
                               "HHH SendCommand to {}, Heater ON", prefix)
            events.sendCommand(Heater, "ON")