The direct connection of photovoltaic (PV) power generation to the grid will threat to the stable operation of the power grid. Energy storage systems is available to reduce the impact on grid caused by PV power fluctuation. In this paper, a smoothing control algorithm based on least squares method is proposed. According to the degree of fluctuation, the algorithm automatically adjusts its parameters. So the smoothing and tracking of the waveform are realized at the same time. The validity of this strategy is verified through simulation with a battery lifetime model. Compared with the traditional filtering algorithm, this method can reduce the unnecessary charging and discharging of the energy storage system and prolong battery life while satisfying the smoothing goal. The research results have certain reference value for the actual PV stabilization strategy formulation.