Automating a hot-pool .Trying to add a delay between emptying and filling

Hello. My first post on this forum, and my first foray into Arudinos.

I have a hot-pool that is emptied on a pump wired independently of the Arduino. The Arduino is connected to a water sensor, which, if detecting the water level is too low, automatically turns on a solenoid connected to a relay to fill the pool back up. However I require that after the sensor detects the water level is too low it waits for half an hour before refilling as I don’t want it to start refilling until it is completely empty, plus everytime someone gets in or out, it activates the relay (relayOne), so I need a half an hour delay. No delay is needed to switch OFF the relay, so once the waterLevel is high, it should turn off the relay immediatly, and keep checking for waterLevel to be low, and then wait half an hour before turning on relayOne.

Additionally a temperature probe with a LCD screen shows the temperature, and if the temperature goes out of range, turns on a heater (relayTwo).

I can get everything working, except the delay.

I can see from the serial reader that the first if statement is continually writing the current millis to the delayStart variable, and thus the 3rd if statement will never be true.

Many thanks for your help

/*
  So far this program reads the water temperature and writes it to the LCD, and if the temperature
  drops below 40C, it turns on relayTwo, as long as water is detected and starting temperature is at least 15C
  It also monitors the water level and if water level is high enough, it turns off the first relay, and if too low, turns it on (after waiting 30 minutes)

*/

#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>
int relayOne = 3;
int relayTwo = 11;
int waterSensor = 9;
int led = 13;
int waterLevel;
float temp;
unsigned long delayStart = 0; // time delay started
unsigned long delayTime = 1800000; // wait 30 mins (1800000 ms) before turning on
bool delayRunning = false; // true if still waiting for delay to finish
#define ONE_WIRE_BUS 10 // Data wire of temp probe is plugged into pin 10 on the Arduino

OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with a OneWire devices
DallasTemperature sensors(&oneWire); // Pass oneWire reference to Dallas Temperature.
LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7)
byte degreeSign[8] = { //create degree sign
  0b00110,
  0b01001,
  0b01001,
  0b00110,
  0b00000,
  0b00000,
  0b00000,
  0b00000
};
void setup() {
  lcd.begin(16, 2);
  lcd.createChar(1, degreeSign);
  sensors.begin();
  pinMode(relayOne, OUTPUT);
  pinMode(relayTwo, OUTPUT);
  pinMode(waterSensor, INPUT);
  pinMode(led, OUTPUT);
  //digitalWrite(led,LOW);
}
void loop() {
  waterLevel = digitalRead(waterSensor);
  delay(100);
  if (waterLevel == LOW) // check if the water level is too low, if yes, turn on the relay after half hour

  {
    delayStart = millis();
    delayRunning = true;
  }
  else
  {
    digitalWrite(relayOne, HIGH);
  }

  if (delayRunning && ((millis() - delayStart) >= delayTime))
  {
    digitalWrite(relayOne, LOW);
    delayRunning = false;
  }
  sensors.requestTemperatures(); // Send the command to get temperatures
  temp = sensors.getTempCByIndex(0); // write the temperature into the temp float
  lcd.setCursor(0, 0);
  lcd.print(" Mikve Temp. is:");
  lcd.setCursor(1, 1); // Sets the location at which subsequent text written to the LCD will be displayed
  lcd.print(temp);
  lcd.write(1); //degree sign
  lcd.print("C ");
  lcd.print(sensors.getTempFByIndex(0));
  lcd.write(1); //degree sign
  lcd.print("F");
  delay(250);

  if (temp < 40 && temp >= 15 && waterLevel == HIGH) // check if the water temp is in the right range, and water is detected. If so, turn on heater
  {
    digitalWrite(relayTwo, LOW);
  }
  else
  {
    digitalWrite(relayTwo, HIGH);
  }

}

When you check the water level, you also need to check that delayRunning is false. Otherwise, as you observe, delayStart keeps getting set to the current time again & again.

Many thanks. Your answer was completely correct! So obvious once you're told!

Initially it was coming on after the delay and then immediatly turning off, so I added another 'if' as follows:

//===========This module checks the water level and fills it up if necessary======================
void waterCheck() {
  waterLevel = digitalRead(waterSensor);
  delay(100);
  if (waterLevel == LOW && !delayRunning) // check if the water level is too low, if yes, turn on the relay after half hour

  {
    delayStart = millis();
    delayRunning = true;

  }
  else
  {
    digitalWrite(relayOne, HIGH);
  }

  if (delayRunning && ((millis() - delayStart) >= delayTime))
  {
      digitalWrite(relayOne, LOW);
    
    if (waterLevel == HIGH) {
      delayRunning = false;
    }
      
  }
}