Timer - scheduler for gardenlight and fauntain (using eventor)

Huge help and inspiration from Costas and psoro’s Scheduler.

My goal was to have my garden fauntain and garden light with comfortable electronic switch.
But after seeing psoro’s scheduler, I could see it I might “need” to have a timer too.

It has two buttons to turn on fauntain and gardenlight individually.
It also have two timers.
And a automatic/manual switch.
One thing thats not visible is the rtc widget which you also have to add, mine is used on another tab.

It uses the Eventor widget to turn on the relay by looking at the virtualpin V51 and V52.

The wiring is fairly simple, I have used a powerboard that has two outputs, both 3.3v for the nodemcu and 5v for the relay.

The code

A huge part is borrowed from psoro’s Scheduler, but boilded down to only whats needed in my version.
So alot of credit goes to him and Costa.

// #define BLYNK_DEBUG
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <TimeLib.h>
#include <WidgetRTC.h>

char auth[] = "xxxxxx";  // Put your Auth Token here. (see Step 3 above)
SimpleTimer timer;
WidgetRTC rtc;

char Date[16];
char Time[16];
int manual=0;

long startsecondswd;            // weekday start time in seconds
long stopsecondswd;             // weekday stop  time in seconds
long nowseconds;                // time now in seconds



void setup() 
{
  WiFi.mode(WIFI_STA);
  Serial.begin(115200); // See the connection status in Serial Monitor
  Blynk.begin(auth, "xxxx", "xxxxx"); //insert here your SSID and password
  rtc.begin();
  Blynk.virtualWrite(V49, 1);
  delay(10);
  
  timer.setInterval(100000L, sendWifi);
  timer.setInterval(60000L, syncRelay);
  timer.setInterval(1000,showCurrentTime);

}


BLYNK_WRITE(V49)
{
  if (param.asInt()==1) 
  {
    manual=1;
  } 
  else 
  {
    manual=0;
  }
}



BLYNK_WRITE(V50)//Fauntain 
{  
    if (manual==1)
      { 
      
      sprintf(Date, "%02d/%02d/%04d",  day(), month(), year());
      sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());
    
      TimeInputParam t(param);
      Serial.println(Time);
      Serial.println(Date);
    
      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
            
      nowseconds = ((hour() * 3600) + (minute() * 60) + second());
      startsecondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
      Serial.println(startsecondswd);  // used for debugging
      if(nowseconds >= startsecondswd){    
        
        if(nowseconds <= startsecondswd + 90){    // 90s on 60s timer ensures 1 trigger command is sent
          Blynk.virtualWrite(V51, 1);
          // code here to switch the relay ON
        }      
      }
      else
      {
      }
      stopsecondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
      Serial.println(stopsecondswd);  // used for debugging
      if(nowseconds >= stopsecondswd){
        Blynk.virtualWrite(V51, 0);
        
        if(nowseconds <= stopsecondswd + 90){   // 90s on 60s timer ensures 1 trigger command is sent
          
         Blynk.virtualWrite(V51, 0);
          // code here to switch the relay OFF
        }              
      }
      else{
        if(nowseconds >= startsecondswd){  
          Blynk.virtualWrite(V51, 1);
          
         
        }          
      }
      }
      else
      {
       // nothing to do today, check again in 30 SECONDS time    
      }
      }
}



BLYNK_WRITE(V53)//Gardenlight 
{  
  if (manual==1)
      { 
      sprintf(Date, "%02d/%02d/%04d",  day(), month(), year());
      sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());
    
      TimeInputParam t(param);
      Serial.println(Time);
      Serial.println(Date);
    
      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
            
      nowseconds = ((hour() * 3600) + (minute() * 60) + second());
      startsecondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
      Serial.println(startsecondswd);  // used for debugging
      if(nowseconds >= startsecondswd){    
        
        if(nowseconds <= startsecondswd + 90){    // 90s on 60s timer ensures 1 trigger command is sent
          Blynk.virtualWrite(V52, 1);
          // code here to switch the relay ON
        }      
      }
      else
      {
      }
      stopsecondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
      Serial.println(stopsecondswd);  // used for debugging
      if(nowseconds >= stopsecondswd){
        Blynk.virtualWrite(V52, 0);
        
        if(nowseconds <= stopsecondswd + 90){   // 90s on 60s timer ensures 1 trigger command is sent
          
         Blynk.virtualWrite(V52, 0);
          // code here to switch the relay OFF
        }              
      }
      else{
        if(nowseconds >= startsecondswd){  
          Blynk.virtualWrite(V52, 1);
          
         
        }          
      }
    }
    else
    {
     // nothing to do today, check again in 30 SECONDS time    
    }
  }
}



void syncRelay()
{
  Blynk.syncAll();
  
  Serial.println("sync relay");
}


void showCurrentTime()
{
  String CurrentDate = String(day()) + '-' + monthShortStr(month()) + '-' + year();
  String CurrentTime = String(hour()) + ':' + minute() + ':' + second();
  String formattedDate = CurrentDate + String(" | ") + CurrentTime;
  Blynk.virtualWrite(V11,formattedDate);
}



void sendWifi() 
{
  Blynk.virtualWrite(1, map(WiFi.RSSI(), -105, -40, 0, 100) );
}



void loop() 
{
  Blynk.run();
  timer.run();
}
3 Likes

Simple, yet very effective. Would you mind posting a video or some pictures of this in action? I’d love to see the end result!

I haven’t build the modules into a waterproff box yet, and the Garden lights are my next diy project.
So this Timer project is only part of a bigger thing.

But will post more pictures when getting closer to complete it.

1 Like

Hi, excuse me, could you tell me why I follow the picture above(nodumcu) and use a led replaces relay, but can not control the led(use the usb can work). Thank you:grin: