Detecting rates of change? For example, rapid humidity increase, diminishing particulate matter in the air

I want to trigger automations when something (humidity, pm2.5s, etc) rapidly increases, so I can turn on a fan or air purifier. I also want to detect when the rate has decreased enough that the fan/purifier is having a negligible effect, so I can turn them off.

How can I setup detecting a rate of change?

Screenshot 2023-07-18 at 9.09.40 AM

For example, I would like to detect the massive spike in pm2.5s in my kitchen and have the purifier turn on. Then after an equally massive spike downward, when it starts to trail off and the purifier has very little effect, detect the rate of change has slowed and turn it off because purifiers cost energy and are loud.

A derivative helper should achieve what you’re after.