Make the valve pipe work with a redstone signal.

This will make the vale pipe be open when a redstone signal is applied, and closed when one is removed. Since the code only operates when a redstone signal changes, using your hand should still be a viable option.