if statement help

This is a simple door up/down situation where light requirements, sensor requirements and button input requirements must be met. (chickens)

Many tries…no happy.

Force over-ride button inputs don’t behave.

const int dawnAdjustPot = A2;
const int duskAdjustPot = A3;
int dawnAdjustPotVar;
int duskAdjustPotVar;

const int photocellPin1 = A0;
const int photocellPin2 = A1;
int photocellReading1;
int photocellReading2;
int light1 = 0;
int light2 = 0;
int avgLight = 0;
const long pause = 1000;
unsigned long previousMillis = 0;

const int topLimitSwitch = 11;       //detect when the door is at the top home
const int bottomLimitSwitch = 12;    // detect when the door is at the bottom home
int valTopLimitSwitch = 0;
int valBottomLimitSwitch = 0;

const int doorUpButton = 7;         //door over-ride
const int doorCloseButton = 6;      //door over-ride
int valDoorUpButton = 0;
int valDoorCloseButton = 0;

int safeLightPin = 3;
int cautionLightPin = 4;
int dangerLightPin = 5;


// connect motor controller pins to Arduino digital pins
// motor one
int enA = 10;
int in1 = 9;
int in2 = 8;

void setup()
{
  pinMode (photocellPin1, INPUT);
  pinMode (photocellPin2, INPUT);

  pinMode(topLimitSwitch, INPUT);
  pinMode(bottomLimitSwitch, INPUT);

  pinMode(safeLightPin, OUTPUT);
  pinMode(cautionLightPin, OUTPUT);
  pinMode(dangerLightPin, OUTPUT);


  pinMode(enA, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);

  pinMode (dawnAdjustPot, INPUT);
  pinMode (duskAdjustPot, INPUT);

  pinMode (doorUpButton, INPUT);
  pinMode (doorCloseButton, INPUT);

  Serial.begin(9600);
}
void doorUp()
{
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  analogWrite(enA, 255); //motor speed
}
void doorDown()
{
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  analogWrite(enA, 255); //motor speed
}
void doorStop()
{
  //now turn off motors
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  analogWrite(enA, 0); //motor speed
}
void dangerLight()
{
  digitalWrite(dangerLightPin, HIGH);
  digitalWrite(safeLightPin, LOW);
  digitalWrite(cautionLightPin, LOW);
}
void cautionLight()
{
  digitalWrite(cautionLightPin, HIGH);
  digitalWrite(dangerLightPin, LOW);
  digitalWrite(safeLightPin, LOW);
}
void safeLight()
{
  digitalWrite(safeLightPin, HIGH);
  digitalWrite(dangerLightPin, LOW);
  digitalWrite(cautionLightPin, LOW);
}

void loop()
{
  photocellReading1 = analogRead(photocellPin1);
  photocellReading2 = analogRead(photocellPin2);

  light1 =  map (photocellReading1, 0, 1023, 0, 100);
  light2 =  map (photocellReading2, 0, 1023, 0, 100);

  avgLight = (((light1) + (light2)) / 2);

  dawnAdjustPotVar = analogRead(dawnAdjustPot);
  dawnAdjustPotVar = map (dawnAdjustPotVar, 0, 1023, 100, 0);

  duskAdjustPotVar = analogRead(duskAdjustPot);
  duskAdjustPotVar = map (duskAdjustPotVar, 0, 1023, 100, 0);

  valDoorUpButton = digitalRead(doorUpButton);
  valDoorCloseButton = digitalRead(doorCloseButton);

  valTopLimitSwitch = digitalRead(topLimitSwitch);
  valBottomLimitSwitch = digitalRead(bottomLimitSwitch);

  if ( (avgLight >= dawnAdjustPotVar) && (valDoorUpButton != LOW) && (valDoorCloseButton == HIGH) && (valTopLimitSwitch == HIGH) || (avgLight >= dawnAdjustPotVar) && (valDoorUpButton == LOW) && (valDoorCloseButton == HIGH) && (valTopLimitSwitch == HIGH))
  {
    doorUp();
  }
else
  {
    doorStop();
  }
  if ((avgLight <= duskAdjustPotVar) && (valDoorCloseButton != LOW) && (valDoorUpButton == HIGH) && (valTopLimitSwitch == HIGH) || (avgLight <= duskAdjustPotVar) && (valDoorCloseButton == LOW) && (valDoorCloseButton == HIGH) && (valBottomLimitSwitch == LOW))
  {
    doorDown();
  }
else
  {
    doorStop();
  }
  if (valBottomLimitSwitch == LOW)
  {
    doorStop();
    safeLight();
  }
  if ((valTopLimitSwitch == HIGH) && (valBottomLimitSwitch == HIGH))
  {
    cautionLight();
  }
  if (valTopLimitSwitch == LOW)
  {
    doorStop();
    dangerLight();
  }
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= pause)
  {
    previousMillis = currentMillis;

    Serial.print(avgLight);     // the average daylight reading
    Serial.println(" =avgLight");

    Serial.print(valTopLimitSwitch);
    Serial.println(" =valTopLimitSwitch");

    Serial.print(valBottomLimitSwitch);
    Serial.println(" =valBottomLimitSwitch");

    Serial.print(valDoorUpButton);
    Serial.println(" =valdoorUpButton");

    Serial.print(valDoorCloseButton);
    Serial.println(" =valdoorCloseButton");

    Serial.print(dawnAdjustPotVar);
    Serial.println(" =dawnAdjustPotVar");

    Serial.print(duskAdjustPotVar);
    Serial.println(" =duskAdjustPotVar");

    Serial.println("------------------------------- ");
  }
}

Can I suggest you add some print statements to doorUp() etc so you can see them being called in the debug stream then you can post some logs if you are still stuck. Hold down your troublesome override buttons while the debug print routine runs so you can see what changes.

Looking at your logic I cant see how the button press is going to override when its behind the test for light level. For example doorUp() cant be called unless avgLight >= dawnAdjustPotVar regardless of the state of other inputs.

It may help to describe whether the switch drives its signal HIGH or LOW when activated eg does valDoorUpButton == HIGH mean the UP button is pressed or not?