Automatic scheduler. ESP-01 with 4 Time Input Widgets

I modify All_days function. For now work, but still testing

 BLYNK_WRITE(V8)//All days
{  
  if (alldays==1) {         
    sprintf(Date, "%02d/%02d/%04d",  day(), month(), year());
    sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());

    TimeInputParam t(param);
  
    terminal.print("All Days Checked schedule at: ");
    terminal.println(Time);
    terminal.flush();
    int dayadjustment = -1;  
    if(weekday() == 1){
      dayadjustment =  6; // needed for Sunday, Time library is day 1 and Blynk is day 7
    }
    if(t.isWeekdaySelected(weekday() + dayadjustment)){ //Time library starts week on Sunday, Blynk on Monday
    terminal.println("ALL DAYS ACTIVE today");
    terminal.flush();
    if (t.hasStartTime()) // Process start time
    {
      terminal.println(String("Start: ") + t.getStartHour() + ":" + t.getStartMinute());
      terminal.flush();
    }
    if (t.hasStopTime()) // Process stop time
    {
      terminal.println(String("Stop : ") + t.getStopHour() + ":" + t.getStopMinute());
      terminal.flush();
    }
    // Display timezone details, for information purposes only 
    terminal.println(String("Time zone: ") + t.getTZ()); // Timezone is already added to start/stop time 
  //  terminal.println(String("Time zone offset: ") + t.getTZ_Offset()); // Get timezone offset (in seconds)
    terminal.flush();
  
     for (int i = 1; i <= 7; i++) {  // Process weekdays (1. Mon, 2. Tue, 3. Wed, ...)
        if (t.isWeekdaySelected(i)) {
        terminal.println(String("Day ") + i + " is selected");
        terminal.flush();
        }
      } 
    nowseconds = ((hour() * 3600) + (minute() * 60) + second());
    startsecondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
    //Serial.println(startsecondswd);  // used for debugging
    if(nowseconds >= startsecondswd){    
      terminal.print("ALL DAYS STARTED at");
      terminal.println(String(" ") + t.getStartHour() + ":" + t.getStartMinute());
      terminal.flush();
      if(nowseconds <= startsecondswd + 90){    // 90s on 60s timer ensures 1 trigger command is sent
        digitalWrite(pompa, LOW); // set LED ON
        Blynk.virtualWrite(V2, 1);
        // code here to switch the relay ON
      }      
    }
    else{
      terminal.println("All Day Device NOT STARTED today");
      terminal.flush();            
    }
    stopsecondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
    //Serial.println(stopsecondswd);  // used for debugging
    if((nowseconds >= stopsecondswd) && (stopsecondswd>startsecondswd)){
      digitalWrite(pompa, HIGH); // set LED OFF
      Blynk.virtualWrite(V2, 0);
      terminal.print("All day STOPPED at");
      terminal.println(String(" ") + t.getStopHour() + ":" + t.getStopMinute());
      terminal.flush();
      if(nowseconds <= stopsecondswd + 90){   // 90s on 60s timer ensures 1 trigger command is sent
        digitalWrite(pompa, HIGH); // set LED OFF
        Blynk.virtualWrite(V2, 0);
        // code here to switch the relay OFF
      }              
    }
    else{
      if(nowseconds >= startsecondswd){  
        digitalWrite(pompa, LOW); // set LED ON  TEST!!!!!
        Blynk.virtualWrite(V2, 1);
        terminal.println("All day is ON");
        terminal.flush();
      }          
    }
    if((nowseconds >= stopsecondswd) && (stopsecondswd<startsecondswd) && (nowseconds<startsecondswd)){
      digitalWrite(pompa, HIGH); // set LED OFF
      Blynk.virtualWrite(V2, 0);
      terminal.print("All day STOPPED at");
      terminal.println(String(" ") + t.getStopHour() + ":" + t.getStopMinute());
      terminal.flush();
      if(nowseconds <= stopsecondswd + 90){   // 90s on 60s timer ensures 1 trigger command is sent
        digitalWrite(pompa, HIGH); // set LED OFF
        Blynk.virtualWrite(V2, 0);
        // code here to switch the relay OFF
      }              
    }
  }
  else{
    terminal.println("All day INACTIVE today");
    terminal.flush();
    // nothing to do today, check again in 30 SECONDS time    
  }
  terminal.println();
}
}

Output is revert for my relay

We have uploaded new release with fixes to TimeInput and Terminal, so soon it will be available

2 Likes

Thanks a lot.

please help me… why start time only from 10 :00 >, if use from < 10:00…relay is not ON?

Hi @Kangmas_Hadi,
Could you please elaborate? not sure if I understand your post… :face_with_raised_eyebrow:
On the other hand, did you change the Time Input Widgets and RTC to your location?

i am from indonesia i was setting GMT + 7 asia/jakarta…if now the clock e.g at 06.00 a.m…the relay is ON stop time only can setting until under 10 :00… but above at 10:00 relay is can not setting ON.

if now the clock e.g at 18.00…the relay start time only can setting above 10 :00…but under 10:00 relay can not setting ON…

please help me to solve the case above…?

@Kangmas_Hadi do you have the very latest version of the app as a timezone bug was introduced in the previous version? Basically the widget reverted to UTC and that could explain why your ON and OFF were mixed up.

1 Like

hello you send me your code i want only 1 time input . i trying and always be wrong ? your code have 1 time input please send me your code and QR code thank you :slight_smile: have good time

Dear @tariktumanbay, I’m really sorry but this is not a code factory as you should understand…
You can start here:

https://community.blynk.cc/search

2 Likes

ok thank you psoro

1 Like

How can I change the timezone ?

For Time Input the procedure is normally to simply click on the widget whilst the project is running and you should see TZ. If it’s not there stop the project, click the widget and scroll to the bottom of the options and add TZ feature.

1 Like

YES, I saw that and took few minutes to get synced.
Thanks for the reply.

Two problems I faced

  1. When the display/buttons show “Device is ON”, the relay will be OFF.
    If it shows “Device is off”, the relay will be on…
    How to fix this ?

  2. If the board gets restarted (due to power failure), the relay stays in ON position, how to fix this ? I will have to use the app to turn it off . It happens even if an active timer is running. For example, if the timer is set to turn off the relay now, if the board gets restarted, the relay will stay ON!!

The code will need to be modified by you.

What is your level of experience with C++?

NO experience!!! :neutral_face: I will try…
I dont need this much functions.
Can you suggest me any alternative method to set timer (which works even after restarting) ?

There are lots of free online resources to help you learn C++
There are also lots of freelance C++ coders available if you don’t want to learn the language.

Time Input is the most powerful scheduler available, but it does require the Blynk project developer to have an understanding of C++.

if your relay has three connectors you can simply swap the wiring and it will work as intended. If it has two connectors you need to go into the code, but its not that hard. HIGH is used to send a signal and is usually associated with ON (e.g. connect an LED and it wil turn on) however relays work the other way round and are thus OFF. so swap the HIGH and LOWs in the code where it concerns the relays and your golden.

@wolph42 That question was 5 months ago :wink:

:joy::joy::joy::joy::joy::joy: