Roger Federer helped Switzerland reach the final of the Hopman Cup, but he needed two tie-breaks sets to edge by Stefanos Tsitipas in Perth.