function call with delayed execution within once-only if-condition

An if-condition is executed once only after state change; within this if-condition the current time A is read and a function X is called where a command is to be executed after a specific delay Y using the time A plus an offset: Y = A + offset.

Does the function X need to be called again until delay Y is reached?

More specifically, here is the if-condition within void loop()

            // check high level sensor
            hiLvlState = digitalRead(sensorPinH);
            if (hiLvlState != lastHiLvlState) {   // state change detection to high level water
              if (hiLvlState == HIGH) {
                startTime2 = millis(); // remember time of high level detection
                lastHiLvlState = hiLvlState; // set lastHighLevelState to HIGH, run this routine only once
                valveDelayedClosure();
              }
            }

If hiLvlState has a change of state to HIGH, then above code needs to be executed once only.

The variable startTime2 reads the current time.

The function valveDelayClosure () is to use this startTime2 and the current time to delay the execution of electroValve closure.

valveDelayClose is a variabel with a fixed value.

// perform when high level is detected with valve open
// delayed valve closure

void valveDelayedClosure ()
{
  currentTime2 = millis();
  if (currentTime2 - startTime2 > valveDelayClose) {
    digitalWrite(electroValve, LOW);
    valveState = digitalRead(electroValve);
    digitalWrite(alarmPin, LOW);
  }
}

If the valveDelayClosure is only called once, during the first pass through the initial if-condition then how would this be best coded so that the electrovalve is effectively closed after this set delay?

Or should a variable (flag) be set within this once-only execution, and outside this "once-only if" write another if condition calling for the function dependent on the state of this flag?

I would set a flag and use that that, together with the elapsed time, to decide if/when the action should happen. Keep each piece of your code as simple as possible.

...R

Robin2:
I would set a flag and use that that, together with the elapsed time, to decide if/when the action should happen. Keep each piece of your code as simple as possible.

...R

Thanks!!