Time counting using millis
This is one of those cases where the solution is simply to implement a
finite state machine. Consider a state machine with these three
states:


LIGH: light has been detected by at least one of the sensors, the
LEDs follow the light sensors
SHORT_DARK: neither sensor sees light, both LEDs are off
LONG_DARK: it has been at least three seconds since neither sensor
saw light, both LEDs are on.


The transitions between those states can be depicted by the following
state diagram:



where “darkness detected” means that no sensor sees light, and “light
detected” means that at least one sensor sees light.

As a general rule, it is a good practice to always draw a state diagram
before you start writing code. Once you are sure your diagram describes
the desired behavior, it is almost trivial to translate it into code.
Here is how I would code it:

void loop()
{
    bool light_k = analogRead(IN_K) &gt;= 1000;
    bool light_d = analogRead(IN_D) &gt;= 1000;

    static enum { LIGHT, SHORT_DARK, LONG_DARK } state;
    static uint32_t darkness_start;
    switch (state) {
    case LIGHT:
        digitalWrite(OUT_K, light_k ? HIGH : LOW);
        digitalWrite(OUT_D, light_d ? HIGH : LOW);
        if (!light_k &amp;&amp; !light_d) {
            darkness_start = millis();
            state = SHORT_DARK;
        }
        break;
    case SHORT_DARK:
        if (light_k || light_d) {
            state = LIGHT;
        } else if (millis() - darkness_start &gt;= 3000) {
            digitalWrite(OUT_K, HIGH);
            digitalWrite(OUT_D, HIGH);
            state = LONG_DARK;
        }
        break;
    case LONG_DARK:
        if (light_k || light_d) {
            state = LIGHT;
        }
        break;
    }
}