I think that you can send gcode commands from the ESP32 to the Duet to execute. Via HTTP or serial connection. I guess that this allows you to send gcode such as setting global variables that your conditional code can access. Others may know more details.