def loop_time(self): if ranges.inrange(): print('Timeout: switch on') relay.set(1) else: print('Timeout: switch off') relay.set(0) register(relay.status())
def __init__(self, timeout=10): self.counter = 0 self.presence = 0 self.before = 0 self.timeout = timeout # Let's start relay.set(0) print('Relay ready', self.timeout)
def loop(self): if not ranges.inrange(): relay.set(0) return #Get Sensor presence #print('Waiting PIR...') self.presence = pir.get() if self.presence: if not self.before: print('Switch on') relay.set(1) self.counter = 0 register(relay.status()) elif relay.get() == 1: self.counter += 1 if self.counter > self.timeout: print('Timeout: switch off') relay.set(0) self.counter = 0 register(relay.status()) else: print(self.counter, end='..') # Save it for next loop self.before = self.presence
def switch_off(self): self.counter = 0 relay.set(0) return 'Off!'
def switch_on(self): self.counter = 0 relay.set(1) return 'On!'