Thinly slice the potatoes and onion - use a mandolin if you have one; you want them as thin as possible. In a medium saucepan, melt the butter and whisk in the flour. You should have a thick paste. Whisk in the milk (I started with the 2 1/2 cups the recipe called for, but wound up adding another splash because I thought it seemed a little thick) along with the thyme and some salt and pepper. Bring to a simmer and cook, stirring, for a minute.
Layer the potatoes and onion in a buttered baking dish; about a third of the potatoes, half the onions, another third of the potatoes, the rest of the onions and the rest of the potatoes. Pour sauce over top, and move a few of the potatoes around with the tip of a knife to let some of the sauce ooze between the layers.
Cover with foil and bake at 350F for 1 hour. Uncover, scatter with cheese if you like, and bake until lightly browned and potatoes are tender, about 20 minutes longer. Let stand for 5 minutes before serving.