Heat the oven to 375°F and grease a 9-by-13-inch dish. Brown the beef and onion with 1/2 teaspoon salt and drain.
Melt the butter in a saucepan, add flour for 1 minute, then whisk in milk, thyme, remaining salt and pepper. Simmer until lightly thickened and stir in 1 1/2 cups Gruyère.
Layer one-third potatoes, half the beef and one-third sauce. Repeat and finish with remaining potatoes and sauce.
Cover tightly and bake for 60 minutes. Uncover, add remaining Gruyère and bake 15 to 20 minutes until the potatoes are tender and top browned.
Rest for 15 minutes before serving.