Automation for a Multi-Zone AC

I have a ‘dumb’ Multi-Zone AC. It has many zones and only a couple of temp sensors, it works as intended but the ‘hardware’ sensors only fit well a few zones and the rest often require manual on/off-ing to keep the same temp, which isn’t always practical (i.e. at night). I also have an ESPHOME device that feeds all the data from the AC to HA (and vice versa), so I can operate the AC from HA and read what state AC is in in sufficient detail.

What I want to achieve is an actual automatic operation. I have HA temp sensors in every zone, and want to write an automation that would basically check the individual sensor readings, compare them to a pre-set target temperature for that zone in HA and switch that zone on or off, and occasionally change the actual AC target temp since the sensor that physically controls it is in zone1 and will interfere.

As far as I understand the main logic will have to be repeating, say, every 30 seconds, checking and doing the same things with different zones.
So I would have a helper switch to enable the Auto mode, and also helper switch to ON/OFF every zone individually. Then within the main loop I want to do

# for every zone 
if checkZoneAUTO(ZONE) == ON {
	if 	(  # needs to be ON
		mainMODE==HEAT and tagetTEMP(ZONE) - currentTEMP(ZONE) > 1.0
		mainMODE==COOL and currentTEMP(ZONE) - tagetTEMP(ZONE) > 1.0
		if checkZoneHW(ZONE)==OFF then { # check that zone is OFF on the AC
			switchZONE(ZONE) # pressing the button on AC control
			if mainON == OFF then switchMAIN()
		} else { # needs to be OFF
			if checkZoneHW(ZONE) == ON then { # can't switch off the last zone on the AC
				if ZONE_ON_CNT > 1 then switchZONE(ZONE) 
				else switchMAIN()

# at the end of the loop check the target temp on the AC
if mainMODE == HEAT then X = 1.5 else X = -1.5
if checkZoneAUTO(ZONE1) == ON then TEMP_TARGET = tagetTEMP(ZONE1) + X 
else TEMP_TARGET = currentTEMP(ZONE) + X 
setACTEMP(TEMP_TARGET) # set target temp on the AC

I could probably “UI my way through it” just laying it out for every zone, but I’d like to make cleaner code. All I did before in HA was automating lights on some sensors, so I don’t have a good idea of how to properly implement this.

Looking for help.