Use something like an Aube RC840T-240; it generates an isolated 24vac supply and has an isolated normally-open 24vac input for closing the contactor. Using anything else is liable to cause life-threatening spiciness if something goes wrong.
I use one for my addition's electric baseboard heat, and control it with a standard dry contact thermostat, but you could easily use a mosfet or relay controlled by an ESP32 or similar instead.
I use one for my addition's electric baseboard heat, and control it with a standard dry contact thermostat, but you could easily use a mosfet or relay controlled by an ESP32 or similar instead.