Preheat the oven to 200C/180C fan/Gas 6. Boil the sliced potatoes for 5 minutes until just tender. Drain well.
Melt the butter in a pan and gently cook the onion for 8 minutes until soft and sweet. Remove from heat.
Mix the cooked potatoes, onion, most of the cheese, the milk and thyme together in a bowl. Season well with salt and pepper.
Line a pie dish with half the pastry. Fill with the potato and cheese mixture, packing it in firmly.
Brush the edges with beaten egg, then lay the remaining pastry on top. Crimp the edges with a fork, cut a small steam hole in the top and brush all over with egg wash.
Bake for 30-35 minutes until the pastry is golden and the filling is bubbling through the steam hole. Let it rest for 5 minutes before slicing.