Method for controlling the temperature of a device (9, 10) for the post-treatment of the exhaust gases of a motor vehicle, the post-treatment device (9, 10) comprising a phase of normal operation in which it traps and accumulates pollutant elements from the exhaust gases and a regeneration phase during which these accumulated pollutant elements are burnt to regenerate the post-treatment device (9, 10), in which each regeneration phase is divided into a succession of fractionated periods (t 1 t 2) (t 2 t 3)..., in which the temperature of the exhaust gases entering the post-treatment device is alternately hotter, in a rich period, and colder, in a lean period, the method comprising a step of determining the duration of a rich or lean period, in which the duration of each lean and/or rich period is determined directly as a function of the duration of the rich and/or lean period preceding it, so that the surplus energy supplied in a rich period is compensated for by a deficiency of energy in a lean period so that the mean energy supplied to the post-treatment device (9, 10) allows the temperature leaving the post-treatment device (9, 10) to remain close, and on average equal, to a reference temperature (Ts ref) that is optimal for the regeneration phase, characterized in that it comprises a step of calculating the reference power (We ref) at the input of the post-treatment device (9, 10) so as to obtain the outlet reference temperature (Ts ref), using the following steps: - determining the sought-after outlet reference power (Ws ref) as a function of the reference temperature (Ts ref) by calculating Ws ref = Ts ref * Q exh * C p, where Q exh is the flow rate of the exhaust gases and C p is the heat capacity of the gases; - determining the reference power (We ref) at the inlet of the post-treatment device (9, 10) using the formula We ref = Ws ref + W losses where W losses represents an estimate of the power losses within the device, characterized in that it comprises a step of calculating the actual power (We) supplied in the post-treatment device (9, 10) using the following steps: -: measuring or estimating, in real time, the temperature (Te) and the flow rate of the gases (Q exh) entering the post-treatment device (9, 10); -: estimating or measuring the potential exothermal power (Wexo) represented by these gases; -: calculating the power entering the post-treatment device (9, 10), using the following formula: We = Te. Q exh. Cp gas + Wexo where Cp gas represents the heat capacity of the incoming gases, and characterized in that the rich period supplies the post-treatment device (9, 10) with a power (We) greater than the reference power (We ref) and in that it comprises a step of calculating the excess energy (E rich) supplied by the rich period using the calculation ∫ t 0 t 0 + D We ref − We ⋅ dt rich = E rich and characterized in that a lean period is initiated after the rich period and supplies the post-treatment device (9, 10) with a power (We) less than the reference power (We ref), and in that it determines, in a step, the duration of the lean period as a function of the rich period, using the following steps: -: calculating the missing energy (E lean) supplied by the lean period by comparison with the reference power (We ref) using the formula: ∫ We ref − We ⋅ dt lean = E lean -: comparing the missing energy (E lean) from the lean period against the excess energy supplied by the rich period (E rich) and determining the end of the lean period when these two energies compensate one another, namely when the following condition is satisfied: E lean = E rich - determining the sought-after outlet reference power (Ws ref) as a function of the reference temperature (Ts ref) by calculating Ws ref = Ts ref * Q exh * C p, where Q exh is the flow rate of the exhaust gases and C p is the heat capacity of the gases; - determining the reference power (We ref) at the inlet of the post-treatment device (9, 10) using the formula We ref = Ws ref + W losses where W losses represents an estimate of the power losses within the device, -: measuring or estimating, in real time, the temperature (Te) and the flow rate of the gases (Q exh) entering the post-treatment device (9, 10); -: estimating or measuring the potential exothermal power (Wexo) represented by these gases; -: calculating the power entering the post-treatment device (9, 10), using the following formula: We = Te. Q exh. Cp gas + Wexo where Cp gas represents the heat capacity of the incoming gases, -: calculating the missing energy (E lean) supplied by the lean period by comparison with the reference power (We ref) using the formula: ∫ We ref − We ⋅ dt lean = E lean -: comparing the missing energy (E lean) from the lean period against the excess energy supplied by the rich period (E rich) and determining the end of the lean period when these two energies compensate one another, namely when the following condition is satisfied: E lean = E rich