if str(row['id']) == '1' and row['enabled'] == '1': sw_1_pin = int(row['pin']) sw_1_cmd = row['command'].split(',') sw_1_cmd = [x.strip() for x in sw_1_cmd] sw_1_cmd_2 = ["/var/www/command/sleeptimer.php","1800"] sw_1_cmd_3 = ["/var/www/command/sleeptimer.php","3600"] GPIO.setup(sw_1_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) def sw_1_event(channel): start_time = time.time() time.sleep(0.005) # edge debounce of 5 ms # only deal with valid edges while GPIO.input(channel) == 0: # wait for button up pass buttonTime = time.time() - start_time #calc button press print('time ' + str(buttonTime)) #if GPIO.input(channel) == 1: if buttonTime < 2: print('short press') subprocess.call(sw_1_cmd) elif 2 <= buttonTime < 4: # long press print('long press') subprocess.call(sw_1_cmd_2) elif buttonTime > 4: # very long press print('very long press') subprocess.call(sw_1_cmd_3) GPIO.add_event_detect(sw_1_pin, GPIO.FALLING, callback=sw_1_event, bouncetime=bounce_time) print(str(datetime.datetime.now())[:19] + ' sw_1: pin=' + str(sw_1_pin) + ', enabled=' + row['enabled'] + ', bounce_time=' + str(bounce_time) + ', cmd=' + row['command'])