Timer Issues

I'm having issues getting timer code to work. At this point the timed operation (solenoid valve) never turns on. My project is a self flushing litter box because let's face it, who likes to dump it. The algorithm is simple: x times per day, solenoid water valve on for y seconds. If float sensor = water, pump on fox z seconds. If float sensor = water> 60 seconds, shutdown and alarm.

#define VALVE 2
#define PUMP 3
#define SENSOR 4
#define ALARM 13


long cleaning_number = 6; // How many operations should be executed for day
long interval = long((1000L*60L*60L*24L)/cleaning_number); // Interval between cleanings in milliseconds

int valve_time=20;   // Time of opening valve in seconds
int pump_time= 25;   // Time of working pump in seconds
int counter=0;
long counter2=0; 
void setup() {
  pinMode(VALVE, OUTPUT);
  pinMode(PUMP, OUTPUT);
  pinMode(ALARM, OUTPUT);
  pinMode(SENSOR, INPUT_PULLUP);

  digitalWrite(VALVE, HIGH);
  digitalWrite(PUMP, HIGH);
  digitalWrite(ALARM, LOW);

  Serial.begin(115200);
  Serial.println("Start programming");
  Serial.print("Interval: ");
  Serial.println(interval);
}

void loop() {
  if(counter2*5000 > interval){
    counter2=0;  
    digitalWrite(VALVE, LOW);
    delay(valve_time*1000);
    digitalWrite(VALVE, HIGH);
    Serial.println("Valve activation");
  }
  if(digitalRead(SENSOR)){
    digitalWrite(PUMP, LOW);
    while(digitalRead(SENSOR)){
      counter++;
      delay(500);
      if(counter>pump_time*2){
         digitalWrite(PUMP, HIGH);
         while(true){
          digitalWrite(ALARM, HIGH);
          delay(300);
          digitalWrite(ALARM, LOW);
          delay(300);
         }
      }
    }
    digitalWrite(PUMP, HIGH);
    counter=0;    
  }
  delay(5000);
  counter2++;
}

You should not be using counter2 to figure out how many times through loop(). You need to use millis() to determine how many milliseconds have elapsed. Loop() will execute many times per milliesocond.