A fiber-optic hydrogen sensor based on Pd–Ta alloy films partially coated π-phase-shifted fiber-Bragg grating (FBG) is proposed and experimentally demonstrated. Three types of Pd–Ta alloy films with different Ta content were prepared via co-sputtering technology. Material characterization shows the transformation of Pd–Ta alloy to amorphous phase with the increase of Ta content, and the phase transition between α-PdTaHx and β-PdTaHx is inhibited at 2 % hydrogen concentration. Hydrogen sensing experiments show that in-situ temperature compensation is possible with Pd/Ta films partially coated on π-phase-shifted FBG. Moreover, the sensor's hysteresis phenomenon was eliminated with an increase in Ta content due to the first-order phase transition. Pd–Ta alloy films hydrogen sensor with a Ta content of 27 % is capable of in-situ temperature compensation, fast response, good stability, and reliability.