Missing something with attempt to understand Advanced Time Input

Yes, I have tried every possible choice for days, all days, no days, actual day, day before only, day after only. You are correct though, I do not have the hack and I see ALL days when NO days are selected

image

I agree wholeheartedly… most current examples offer semi-theoretical use cases, fine for those that can handle some coding, but no good for those that literally want a copy/paste “Pushenzee buttons and watchenzee blinkin lights” example.

However, I believe the developers are working on some totally improved & advanced Sketch Builder routines…


Meanwhile, here is my “final”? relatively copy/paste-able, start and stop time only (all days of the Week), shows stuff and toggles a digital pin (built-in LED on Wemos D1 Mini), example :stuck_out_tongue:

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <WidgetRTC.h>
BlynkTimer timer;
char auth[] = "xxxxxxxxxx";
char ssid[] = "xxxxxxxxxx";
char pass[] = "xxxxxxxxxx";
char currentTime[9];
char startTime[9];
char stopTime[9];
int SThour;
int STmin;
int STsec;
int SPhour;
int SPmin;
int SPsec;

WidgetRTC rtc;  // Set RTC widget.

void setup()
{
  pinMode(2, OUTPUT);  // Built-in LED
  digitalWrite(2, HIGH); // Turn OFF built-in LED
  Serial.begin(115200);  // Debug console
  Blynk.begin(auth, ssid, pass);
  rtc.begin();
  setSyncInterval(360);
  timer.setInterval(30000L, TimeCheck);  // Update Time Check every 30 seconds
}



BLYNK_CONNECTED() {
  Blynk.syncVirtual(V1); //  Synchronize Time Input Widget when connected
  TimeCheck(); // Initial Time Check
}


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



BLYNK_WRITE(V1) {  // Called whenever setting Time Input Widget
  TimeInputParam t(param);
  SThour = t.getStartHour();
  STmin = t.getStartMinute();
  STsec = t.getStartSecond();
  SPhour = t.getStopHour();
  SPmin = t.getStopMinute();
  SPsec = t.getStopSecond();
}



void TimeCheck() {  // call with timer every 30 seconds or so
  // Get RTC time
  sprintf(currentTime, "%02d:%02d:%02d", hour(), minute(), second());
  Serial.print("Current Time: ");
  Serial.println(currentTime);

  // Get Time Input Widget time
  sprintf(startTime, "%02d:%02d:%02d", SThour, STmin, STsec);
  Serial.print("Start Time: ");
  Serial.println(startTime);

  sprintf(startTime, "%02d:%02d:%02d", SPhour, SPmin, SPsec);
  Serial.print("Stop Time: ");
  Serial.println(startTime);

  if (hour() == SThour) {
    if (minute() == STmin) {
      Serial.println("Doing something now");
      digitalWrite(2, LOW); // Turn ON built-in LED
    } else if (minute() < STmin) {
      Serial.println("Will do something");
    } else if (minute() > STmin) {
      Serial.println("Did something");
    } else {
      Serial.println("Clueless");
    }
  }

  if (hour() == SPhour) {
    if (minute() == SPmin) {
      Serial.println("Stopping something now");
      digitalWrite(2, HIGH); // Turn OFF built-in LED
    } else if (minute() < SPmin) {
      Serial.println("Will stop something");
    } else if (minute() > SPmin) {
      Serial.println("Stopped something");
    } else {
      Serial.println("Clueless");
    }
  }
  Serial.println("----------");
}
[5887] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.5.0 on Arduino

[5893] Connecting to 10.10.3.13:8442
[10894] Connecting to 10.10.3.13:8442
[10923] Ready (ping: 19ms).
[11069] Time sync: OK
Current Time: 12:40:21
Start Time: 12:41:00
Stop Time: 12:42:00
Will do something
Will stop something
----------
Current Time: 12:40:51
Start Time: 12:41:00
Stop Time: 12:42:00
Will do something
Will stop something
----------
Current Time: 12:41:21
Start Time: 12:41:00
Stop Time: 12:42:00
Doing something now
Will stop something
----------
Current Time: 12:41:51
Start Time: 12:41:00
Stop Time: 12:42:00
Doing something now
Will stop something
----------
Current Time: 12:42:21
Start Time: 12:41:00
Stop Time: 12:42:00
Did something
Stopping something now
----------
Current Time: 12:42:51
Start Time: 12:41:00
Stop Time: 12:42:00
Did something
Stopping something now
----------
Current Time: 12:43:21
Start Time: 12:41:00
Stop Time: 12:42:00
Did something
Stopped something
3 Likes

Try the EziScheduler at Time input widget and eventor without any changes.

There are a couple of revisions after this version and the library hack but they are only required for rare case events.

@costas I have iOS so I do not have access to Eventor widget. So if I understand correctly, then I will not be able to follow this example but I will check it out, Thank you

@Gunner I appreciate the code you have provided, Thank you I will give it a try. BTW, I am not complaining at all.Without Blynk cut and paste programmers like me would have never become interested in coding, IOT etc. Like everything new, it can be confusing and frustrating.

The sketch doesn’t use Eventor.

I see that now since I have looked at the code. Was thrown by the title! I am loading it now
Thanks

Not bad for a first shot :slight_smile:

@Costas the code you referred me to worked as expected. I assigned the Time Input widget to V1 and an LED to V0. When the start time triggered, the LED was HIGH and I saw the print out in serial monitor. Awesome, Thank you. Now, I shall proceed to test the code that @Gunner provided. Thank you both very much. I then need to spend some time to try to understand what is going on in the code.

Well, I felt good about it until I saw yours :blush:

How did I miss that the first time around?? Oh well… this is how I learn :smiley:

Dunno but I have posted it several times and added minor tweaks as I will highlight below.

@mpo881 the library hack is just a couple of characters and documented at TimeInput Widget delivers ALL days selected when no day is selected - #7 by Darwini
The hack makes no days selected actually mean " I have selected no days as it’s the quickest way of doing scheduling without changing or resetting the times as I might want the same times in the future".

dayadjustment variable is required because Blynk start the week on a different day to the popular Time Library.

As per the library hack I just disable days with the Widget rather than using the reset time facility. Reset time facility means OFF.

I always thought that computers work with 0 and 1’s with 0 meaning OFF and 1 meaning ON but it turns out I was wrong. For Blynk computers off is -1 as documented from about post #66 at RF 433 Mhz on virtual pin doesn't want to send (with scheduling) - #66 by Costas

In the version of code I posted in that thread we were using unsigned int for variables associated with time and wrongly assuming no time or off would be zero. No time, as created with the reset facility, is actually -1 and therefore crashes the ESP with an unsigned int.

So you need to change:

  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);

To:

  int nowseconds = ((hour() * 3600) + (minute() * 60) + second());
  int startseconds = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);  
  int stopseconds = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);

@Gunner your code worked fine and toggled the built in LED at the chosen time triggers-Thank you!

@Costas thanks for the explanation and links to the hack. I will be reading this all for a bit yet trying to wrap my head around it all.

THANK YOU BOTH for your time and help.