Time Input Widget Readings

I have an issue with the Time Input Widget Serial readings. I am trying to get the following outputs from it :

  1. When day/days selected i want an output of 1, 0.

  2. When day/days selected and start/stop times set I want an output of 1, 1.

At the moment I get 1, 0 when day/days are selected which is correct, but i get 1, 0, 1, 1 when day/days and start/stop times set, when instead i want 1,1.
I have tried so many versions of this i have lost count. could someone have a look and advise please

BLYNK_WRITE(V47) //Time Input Widget
{
  TimeInputParam t(param);
  int dayadjustment = -1;  
  if(weekday() == 1)
  {
    dayadjustment = 6;
  }
  if (t.isWeekdaySelected((weekday() + dayadjustment)))
  {
    if (t.hasStartTime())
    {
     S1StTime = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);  //Get start time
     Serial.println(S1StTime);
    }
    if (t.hasStopTime())
    {
    S1SpTime = (t.getStopHour() * 3600) + (t.getStopMinute() * 60); //Get stop time
    Serial.println(S1SpTime);
    }
    for (int i = 1; i <= 7; i++)
    {
      if (t.isWeekdaySelected(i))   //Day/days set HERE I WANT 1, 0
      {
        ST1ScheduleActive = 1;
        ST1TimeActive = 0;
        Serial.println(ST1ScheduleActive);
        Serial.println(ST1TimeActive);
      }
       if (t.isWeekdaySelected(i) && t.hasStartTime() && t.hasStopTime())   //Day/days, start and end times set HERE I WANT 1, 1.
      {
       ST1ScheduleActive = 1;
       ST1TimeActive = 1;  
       Serial.println(ST1ScheduleActive);
       Serial.println(ST1TimeActive);
      }
    }
  }
}

Try this:

      if (t.isWeekdaySelected(i) && !t.hasStartTime())   //Day/days set HERE I WANT 1, 0
      {
        ST1ScheduleActive = 1;
        ST1TimeActive = 0;
        Serial.println(ST1ScheduleActive);
        Serial.println(ST1TimeActive);
      }
       else if (t.isWeekdaySelected(i) && t.hasStartTime() && t.hasStopTime())   //Day/days, start and end times set HERE I WANT 1, 1.
      {
       ST1ScheduleActive = 1;
       ST1TimeActive = 1;  
       Serial.println(ST1ScheduleActive);
       Serial.println(ST1TimeActive);
      }

Brilliant!!! works thank you.

1 Like

By the way how do you tag a conversation SOLVED?? I see no option on my screen?

You tap the pencil icon next to the title of the topic and choose “Solved” from the drop-down menu.

But, I’ve just done it for you.

Pete.

Thanks

@JustBertC been testing the code you posted and while i thought it was working if fact it is not. What i get now is
If I select Mon - no output data
if I select Mon, Tues - no output
if I select Mon, Tues, Wed, - no output
if I select Mon - Thurs - no output
if I select Fri - i get 1, 0
if I select Mon - Friday - I get 1, 0, 1, 0, 1, 0, 1, 0, 1, 0
if I seelct Sat - no output
if i select Sun - no output
if I select All days - 1, 0 X 7
And when you add in the start and stop times all the readings which were coming through turn to 1, 1.

BLYNK_WRITE(V47)
{
  TimeInputParam t(param);
  int dayadjustment = -1;  
  if(weekday() == 1)
  {
    dayadjustment = 6;
  }
  if (t.isWeekdaySelected((weekday() + dayadjustment)))
  {
    if (t.hasStartTime())
    {
     S1StTime = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
    }
    if (t.hasStopTime())
    {
    S1SpTime = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
    }
    for (int i = 1; i <= 7; i++)
    {
      if (t.isWeekdaySelected(i) && !t.hasStartTime())   //Day/days set HERE I WANT 1, 0
      {
        ST1ScheduleActive = 1;
        ST1TimeActive = 0;
        Serial.println(ST1ScheduleActive);
        Serial.println(ST1TimeActive);
      }
       else if (t.isWeekdaySelected(i) && t.hasStartTime() && t.hasStopTime())   //Day/days, start and end times set HERE I WANT 1, 1.
      {
       ST1ScheduleActive = 1;
       ST1TimeActive = 1;  
       Serial.println(ST1ScheduleActive);
       Serial.println(ST1TimeActive);
      }
    }
  }
}

You should add some meaningful serial.print statements yo give you more of a clue about the values of the various variables. Your current 1’s and 0’s don’t give any clue about what’s actually happening in the background.

Pete.

1 Like

What more serial prints could I add? All I am asking in each statement is if day or days selected no time a return of 1, 0 which are telling me that I have selected a day/days but no time and if day/days selected and start/stop times selected to get 1, 1. Only 2 statements

I think it is working as it should (well as it is written).

if (t.isWeekdaySelected((weekday() + dayadjustment)))

is only going to be true if the current day is selected in the app. Since today is Friday, that is why the only time you get outputs/serial prints is when you have Friday selected. Mon-Fri, and All days. Tomorrow (Saturday) will probably give you different results than today.

If you removed the for loop from this if statement it may give the results you are expecting.

BLYNK_WRITE(V47)
{
  TimeInputParam t(param);
  int dayadjustment = -1;  
  if(weekday() == 1)
  {
    dayadjustment = 6;
  }
  if (t.isWeekdaySelected((weekday() + dayadjustment)))
  {
    if (t.hasStartTime())
    {
     S1StTime = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
    }
    if (t.hasStopTime())
    {
    S1SpTime = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
    } 
 }
    for (int i = 1; i <= 7; i++)
    {
      if (t.isWeekdaySelected(i) && !t.hasStartTime())   //Day/days set HERE I WANT 1, 0
      {
        ST1ScheduleActive = 1;
        ST1TimeActive = 0;
        Serial.println(ST1ScheduleActive);
        Serial.println(ST1TimeActive);
      }
       else if (t.isWeekdaySelected(i) && t.hasStartTime() && t.hasStopTime())   //Day/days, start and end times set HERE I WANT 1, 1.
      {
       ST1ScheduleActive = 1;
       ST1TimeActive = 1;  
       Serial.println(ST1ScheduleActive);
       Serial.println(ST1TimeActive);
      }
    }
  
}
1 Like

I will try and let you know

1 Like

You could add a massive amount of additional information to your serial print output, to allow to see the value of the various variables in your ‘if’ statements and the value of your counter in your ‘for’ loop.
At the moment you’re assuming that the program flow is working in a particular way (which it clearly isn’t). Well designed debug output messages will show you what’s actually happening.

Pete.

1 Like