Relay is not activated reliably

Unfortunately my english is not very good.
I have a problem. I have set 4 timers. Everyone should turn on a relay at a certain time and then switch it off again.
That works well. But what I noticed is: If the switching process is a timeout (ESP8266), then the relay does not switch. Only when I reset the Arduino and the “SyncAll” is carried out, the relay also.
How can I ensure that the relays are switched safely? Is it possible to set the pin to HIGH after a timeout?

best regards

    //===BLYNK=============================================
    #include <SPI.h>
    #include <Ethernet.h>
    #define BLYNK_PRINT Serial 
    #include <ESP8266_Lib.h>
    #include <BlynkSimpleShieldEsp8266.h>
    char auth[] = "-----";
    char ssid[] = "------";
    char pass[] = "------";
    #include <SoftwareSerial.h>
    SoftwareSerial EspSerial(8, 9); // RX, TX
    #define ESP8266_BAUD 9600
    ESP8266 wifi(&EspSerial);
    //===DHT22=============================================
    #include <DHT.h>
    #define DHTPIN A0
    #define DHTTYPE DHT22
    DHT dht(DHTPIN, DHTTYPE);
    //===DS18B20===========================================
    #include <OneWire.h>
    #include <DallasTemperature.h>
    #define ONE_WIRE_BUS A1
    OneWire oneWire(ONE_WIRE_BUS);
    #define TEMPERATURE_PRECISION 9
    DallasTemperature sensors(&oneWire);
    //===Timer=============================================
    #include <SimpleTimer.h>
    SimpleTimer timer;
    //===Timer und RTC=====================================
    #include <TimeLib.h>
    #include <WidgetRTC.h>

    WidgetRTC rtc;
    BLYNK_ATTACH_WIDGET(rtc, V5);

    WidgetLED led1(V17);
    WidgetLED led2(V18);
    WidgetLED led3(V19);
    WidgetLED led4(V20);

    #define BLYNK_DEBUG
    #define BLYNK_PRINT Serial

    ///////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////SETUP///////////////////////////////////////
    void setup()
    {  
      Serial.begin(9600);
      sensors.begin();                      //DS18B20 Begin
      
      delay(10);
      EspSerial.begin(ESP8266_BAUD);        //9600Bd fĂĽr ESP8266
      delay(10);
      Blynk.begin(auth, wifi, ssid, pass);  //Verbinde mit WLan
      delay(10);
      while (Blynk.connect() == false) {}
      rtc.begin();                          //DS1307 Begin
      timeStatus();                         //
      setSyncInterval(10);                  //TimeSync
      
      
      timer.setInterval(950L, sendUptime);  //nach 950ms sendUptime ausfĂĽhren
      timer.setInterval(9000L, leseDS18B20);//nach 9000ms leseDS18B20 ausfĂĽhren

    }

    ///////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////SYNC////////////////////////////////////////
    bool isFirstConnect = true;
    BLYNK_CONNECTED() {
      if (isFirstConnect) 
      {
        Blynk.syncAll();                //Synchronisiert die Pins mit dem Blynkserver
        isFirstConnect = false;
        Serial.println("SyncAll");
      }
    }
    ///////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////Lese DS18B20 und DHT22//////////////////////////////
    void leseDS18B20()
    {
      sensors.requestTemperatures();
      Blynk.virtualWrite(12, sensors.getTempCByIndex(0));
      Blynk.virtualWrite(13, sensors.getTempCByIndex(1));

      float h = dht.readHumidity();
      float t = dht.readTemperature();
      
      Blynk.virtualWrite(10, t); // virtual pin 10
      Blynk.virtualWrite(11, h); // virtual pin 11
      
      Serial.println("DS18b20 und DHT22 gelesen...");
    }
    ///////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////SEND UP/////////////////////////////////////////
    void sendUptime()
    {
      String currentTime;
      if((minute() < 10) && (minute() < 10) && (second() < 10)){currentTime = String(hour()) + ":0" + minute() + ":0" + second();}
      else{currentTime = String(hour()) + ":" + minute() + ":" + second();}
      if((minute() < 10) && (!second() < 10)){currentTime = String(hour()) + ":0" + minute() + ":" + second();}
      if((!minute() < 10) && (second() < 10)){currentTime = String(hour()) + ":" + minute() + ":0" + second();}
      
      //String currentTime = String(hour()) + ":" + minute() + ":" + second();
      String currentDate = String(day()) + "." + month() + "." + year();
      /*Serial.print("RTC Zeit: ");
      Serial.print(currentTime);
      Serial.print(" ");
      Serial.print(currentDate);
      Serial.println();*/

      Blynk.virtualWrite(V1, currentTime);
      Blynk.virtualWrite(V2, currentDate);
    }

    ///////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////LOOP////////////////////////////////////////////
    void loop()
    {
      Blynk.run();
      timer.run();

      if(digitalRead(2) == 1){led1.on();}else{led1.off();}
      if(digitalRead(3) == 1){led2.on();}else{led2.off();}
      if(digitalRead(4) == 1){led3.on();}else{led3.off();}
      if(digitalRead(5) == 1){led4.on();}else{led4.off();}
    }

Please Write 3 backticks instead of BBCode [c] and [/c].
This is 3 backticks
[c]This is BBCode[/c]

No one can help :frowning:

I’m unsure that the code is wrong.

Declare your pins and initialize your pin either inputs or outputs.

OK! So for example "pinMode (2, OUTPUT) ???

Did you intend this to be “minute() < 10) && (minute() < 10…”?

That piece of code is not going to work in any case, imagine this @SleXx:

it’s 16:05:50, and your code is not triggered, but it does exactly what your code is telling the hardware to do because not all requirements for your IF statement are met.

What you do there is: IF the first digit is smaller then 10 AND the second digit is smaller then 10 AND the last digit is smaller than 10, do something.

And it should be:

IF the first digit is smaller than 10, format with leading zero
IF the second digit is smaller than 10, format with leading zero
IF the third digit is smaller than 10, format with leading zero.

See the difference in logic?