Time input widget and eventor

“time input” widget with start-stop time activated.
assigned to V50

when designated time is reached, what is the output of that widget to V50?

is it the time or 0/1?
because I wanted it to turn on a relay on d5/gp14. (on = 0)
and tried this rule to turn on relay:
When V50 is equal to 1 turn OFF gp14

is this the way to do it (not working though)?

BLYNK_WRITE(V50) {
  TimeInputParam t(param);

  // Process start time

  if (t.hasStartTime())
  {
    Blynk.virtualWrite(V51, 1);
  }
  else
  {
    // Do nothing
  }

  // Process stop time

  if (t.hasStopTime())
  {
    Blynk.virtualWrite(V51, 0);
  }
}

and then in Eventor:

When V51 is equal to 1 turn OFF gp14
When V51 is equal to 0 turn ON gp14

No.

Do you need Time Input?

I want to turn on/off my garden light and water fountain with a relay switch.

but it could be fun if it also could turn on/off automatic.
And “Time input” looks to be a good way to do this, it has a time interval feature.

Eventor could turn it on by setting it up a fixed time in the rule, but think it would be better with a time widget, then I can and easily change the time.

Time Input doesn’t do anything unless you provide coding for it i.e coding to check current time against ON and OFF times set in the widget.

Sample code exists on this site, check out the “Scheduler” project by @psoro

oh I see… could have been cool if the time input also returned a 0/1…

I’ll try and look into Psoro’s scheduler, thx for pointing it out.

I got it working with help from analyzing psoro’s scheduler project.

I got it boiled down to this… dont know if I could cut more out but its working with the time input widget.

// #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[] = "";  // Put your Auth Token here. (see Step 3 above)
SimpleTimer timer;
WidgetRTC rtc;

char Date[16];
char Time[16];

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, "", ""); //insert here your SSID and password
  rtc.begin();
  delay(10);
  
  timer.setInterval(100000L, sendWifi);
  timer.setInterval(60000L, syncRelay);
  timer.setInterval(1000,showCurrentTime);

}



BLYNK_WRITE(V50)//Fauntain 
{  
    sprintf(Date, "%02d/%02d/%04d",  day(), month(), year());
    sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());
  
    TimeInputParam t(param);
    Serial.println(Time);
  
    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 
{  
    sprintf(Date, "%02d/%02d/%04d",  day(), month(), year());
    sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());
  
    TimeInputParam t(param);
    Serial.println(Time);
  
    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();
}

funny after proclaiming I got it solved, I found some errors:

  • after midnight it wont sync relays
  • I cant turn of “automatic” setting.

Gonna move the project to WIP :slight_smile:

I am having myself similar problems with timers. Blynk guys are doing really a great job with the application upgrading, adding very interested and useful widgets all time. (specially for Android).
However, if here is something i could suggest to get improved is the timer widget. It would be great if it could work like a time input widget, which to be used as a timer requires a lot of coding in the hardware.
It is totally unpractical that to change the time parameter in the timer you have to stop the app running and get into the “programming” to change the time. Besides, I have not discovered yet about why the timers work some times and do not in many other times. Is totally unreliable.
Regards
rmerlob

In this I can input time, or change it to my needs on the go, is that what you are looking for?

Thanks tjohansen, Looks good at first sight.
I will try it.
What would it be the response if one the time inputs have all days disabled ?
Still, I thought main objective of Blynk was supposedly to reduce the need of coding to the maximum so its accessible to people with non programming expertise.
It would be great if “time input” writes a 0 or 1 if conditions are met.
Regards

I believe that was an initial marketing strategy (and still valid)… And Blynk has many features that can be easily done with minimal or no coding.

But anything with this much flexibility and customizable options will always require some degree of skill to maximise it’s potential.

Based on what I have seen and read… I think the main objective is as a customisable Graphical Control Interface for IOT. And that it is :stuck_out_tongue:

"Blynk is a Platform with iOS and Android apps to control Arduino, Raspberry Pi and the likes over the Internet.

It’s a digital dashboard where you can build a graphic interface for your project by simply dragging and dropping widgets."

This is effectively what the Time option in the Eventor Widget does… without needing code :wink:

Thanks Gunner for your comments.
Yeah, from your point of view or my point of view that is perfectly doable, however, if the “timer input” could work as a real timer, my grandma could set the parameters, while I don not see her being able to adjust timer and events.
Thanks again
Regards,

@rmerlob also when you publish your app to the world Eventor will not function for the the end users.

This issue with making the Input Timer the way many seem to want it, is that it relies on the App being online (like the Eventor) in order to switch those pins.

The current Timer takes the input, sends the data immediately to the Sketch, for processing via code, and then the timing is ready and availed for action, each and every time… even if server connection goes down (assuming coded properly for that).

So there are differing options, with differing levels of complexity, that offer differing levels of connection independence.

Hopefully your Grandma can use the Time Input widget as per the following revamped sketch. It’s really quite straightforward and easy to incorporate into your own projects.

/********************************************************************************* 
  EziSchedulerV2.ino   by Costas, 7 Sept 2017
  Scheduler with Time Input and obligatory OTA update facility for ESP's
  RTC widget (no pin allocation)
  LED V0
  Time Input V1
  To add more schedules simply copy BLYNK_WRITE(V1) function and change V1 to V2 etc
  and in activetoday() function add: Blynk.syncVirtual(V2); // sync scheduler #2 
***********************************************************************************/
#define BLYNK_PRINT Serial 
#include <ArduinoOTA.h>             
#include <ESP8266WiFi.h>        
#include <BlynkSimpleEsp8266.h> 
BlynkTimer timer;

#include <TimeLib.h>
#include <WidgetRTC.h>
WidgetRTC rtc;
char currentTime[9];

char auth[]   = "************"; 
char ssid[]   = "GargoyleTest";                     
char pass[]   = "************";                     
char server[] = "blynk-cloud.com"; 
bool clockSync = false;    

void setup() {
  Serial.begin(115200);
  Serial.println();
  Blynk.begin(auth, ssid, pass, server);
  ArduinoOTA.setHostname("EziSchedulerV2");       
  ArduinoOTA.begin();    
  timer.setInterval(60000L, activetoday);  // check every 60s if ON / OFF trigger time has been reached
  timer.setInterval(1000L, clockDisplay);  // check every second if time has been obtained from the server
}

BLYNK_CONNECTED() {
  rtc.begin();
}

void activetoday(){         // check if schedule #1 should run today
  if(year() != 1970){
    Blynk.syncVirtual(V1);  // sync scheduler #1  
  }
}

void clockDisplay(){  // only needs to be done once after time sync
  if((year() != 1970) && (clockSync == false)){ 
    sprintf(currentTime, "%02d:%02d:%02d", hour(), minute(), second());
    Serial.println(currentTime);
    clockSync = true;
  } 
}    

BLYNK_WRITE(V1) {   // Scheduler #1 Time Input widget  
  TimeInputParam t(param);
  unsigned int nowseconds = ((hour() * 3600) + (minute() * 60) + second());
  unsigned int startseconds = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);  
  unsigned int stopseconds = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
  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  
    //Schedule is ACTIVE today 
    if(nowseconds >= startseconds - 31 && nowseconds <= startseconds + 31 ){    // 62s on 60s timer ensures 1 trigger command is sent
      Blynk.virtualWrite(V0, 255);  // turn on virtual LED
      Serial.println("Schedule 1 started");
    }                  
    if(nowseconds >= stopseconds - 31 && nowseconds <= stopseconds + 31 ){   // 62s on 60s timer ensures 1 trigger command is sent
      Blynk.virtualWrite(V0, 0);   // turn OFF virtual LED
      Serial.println("Schedule 1 finished");
    }               
  }
}

void loop() {
  if(Blynk.connected()){ 
    Blynk.run();        
  }                     
  ArduinoOTA.handle(); 
  timer.run();
}
3 Likes

Thanks a lot Costas,
I will definitely try it.

thats the one i wanted but never fin until today big thanks

What it’s this?