solenoid doesnt start for logic as per flow chart

Hi,

I planned the below flow chart:

 for the code
 if (rainSenseReading < 500)  {
    rainMsg = F("It is raining heavily !");
    power_to_solenoid = false;
  }
  if (rainSenseReading < 300) {
    rainMsg = F("Moderate rain.");
    power_to_solenoid = false;
  }
  if (rainSenseReading < 200) {
    rainMsg = F("Light Rain Showers !");
    power_to_solenoid = false;
  }
  if (rainSenseReading > 500) {
    rainMsg = F("Not Raining.");
    power_to_solenoid = true;
  }
  else power_to_solenoid = false;

  if ((getHour() >= 19  && getHour() <= 23) || (getHour() >= 0 && getHour() <= 7)) {
    power_to_solenoid = false;
  }

  if (watrLvlSnsr >=400){
    power_to_solenoid = false;
  }

  // Turn on Solenoid Valve if soil moisture value less than 25
  if (val < DRY_SOIL_DEFAULT || power_to_solenoid == true) {
    soilMsg = F("Soil is dry. ");
    // do not water pot if its raining or if it is night.
    if (analogValue > 300) {
      soilMsg = soilMsg +  F("Watering the plant.");
      // turn solenoid off after 45 sec
      digitalWrite(solenoidPin, HIGH);
      digitalWrite(buzzerout, HIGH);
      if ((!power_to_solenoid) && (timer0 > interval)) {
        power_to_solenoid = false; // don't execute this again
        digitalWrite(solenoidPin, LOW);
        digitalWrite(buzzerout, LOW);

      }

    }
  }
  else {
    digitalWrite(solenoidPin, LOW);
    soilMsg = F("Soil is damp.");
    power_to_solenoid = false;
    digitalWrite(buzzerout, LOW);
  }

all I want if soil moisture sensor touches the lowest level once, it should run for 45 seconds. Full code can be found here

When you reach the level ‘set’ a flag and put 45 seconds into your timer.

In loop() check to see if the flag is set and there is still some time in the timer.
If above is true, turn on the water.
If above is false, ‘reset’ the flag and turn off the water.

.

These

if (rainSenseReading < 500)  {

}
if (rainSenseReading < 300) {

}
// etc

can all be true at the same time. Maybe you meant

if (rainSenseReading > 500)  {

}
else if (rainSenseReading > 300) {

}
// etc

…R

LarryD: If above is false, 'reset' the flag and turn off the water.

isnt this is what I am doing here:

if ((!power_to_solenoid) && (timer0 > interval)) {
        power_to_solenoid = false; // don't execute this again
        digitalWrite(solenoidPin, LOW);