Ah, the penny drops (for me): the .CoolReqOn and .HeatReqOn bits are the temperature-driven bang-bang control signal from the "unit," and your code tells the unit how many stages to run simultaneously.
That being the case, this scheme is similar to the "
Speed control using level switches" previous thread at
this link.
- Level in the tank/sump in the previous thread is analogous to thermal energy (and therefore temperature) in the warehouse in this thread.
- The high level switch signal in the previous thread is analogous to the .CoolReqOn signal in this thread.
- Flow into the tank/sump in the previous thread is analogous to thermal energy transfer into the warehouse from the hotter ambient conditions in this thread.
- Flow out of the tank/sump controlled via pump speed in the previous thread is analogous to thermal energy transfer out of the warehouse controlled via the A/C units in this thread.
- Incrementing or decrementing VFD/Pump speed by steps in the previous thread analogous to increasing or decreasing the number of stages to run, when .CoolReqOn is 1, in this thread
So what you want to do is to "give back" half of the stage increases each time. That said, is are not analogous between the two threads are the resolution of each control output: the VFD speed range from the previous thread can probably be commanded over a few hundred or thousand increments; the stages of this thread have at most four steps. So "giving back half" is more or less meaningless.
OP said they want to minimize energy. So the actual question is whether it will use less energy, over the long term, to
- EITHER run all of the stages, when .CoolReqOn becomes 1, and to cool the warehouse as quickly as possible and get the unit to set .CoolReqOn back to 0 as quickly as possible, so each cycle is as short as possible,
- [high power] times [short time] = energy usage
- OR run the minimum number of stages that will cool the warehouse less quickly over a longer cycle.
- [low power] times [long time] = energy usage
Another piece of the optimization is how much of a temperature excursion is allowable.
A similar problem was anaylyzed years ago for getting the best gas mileage (Miles per gallon; km [rt litre) with ICE cars that are stopping and accelerating. It turned out that slightly better mileage is achieved by accelerating hard to the target speed (speed limit), because an ICE is, in part, an air pump, and having the throttle more open during acceleration reduces the overall energy requirement
per mile. I'm not saying the same is true here, but who knows.