nodeMCU - 2 loops at a time - one continuously and second every 10 seconds
Rather than using delay, use millis() and a variable to check if the some time has expired

void loop()
{
    static int check = 0;
    int now = millis();
    if (now &gt;= check) {
        if (digitalRead(pinD1)==1){
            digitalWrite(pinD0, HIGH);
            check = now + 20000;  
        } else {
            digitalWrite(pinD0, LOW);
            check = now;
        }
    }
    loop2();  
}

void loop2()
{
    static int check = 0;
    int now = millis();
    if (now &gt;= check) {
        if (json1=="ON"){
            digitalWrite(pinD0, HIGH);
        } else {
            digitalWrite(pinD0, LOW);
        }
        check = now + 20000;
    }
}