1. Preheat oven to 350°F. Grease a 9x13" pan and set aside.
2. Cook onion and butter over medium low until onion is tender. Add thyme and flour and cook for 1-2 minutes.
3. Turn heat to low and add milk a little bit at a time whisking between each addition. The mixture will thicken but as you continue adding and whisking, it will smooth out. Stir in chicken broth, salt and pepper bring to a boil and allow to boil 1 minute.
4. Place ⅓ of the potatoes topped with ⅓ of the ham and ⅓ of the sauce. Repeat layers ending with sauce on top.
5. Bake covered for 50 minutes. Uncover and bake 25-35 minutes longer or until potatoes are tender. Add the cheese during the last 15 minutes if using.
6. Cool at least 15 minutes before serving. Garnish with parsley