def openTelldus(self): log.info('Opening telldus') td.init( defaultMethods = td.TELLSTICK_TURNON | td.TELLSTICK_TURNOFF | td.TELLSTICK_BELL | td.TELLSTICK_TOGGLE | td.TELLSTICK_DIM | td.TELLSTICK_LEARN ) #td.debug = True log.info('Registering device event handler') self.deviceCallbackId = td.registerDeviceEvent(self.deviceEventCallback) log.info('Registering sensor event handler') self.sensorCallbackId = td.registerSensorEvent(self.sensorEventCallback) #td.registerRawDeviceEvent(...) # if we want to support ALL recvd signals. noisy! log.info('Initializing complete')
def main(): args = sys.argv[1:] if not args: help() return td.init() if args[0] == "add": msg = args[1] if not msg: print("Empty message") else: td.write(msg) elif args[0] == "print": td_print(td.read()) else: help()
def openTelldus(self): log.info('Opening telldus') td.init(defaultMethods=td.TELLSTICK_TURNON | td.TELLSTICK_TURNOFF | td.TELLSTICK_BELL | td.TELLSTICK_TOGGLE | td.TELLSTICK_DIM | td.TELLSTICK_LEARN) #td.debug = True log.info('Registering device event handler') self.deviceCallbackId = td.registerDeviceEvent( self.deviceEventCallback) log.info('Registering sensor event handler') self.sensorCallbackId = td.registerSensorEvent( self.sensorEventCallback) #td.registerRawDeviceEvent(...) # if we want to support ALL recvd signals. noisy! log.info('Initializing complete')
def init(self, SensorPollDelay, TempUnits): #TELLSTICK_BELL | TELLSTICK_TOGGLE | TELLSTICK_LEARN | TELLSTICK_EXECUTE | TELLSTICK_UP | TELLSTICK_DOWN | TELLSTICK_STOP td.init( defaultMethods = td.TELLSTICK_TURNON | td.TELLSTICK_TURNOFF | td.TELLSTICK_DIM)
result = 1 else: write("This rule does not apply today") result = 0 else: write("this rule is set to all days") result = 1 return result Atimer = ActionTimer(queue) Atimer.daemon = True Atimer.start() # init connection to telldusd td.init(defaultMethods=td.TELLSTICK_TURNON | td.TELLSTICK_TURNOFF) #while count < 100000: while 1: write("New run: " + str(datetime.datetime.now())) son = 0 soff = 0 now = datetime.datetime.now() Ynow = now.year mnow = now.month Dnow = now.day Hnow = now.hour Mnow = now.minute wDay = calendar.weekday(Ynow, mnow, Dnow) Wday = weekDay(wDay) Utime = int(time.time())
# file: logger.py import td import time def logSensorEvent(protocol, model, id, dataType, value, timestamp, callbackId): # print a line for each event with time, sensor id, data type, value, protocoll, and model print '%s,%d,%d,%s,%s,%s' %(time.strftime("%Y-%m-%d,%H:%M:%S"), id, dataType, value, protocol, model) if __name__ == '__main__': # Intialize the communcation td.init( defaultMethods = td.TELLSTICK_TURNON | td.TELLSTICK_TURNOFF ) # Register callbacks callbackId = [] callbackId.append(td.registerSensorEvent(logSensorEvent)) # Run infinite loop try: while(1): time.sleep(1) except KeyboardInterrupt: for i in callbackId: # De-register callbacks td.unregisterCallback(i) # Close communication so telldus-core can do some cleanup. td.close() ## End logger.py
parser.add_option("-v", "--dimlevel", dest="dimlevel", metavar = 'level', help="Set dim level. 'level' should be an integer, 0-255. Note: This parameter also requires the --dim/-d for anything to happen.") parser.add_option("-b", "--bell", dest="bell", metavar = 'bell', help="Sends bell command to devices supporting this. 'device' could either be an integer of the device-id, or the name of the device. Both device-id and name is outputed with the --list option.") parser.add_option("-e", "--learn", dest="learn", metavar = 'learn', help="Sends a special learn command to devices supporting this. This is normaly devices of 'selflearning' type. 'device' could either be an integer of the device-id, or the name of the device. Both device-id and name is outputed with the --list option.") parser.add_option("-t", "--event", action="store_true", default=False, help="Listen for events untill interrupted by ctrl-c") (options, args) = parser.parse_args() td.init( defaultMethods = td.TELLSTICK_TURNON | td.TELLSTICK_TURNOFF ) #Application can configure to support different methods # td.init() if options.on != None and options.off == None and options.bell == None and options.list == False and options.dim == None and options.learn == None and options.event == False: # # ON # deviceId, deviceName = getDeviceIdAndName(options.on) if deviceId == -1: parser.error('unknown device: ' + options.on) resCode = td.turnOn(deviceId) if resCode != 0: res = td.getErrorString(resCode)
"-e", "--learn", dest="learn", metavar='learn', help= "Sends a special learn command to devices supporting this. This is normaly devices of 'selflearning' type. 'device' could either be an integer of the device-id, or the name of the device. Both device-id and name is outputed with the --list option." ) parser.add_option("-t", "--event", action="store_true", default=False, help="Listen for events untill interrupted by ctrl-c") (options, args) = parser.parse_args() td.init(defaultMethods=td.TELLSTICK_TURNON | td.TELLSTICK_TURNOFF ) #Application can configure to support different methods # td.init() if options.on != None and options.off == None and options.bell == None and options.list == False and options.dim == None and options.learn == None and options.event == False: # # ON # deviceId, deviceName = getDeviceIdAndName(options.on) if deviceId == -1: parser.error('unknown device: ' + options.on) resCode = td.turnOn(deviceId) if resCode != 0: res = td.getErrorString(resCode)