I would tend to approach it using new interrupt routines. Setting the relays to a neutral state could be fired by your fully opened, fully closed switches not the delayed polling from the driver. I'd like to do a generalized version of this but wouldn't get to it until maybe the weekend. If you need an extra delay after the switches close then instead of the interrupts perhaps just add switch checking in the loop routine. You could set a flag to let the loop routine know movement has started could also indicate whether opening or closing. The loop period could be shortened when waiting for movement than the normal nothing happening loop timer.