Need to set a FAILSAFE in an if else loop
This is one of those cases when thinking in terms of a finite state
machine makes the programming quite straightforward. Here I would
use three states:


In the OFF state, the switch is LOW and the solenoid is off
in the ON state, the switch is HIGH and the solenoid is on
in the DELAYING state, the switch is LOW, but the program is
keeping the switch HIGH for three seconds.


The possible transitions are:


OFF → ON when the switch goes HIGH
ON → DELAYING when the switch goes LOW
DELAYING → OFF after three second in this state
DELAYING → ON when the switch goes HIGH.


The last transition is meant to ensure that LOW states of the switch
that last less than three seconds do not turn the solenoid off.

And here is a tentative implementation. Keep your constants and your
setup(), and replace your loop() with this:

const uint32_t DELAY_TIME = 3000;  // time to deay the -&gt; off transition

void loop() {
    static enum {OFF, ON, DELAYING} state;
    static uint32_t start_delay;
    int floatswitch = digitalRead(FLOAT_PIN);

    switch (state) {
        case OFF:
            if (floatswitch == HIGH) {
                Serial.println("Switch closed");
                digitalWrite(SOLENOID_PIN, HIGH); // Turn the SOLENOID on
                state = ON;
            }
            break;
        case ON:
            if (floatswitch == LOW) {
                start_delay = millis();
                state = DELAYING;
            }
            break;
        case DELAYING:
            if (floatswitch == HIGH) {
                state = ON;
            }
            else if (millis() - start_delay &gt;= DELAY_TIME) {
                digitalWrite(SOLENOID_PIN, LOW); // Turn the SOLENOID off
                state = OFF;
            }
            break;
    }
}