Fan control for temperature management

Wondering is there is something cookie cutter to do what I want, or if I’ll have to go it from scratch (I’d rather not reinvent the wheel, but don’t mind the legwork if Its needed)

My situation is, I have some very high ceilings in my house (probably 20’ at the high point), this creates some interesting effects where the temperature at the top of the room is substantially different than the temperature at the bottom of the room.

What I’d like to do is control a ceiling fan on the basis of this temperature difference and a ‘target’ temperature.

In other words - if the top of the room is hotter than the bottom, and I want the bottom hotter then then turn on the fan. If the top of the room is cooler than the bottom (hvac vents are near the top of the room) and I want it cooler on the bottom, the turn on the fan.