Blink without delay timer inside blink without delay If

Hey guys, im having a hard time getting a timer inside an if statement going. I took some time to study how to do the blink without delay to actuate a valve after X amount of time using a relay, but I want to also keep that digital output energized for 5 seconds to allow the ball valve to fully open, then denergize the relay, and then exit the if. The following code below executes the energize command after my set interval, but when it enters the 2nd blink without delay it completely ignores the timer. I get all of my serial.print commands so I know it executes to the end. Any help would be appreciated

//Opens actuator
  unsigned long actOpenEnergizeCurrentMillis = millis(); //Actuator Open Energize Timestamp
    if ((actOpenEnergizeCurrentMillis - actOpenEnergizePreviousMillis) >= actOpenInterval) {//Enters after 60 minutes
      Serial.println ("actuator opened");
      actOpenEnergizePreviousMillis = actOpenEnergizeCurrentMillis; //Rewrites time stamp
      if (actOpenState == LOW) { //If in a deenergized state
        Serial.println("Opening");
        actOpenState = HIGH; //Execute into energized state
        digitalWrite(52, actOpenState);
      if (actOpenState == HIGH){ //If in an energized State
          unsigned long actOpenDeenergizeCurrentMillis = millis(); // Actuator Open Deenergize Time Stamp
          if (actOpenDeenergizeCurrentMillis - actOpenDeenergizePreviousMillis >= actOpenDeenergizeOpInterval) {//Compared time stamp vs set interval of 5 seconds
            actOpenDeenergizePreviousMillis = actOpenDeenergizeCurrentMillis;//Rewrites time Stamp
            Serial.println ("5 second open time");
            if (actOpenState == HIGH) { // If actuator is energized
              actOpenState = LOW;//Deenergize
              digitalWrite(52, actOpenState);
              Serial.println("open denergized");
              actuatorStatus = OPENSTATE;
            }
          }
        }
      }
    }

You put the part that handles timing turning the relay off INSIDE the part that turns it on. That means that it only checks to see if it is time to turn it off at the exact time it turns it on. Of course it isn't then and it doesn't come back to check.

You need to break your loop into two parts based on whether or not the relay is on.

if(the valve is closed){
   if(it is time to open it) {
      open it and record the opening time
  }
}
else {  // valve is open
   if(it is time to close it) {
     close it and record the closing time
   }
}

Or you need a second timer. Only turn on the second one if they first one has expired.

Thank you for your replies. I seperated the two parts for open relay energize and open relay deenergize and i am still having the same issue with it executing all at the same time. This is the info i get from my serial monitor.

actuator opened
Opening
1
5 second open time
open denergized
0

my apologies if the codes all over the place and hard to read, its my first time programming!

void setup()
//Actuator Status
int actuatorStatus = CLOSESTATE;

//Actuator Open Function
int actOpenState = LOW;
const long actOpenInterval = 10000;
int actuatorOpenReady = 0;

//Actuator Close Function
int actCloseState = LOW;
const long actCloseInterval = 5000;



//Actuator Open Energize
unsigned long actOpenEnergizePreviousMillis = 0;

//Actuator Open Deenergize
unsigned long actOpenDeenergizePreviousMillis = 0;
const long actOpenDeenergizeOpInterval = 5000;

//Actuator Close Energize
unsigned long actCloseEnergizePreviousMillis = 0;

//Actuator Close Deenergize
unsigned long actCloseDeenergizePreviousMillis = 0;
const long actCloseDeenergizeOpInterval = 5000;

void loop()

//Opens actuator
  unsigned long actOpenEnergizeCurrentMillis = millis(); //Actuator Open Energize Timestamp
    if ((actOpenEnergizeCurrentMillis - actOpenEnergizePreviousMillis) >= actOpenInterval) { //Enters after 60 minutes
      Serial.println ("actuator opened");
      actOpenEnergizePreviousMillis = actOpenEnergizeCurrentMillis; //Rewrites time stamp
      if (actOpenState == LOW) { //If in a deenergized state
        Serial.println("Opening");
        actOpenState = HIGH; //Execute into energized state
        digitalWrite(52, actOpenState);
        actuatorOpenReady = 1;
        Serial.printlnln(actuatorOpenReady);
      }
    }

    if (actuatorOpenReady == 1){ //If in an energized State
          unsigned long actOpenDeenergizeCurrentMillis = millis(); // Actuator Open Deenergize Time Stamp
          if (actOpenDeenergizeCurrentMillis - actOpenDeenergizePreviousMillis >= actOpenDeenergizeOpInterval) {//Compared time stamp vs set interval of 5 seconds
            Serial.println ("5 second open time");
            actOpenDeenergizePreviousMillis = actOpenDeenergizeCurrentMillis;//Rewrites time Stamp
            if (actOpenState == HIGH) { // If actuator is energized
              actOpenState = LOW;//Deenergize
              digitalWrite(52, actOpenState);
              Serial.println("open denergized");
              actuatorStatus = OPENSTATE;
              actuatorOpenReady = 0;
              Serial.println(actuatorOpenReady);
            }
          }
        }

The posted code doesn't even come close to being able to compile. You've got the loop function inside the setup function.

Look at your code, the only if statements there are the timing ones. Look at the pseudo code I wrote for you in reply #1. Notice how it checks to see if the relay is open or closed FIRST and uses that information to decide which one of the timing statements to run.