Delaying action on State Change

Sounds like a job for a State Machine.

WaitingForSwitchOn
wait until switch is on
MotorMovingOut
wait until motor time elapses
Dwell
wait until dwell time elapses
WaitingForSwitchOff
wait until switch is off
MotorMovingIn
wait until motor time elapses
go back to WaitingForSwitchOn