Пример #1
0
def SwitchOff(devKey):
    nwkId = database.GetDeviceItem(devKey, "nwkId")
    ep = database.GetDeviceItem(devKey, "endPoints")
    if nwkId and ep:
        #database.UpdateLoggedItem(devKey, "State", "SwitchOff") # So that we can access it from the rules later
        devices.DelTempVal(
            devKey, "SwitchOff@"
        )  # Remove any pending "Off" events if we're turning the device off directly
        devices.SetTempVal(devKey, "JustSentOnOff", "True")
        devices.SetTempVal(devKey, "ExpectOnOff", "SwitchOff")
        queue.EnqueueCmd(devKey,
                         ["AT+RONOFF:" + nwkId + "," + ep + ",0,0", "OK"
                          ])  # Assume FFD if it supports OnOff cluster
        database.SetDeviceItem(devKey, "dimLevel", 0)  # Set dimness to 0
Пример #2
0
def SwitchOn(devKey):
    nwkId = database.GetDeviceItem(devKey, "nwkId")
    ep = database.GetDeviceItem(devKey, "endPoints")
    dimLevel = database.GetDeviceItem(devKey, "dimLevel")
    inClstr = database.GetDeviceItem(
        devKey, "inClusters")  # For checking whether we have LevelCtrl
    if nwkId and ep:
        #database.UpdateLoggedItem(devKey, "State", "SwitchOn") # So that we can access it from the rules later
        devices.SetTempVal(devKey, "JustSentOnOff", "True")
        devices.SetTempVal(devKey, "ExpectOnOff", "SwitchOn")
        queue.EnqueueCmd(devKey,
                         ["AT+RONOFF:" + nwkId + "," + ep + ",0,1", "OK"
                          ])  # Assume FFD if it supports OnOff cluster
        if zcl.Cluster.LevelCtrl in inClstr and dimLevel != 100:  # Queue up a dimming command if available and we're at a different dimness
            queue.EnqueueCmd(
                devKey,
                ["AT+LCMVTOLEV:" + nwkId + "," + ep + ",0,1,FE,0001", "OK"
                 ])  # Ensure fully bright ready to be turned on
            database.SetDeviceItem(
                devKey, "dimLevel",
                100)  # Assume the LevelCtrl command above works
Пример #3
0
def SetDimDuration(devKey, durationS):
    if durationS > 0:  # Duration of 0 means "Stay on forever"
        log.debug("Fading to off after " + str(durationS))
        devices.SetTempVal(devKey, "FadeDown@",
                           datetime.now() + timedelta(seconds=durationS))
Пример #4
0
def SetOnDuration(devKey, durationS):
    if durationS > 0:  # Duration of 0 means "Stay on forever"
        log.debug("Switching off after " + str(durationS))
        devices.SetTempVal(devKey, "SwitchOff@",
                           datetime.now() + timedelta(seconds=durationS))
Пример #5
0
def EventHandler(eventId, eventArg):
    if eventId == events.ids.TRIGGER:
        devKey = devices.GetKey(
            eventArg[1])  # Lookup device from network address in eventArg[1]
        if devKey != None:
            devices.NoteMsgDetails(devKey, eventArg)  # Note presence
            now = datetime.now()
            nowStr = now.strftime("%H:%M")
            zoneType = database.GetDeviceItem(devKey,
                                              "iasZoneType")  # Device type
            if zoneType != None:
                oldState = database.GetLatestEvent(devKey)
                if zoneType == zcl.Zone_Type.Contact:
                    if int(eventArg[3], 16) & 1:  # Bottom bit indicates alarm1
                        newState = "opened"
                    else:
                        newState = "closed"
                    if oldState != newState:  # NB Might get same state if sensor re-sends, or due to battery report
                        database.UpdateLoggedItem(
                            devKey, "State", newState
                        )  # So that we can access it from the rules later
                        database.NewEvent(
                            devKey, newState
                        )  # For web page.  Only update event log when state changes
                        DeviceRun(devKey, "==" + newState
                                  )  # See if rule exists (when state changes)
                        #log.debug("Door "+ eventArg[1]+ " "+newState)
                elif zoneType == zcl.Zone_Type.PIR:
                    if int(eventArg[3], 16) & 1:  # Bottom bit indicates alarm1
                        newState = "active"
                        devices.SetTempVal(
                            devKey, "PirInactive@",
                            datetime.now() + timedelta(seconds=300))
                    else:
                        newState = "inactive"  # Might happen if we get an IAS battery report
                    if oldState != newState:
                        database.UpdateLoggedItem(
                            devKey, "State", newState
                        )  # So that we can access it from the rules later
                        database.NewEvent(
                            devKey, newState
                        )  # For web page.  Only update event log when state changes
                    DeviceRun(devKey, "==" + newState)  # See if rule exists
                else:
                    log.debug("DevId: " + eventArg[1] + " zonestatus " +
                              eventArg[3])
            else:
                log.fault("Unknown IAS device type for devId " + eventArg[1])
        else:  # devKey == None
            telegesis.Leave(
                eventArg[1]
            )  # Tell device to leave the network, since we don't know anything about it
    elif eventId == events.ids.BUTTON:
        devKey = devices.GetKey(
            eventArg[1])  # Lookup device from network address in eventArg[1]
        if devKey != None:
            #log.debug("Button "+ eventArg[1]+ " "+eventArg[0]) # Arg[0] holds "ON", "OFF" or "TOGGLE" (Case might be wrong)
            database.NewEvent(devKey, "pressed")  # For web page
            DeviceRun(devKey, "==" + eventArg[0])  # See if rule exists
        else:  # devKey == None
            telegesis.Leave(
                eventArg[1]
            )  # Tell device to leave the network, since we don't know anything about it
    elif eventId == events.ids.MULTISTATE:
        devKey = devices.GetKey(
            eventArg[1])  # Lookup device from network address in eventArg[1]
        if devKey != None:
            database.NewEvent(devKey,
                              "MultiState==" + eventArg[0])  # For web page
            DeviceRun(devKey, "==" + eventArg[0])  # See if rule exists
        else:  # devKey == None
            telegesis.Leave(
                eventArg[1]
            )  # Tell device to leave the network, since we don't know anything about it