Temp increase or decrease as condition

I would have done what you did above, or I would have used two sensors and compared ambient to stack temp.

I am out of my league much beyond this. There is an app you should check out for an example of how to do a rise, in this case, humidity. Smart Humidity Fan Maybe you could adapt that, or use it as an example for a new app. Please be sure to ask the author if you decide to publish any of this code though.

Maybe someone else has a suggestion for you.