Place the oven rack in the center of the oven and preheat the oven to 375° F.
Spray a 2 quart casserole with vegetable spray
In a large saucepan, melt butter over medium heat. Add the diced onions and sweat for 4-5 minutes until the onions are softened and translucent.
Add the flour, salt, onion powder, dry mustard and pepper and stir constantly as it cooks and bubbles for about one minute. When there are no bits of dry flour or spices left, add the milk a little at a time, whisking after each addition until the milk is incorporated. Heat the sauce to a boil over medium high heat, stirring constantly. When the sauce begins to bubble cook for an additional minute, then remove from the heat. Stir in the chopped thyme.
Add 1½ cups of the grated mozzarella and ¾ cup of the pecorino romano and stir until the cheese is completely melted.
Add about a half cup of the sauce to the bottom of the casserole dish and spread evenly in the bottom.
Arrange ⅓ of the potatoes, overlapping each other in the bottom of the dish. Sprinkle ½ of the ham cubes over the potatoes.
Add ⅓ of the cheese sauce to the potatoes and gently spread with a spatula (doesn't have to be perfect).
Add another layer of potatoes, ham and sauce followed by the remainder of the potatoes and sauce.
Cover with a lid or aluminum foil and bake in the oven for 45 minutes.
Reduce the heat to 350° and remove the lid or foil. Continue to bake for 20 minutes.
Sprinkle on the remaining mozzarella and pecorino romano and bake for an additional 10-15 minutes or until the cheese is melted and browned.
Let the casserole cool for about 10 minutes before serving.