Controlling the relay using a motion sensor