Heat the oven to 375°F and grease a 3-quart baking dish.
Melt the butter in a wide skillet over medium heat and cook the onions with 1/4 teaspoon salt for 15 minutes, stirring often, until deep golden and soft.
Sprinkle in the flour and cook for 1 minute, then slowly stir in the broth, Worcestershire, thyme and pepper until the sauce lightly coats a spoon.
Layer half the potatoes in the dish, season with half the remaining salt and add half the onions, sauce and meatballs; repeat the layers.
Cover tightly with foil and bake for 55 minutes, until a knife slides easily into the potatoes.
Uncover, add the Gruyère and bake for 15 to 20 minutes, until browned at the edges, bubbling in the center and 165°F around the meatballs.
Rest the gratin for 10 minutes so the sauce thickens before spooning it out.