To begin, brush a casserole dish with butter. Set it aside.
Preheat your oven to 375 degrees.
Finely dice the onion.
In a saucepan, melt the butter over low heat and toss in the onions. Let the simmer and sauté gently until the onions are tender.
Meanwhile, spread half of your potatoes in the bottom of your prepared casserole dish.
Sprinkle in half of the ham and repeat with the remaining potatoes & ham.
When the onions are tender, stir in the flour. Let it cook for a minute.
Whisk in 3 cups of milk and the salt, pepper, and thyme. Cook this over medium heat, stirring continually until it comes to a boil and thickens. Remove it from the heat.
Slowly pour the lovely sauce over the top of the potatoes & ham.
Cover this with foil and bake for about 65-75 minutes, or until the potatoes are just about done. Remove the foil and bake 15 more minutes.