Preheat the oven to 350°F. Butter a 9 × 13-inch baking dish.
In a medium saucepan, combine the heavy cream and half-and-half. Fully heat the mixture over medium heat but do NOT let it boil.
Add the onion, thyme, salt, and pepper to the hot mixture and whisk to combine, then reduce the heat to medium-low and simmer for a few minutes to let the flavors meld.
Add the flour and whisk to combine, then remove the pan from the heat.
Layer one-third of the potato slices in the buttered dish.
Sprinkle one-third of the ham on top and one-quarter of each cheese.
Pour one-third of the cream mixture on top.
Then repeat the layers twice more. Sprinkle the final one-quarter of the cheeses after the last cream layer.
Cover the dish with foil and bake for 40 minutes.
Then remove the foil and bake until bubbling and golden, about 20 more minutes.
Important: Allow the casserole to sit for at least 15 minutes before serving to let the sauce settle and thicken. Cut into squares or scoop out with a big serving spoon!
