Compare temperatures from 5 min ago (last update) / now

Hello,
I have a gas water heater and I wanna keep track of it (when it turns on) and how long it stays on.
I tried adding a vibration sensor but no luck,
Now i added a temperature sensor inside on the exaust. It was working like a charm until summer came.
I was using it to consider it on when it was above 37c. But I live in Rio de Janeiro and on summer we get mid 40´s (I forgot about that when I made the automation).
So here is my idea, I got a sonoff temperature sensor (sensor.water_heater_temperature) and I wanna compare the “update before last” temperature vs its temperature now (last update). And if the difference is grater than 10%, set it as on.

Is it possible? i can’t find where to get the update before last temperature.

Thanks

I haven’t tried it, but the derivative helper has an example with temperature changes.

The documentation says it “creates a sensor that “smooths-out” another sensor”, but this doesn’t sound right. A derivative is a rate of change, so it ought to be able to tell you the temperature is changing at a rate of +10° per 30 minutes (for example). A high positive / high negative should correspond to the heater going on / off, assuming the weather doesn’t change as fast as the heater.

tried it for a day. still couldn’t get what I wanted. I’ll keep tweaking it.

Thanks