Time Input Sync after drop in connection

Hello !
I am using time input widget to set start and stop time. Everything works fine.
The problem is -
Lets assume i have set the time for turning on a relay and during this time the internet was ok.
Later if the internet goes down then obviously the relay doesnt turn on due to lack of internet.
Now, once the internet is back the module doesnt turn on once it is connected. It remains OFF.

This happens the other way around too !!
if the relay has been turned on with in the set time and then, if the internet goes down and comes back online after the stop time has been passed ! Then the relay will stay ON the whole time…

Is there a way to read the Time Input widgets (virtual pin) value stored on the cloud server and accordingly turn on\off the relay ?? (I think the widget throws 1 and 0 at start and stop )

Hi there,

I kinda have the same issue (power failures) and am trying to implement the codes below in my sketch to make sure the internet connects again.

Then Sync all should work when the internet goes back online:

Hope this helps

I’d always recommend people not to use Blynk.syncAll, but to use Blynk.syncVirtual(vPin) on the virtual pins that need to be synchronised.


Hello !!

I have no problem reconnecting to the blynk cloud after the internet is back again.
I think i have failed to explain , I will give one more try…

Ex : Start time 11:00 AM - Stop time 2:00PM (Time the relay should turn on and off)
Now lets say the relay turned on at 11:00AM and waits to turn back off at 2:00PM, unfortunately the internet goes down at 1:50PM . So now the relay will remain ON due to lack of internet !
At 2:15PM the internet is back online !! And the device reconnects to blynk cloud no issues. But the relay will remain in the ON state… I will not turn OFF… It will turn off only at 2:00PM the next day if the internet is okay !!

Is there a way to know whether the time has passed and turn the relay OFF ?? by getting the value from the server ??

I understood your first explanation. I am not a very good coder, actually my coding sucks… but the idea should work.

If you use @PeteKnight 's suggestion and use the timer to resync at certain intervals…
Not sure if this is correct?

  //Blynk.syncAll();                                      //synchronize the state of widgets with hardware states
  //Blynk.syncVirtual(V0);                                //synchronize the state of virtual pins
  //Blynk.syncVirtual(V0,600000L);        // every 10 min
  Blynk.syncVirtual(V0,1800000L);       //every 30 min

Use the server as the timer (timer widget) for your relay… to switch a widget led on and off - led controls the relay.
So if the internet is on again, blynk should sync your relay with the state of the led.


I tried this but no luck !! In the app it will be showing ON so eventually that will be synced !! So it remains ON !!!

Another way is take the times you set and make a comparison to actual time so when internet reconnects a comparison with actual time is carried out to determine if the relay should be on or off

Hello !!
For this we need to have any RTC right like DS3231 ? Only then we can compare like you said !! Correct me if i am wrong !! Because everything is working on the server side and when no connection is available then there is data to compare right ??? :roll_eyes:

This is how I do it

void SetLed(int pin,
            unsigned long time,       //Current time in millis
            unsigned long start,      //Start time of LED channel
            unsigned long fadeup,     //Fadeup period in millis
            unsigned long period,     //Total photo period
            unsigned long fadedown,   //Fadedown period in millis
            unsigned long stop,       //Stop time of LED channel
            float pwm,                //Max value of brightness
            int Vpin)                 //ProgressBar
  if (time > start + fadeup && time <= start + period - fadedown)
    analogWrite(pin, pwm);
    int progress = round((pwm*100)/1023);
    Blynk.virtualWrite (Vpin, progress);   
  else if (time > start && time <= start + fadeup)
    float brightness;
    brightness = map(time - start, 0, fadeup, 0, pwm);
    analogWrite(pin, brightness);
    int progress = round((brightness*100)/1023);
    Blynk.virtualWrite (Vpin, progress);   
  else if (time > start + period - fadedown && time <= start + period)
    float brightness;
    brightness = map(time - start - period + fadedown, 0, fadedown, pwm, 0);
    analogWrite(pin, brightness);
    int progress = round((brightness*100)/1023);
    Blynk.virtualWrite (Vpin, progress);   
  else if (time > stop || time < start)
    analogWrite(pin, 0);
    Blynk.virtualWrite(Vpin, 0);

I am using my phone for the above so I cant find the triple back ticks

I guessed it !!

" ``` "
:point_up_2: if you want to copy the back ticks

I didn’t suggest that a timer should be used to trigger the Blynk.syncVirtual call(s).
The way to do it is to use the BLYNK_CONNECTED callback function to trigger the synchronisation whenever the device reconnects to Blynk.


1 Like

:point_up_2: Was your suggestion, sorry for the confusion.

Hello !!
I firstly dont know whether to ask this doubt\problem here or create a new topic, but as this related to Time input widget i feel i can post this here… if not please tell me i will create a new topic …

The problem is i am trying to read the t.isWeekdaySelected out side the BLYNK_WRITE function. TimeInputParam t(param); as this can only be called inside BLYNK_WRITE… As i am not a coder i think i have failed to explain properly, But i want to see the days selected in a void function…

But i found a post where @Gunner told to do so :point_down:

bool Mon;
bool Tue;
bool Wed;
bool Thu;
bool Fri;
bool Sat;
bool Sun;

And later check the if the days has been selected

BLYNK_WRITE(V1) {  // Called whenever setting Time Input Widget
  TimeInputParam t(param);

  Mon = t.isWeekdaySelected(weekday(1)); // Check if Monday is selected or not (1 = Yes, 0 = No)
  Tues = t.isWeekdaySelected(weekday(2));
  Wed = t.isWeekdaySelected(weekday(3));
  Thu = t.isWeekdaySelected(weekday(4));
  Fri = t.isWeekdaySelected(weekday(5));
  Sat = t.isWeekdaySelected(weekday(6));
  Sun = t.isWeekdaySelected(weekday(7));

Later checking if the days are selected

void checkdays1() {
  if (Mon == 1) {
  } else if (Tues == 1) {
  } if (Wed == 1) {
  } else if (Thu == 1) {
  } if (Fri == 1) {
  } else if (Sat == 1) {
  } if (Sun == 1) {

Every things seems to work properly !! But when i select only a single day ex: Sat… I does not trigger the event… But if a select Fri , Sat, Sun then it will trigger…

Can someone tell me where am i going wrong ?? @proietti @PeteKnight

How to assign the 'time input' param to a global var

I’d start by putting some serial print statements in your code, so that you can see the value of your variables and monitor the program flow through the if/else statements.


Okay i did what you said and yes even though i select a single day or all days, it is selecting all days
Serial monitor output

Mon selected
Tue selected
Wed selected
Thu selected
Fri selected
Sat selected
Sun selected

I am not understanding how to read the days selected from Blynk App !!

I think we’d need to see your full code to be able to provide more specific feedback.


Here is the code

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define BLYNK_PRINT Serial
#include <TimeLib.h>
#include <WidgetRTC.h>
WidgetRTC rtc;
BlynkTimer timer;

bool MonWeekDay;
bool TuesWeekDay;
bool WedWeekDay;
bool ThuWeekDay;
bool FriWeekDay;
bool SatWeekend;
bool SunWeekend;

char ssid[] = "xxxxxxxxx";
char auth[] = "xxxxxxx";
char pass[] = "xxxxxxxx" ; 

void setup(){
  Serial.begin(115200);  // Debug console
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(10000L, checkdays);

void loop()

BLYNK_WRITE(V1) {  // Called whenever setting Time Input Widget
  TimeInputParam t(param);

  MonWeekDay = t.isWeekdaySelected(weekday(1));// Check if Monday is selected or not (1 = Yes, 0 = No)
  TuesWeekDay = t.isWeekdaySelected(weekday(2));
  WedWeekDay = t.isWeekdaySelected(weekday(3));
  ThuWeekDay = t.isWeekdaySelected(weekday(4));
  FriWeekDay = t.isWeekdaySelected(weekday(5));
  SatWeekend = t.isWeekdaySelected(weekday(6));
  SunWeekend = t.isWeekdaySelected(weekday(7));

void checkdays() {
  if (MonWeekDay == 1) {
    Serial.println("Mon Selected");
  } else if (TuesWeekDay == 1) {
    Serial.println("Tue Selected");
  } if (WedWeekDay == 1) {
    Serial.println("Wed Selected");
  } else if (ThuWeekDay == 1) {
    Serial.println("Thu Selected");
  } if (FriWeekDay == 1) {
    Serial.println("Fri Selected");
  } else if (SatWeekend == 1) {
    Serial.println("Sat Selected");
  } if (SunWeekend == 1) {
    Serial.println("Sun Selected");

first i would like to read the input from the app side… later i will call the function on what to do if the condition is met…

Are you sure this syntax is correct?
I would have expected this:
MonWeekDay = t.isWeekdaySelected(1);


:thinking::thinking: now you are putting me in more confusion :joy:
Can you please tell if that is wrong ??

for (int i = 1; i <= 7; i++) {
    if (t.isWeekdaySelected(i)) {
      Serial.println(String("Day ") + i + " is selected");