logging.debug(' @Wc_1 move detected after: %s seconds ,keep going...', round((time.time() - last_time_move_detected), 2)) last_time_move_detected = time.time() time.sleep(1) elif no_move_time > 180: logging.debug(' @Wc_1 no move detected for 3 minutes, stop procedure') break else: time.sleep(0.1) # things to do after wc1 is free GPIO.remove_event_detect(gpio.WC1_MOVE_sensor) # Main Loop of the program while True: if WC1_OCCUPIED == False and gpio.is_wc1_door_closed() and gpio.is_wc1_motion_detected_by_PIR(): # change state of the WC1 to occupied WC1_OCCUPIED = True # SEND REST gpio.wc1_led_occupied() detection_counter += 1 logging.debug('#Main Thread | change state of the WC1 (Free --> Occupied) | time: %s | detection counter: %s', time.strftime("%H:%M:%S"), detection_counter) # start new thread start_thread = time.time() t = threading.Thread(target=wc1_worker, args=[]) t.start() t.join() logging.debug('#Main Thread | change state of the WC1 (Occupied --> Free) | thread total time(duration): %.2f \n\n\n', (time.time() - start_thread))