Exemple #1
0
def on(relay_num, log=True, max_duration=None):
    pin = relays[relay_num]
    GPIO.output(pin, ON)
    cancel_timer(relay_num)
    if max_duration is not None:
        timers[relay_num] = util.delay(off, max_duration, [relay_num], {"log_extra": "via timer"})
    if log:
        log_action(relay_num, "turn on")
Exemple #2
0
def on(relay_num, log=True, max_duration=None):
    pin = relays[relay_num]
    GPIO.output(pin, ON)
    cancel_timer(relay_num)
    if max_duration is not None:
        timers[relay_num] = util.delay(off, max_duration, [relay_num],
                                       {"log_extra": "via timer"})
    if log:
        log_action(relay_num, "turn on")
Exemple #3
0
def toggle(relay_num, log=True, max_duration=None):
    pin = relays[relay_num]
    new_state = not bool(GPIO.input(pin))
    GPIO.output(pin, new_state)
    cancel_timer(relay_num)
    if new_state == ON and max_duration is not None:
        timers[relay_num] = util.delay(off, max_duration, [relay_num], {"log_extra": "via timer"})
    if log:
        log_action(relay_num, "toggle %s" % ('off' if new_state == OFF else 'on'))
    return new_state
Exemple #4
0
def toggle(relay_num, log=True, max_duration=None):
    pin = relays[relay_num]
    new_state = not bool(GPIO.input(pin))
    GPIO.output(pin, new_state)
    cancel_timer(relay_num)
    if new_state == ON and max_duration is not None:
        timers[relay_num] = util.delay(off, max_duration, [relay_num],
                                       {"log_extra": "via timer"})
    if log:
        log_action(relay_num,
                   "toggle %s" % ('off' if new_state == OFF else 'on'))
    return new_state
Exemple #5
0
def set_relay(relay_num, state):
    pin = relays[relay_num]
    GPIO.output(pin, state)
Exemple #6
0
def off(relay_num, log=True, log_extra=""):
    pin = relays[relay_num]
    GPIO.output(pin, OFF)
    cancel_timer(relay_num)
    if log:
        log_action(relay_num, "turn off %s" % log_extra)
Exemple #7
0
def all_off(log=True):
    for relay_num, pin in relays.iteritems():
        GPIO.output(pin, OFF)
    if log:
        log_action("all", "turn off")
Exemple #8
0
}

sensors = {1: 24}

timers = {}

ON = False
OFF = True

max_synchronous_delay = 0.10

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
for relay, pin_num in relays.iteritems():
    GPIO.setup(pin_num, GPIO.OUT)
    GPIO.output(pin_num, OFF)

for sensor, pin_num in sensors.iteritems():
    GPIO.setup(pin_num, GPIO.IN)


def log_action(device, action):
    print("GPIO Device: %s Action: %s" % (device, action))


def cancel_timer(relay_num, remove_only=False):
    if relay_num in timers:
        if not remove_only:
            timers[relay_num].cancel()
        del timers[relay_num]
Exemple #9
0
def off(relay_num, log=True, log_extra=""):
    pin = relays[relay_num]
    GPIO.output(pin, OFF)
    cancel_timer(relay_num)
    if log:
        log_action(relay_num, "turn off %s" % log_extra)
Exemple #10
0
def all_off(log=True):
    for relay_num, pin in relays.iteritems():
        GPIO.output(pin, OFF)
    if log:
        log_action("all", "turn off")
Exemple #11
0
def set_relay(relay_num, state):
    pin = relays[relay_num]
    GPIO.output(pin, state)
Exemple #12
0
}

timers = {

}

ON = False
OFF = True

max_synchronous_delay = 0.10

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
for relay, pin_num in relays.iteritems():
    GPIO.setup(pin_num, GPIO.OUT)
    GPIO.output(pin_num, OFF)

for sensor, pin_num in sensors.iteritems():
    GPIO.setup(pin_num, GPIO.IN)


def log_action(device, action):
    print("GPIO Device: %s Action: %s" % (device, action))


def cancel_timer(relay_num, remove_only=False):
    if relay_num in timers:
        if not remove_only:
            timers[relay_num].cancel()
        del timers[relay_num]