Timer widget - what is the output?

HAPPY CHRISTMAS TO YOU ALL :slight_smile:

timer input widget functionality question

as per here: https://examples.blynk.cc/?board=ESP8266&shield=ESP8266%20WiFi&example=Widgets%2FTimer

it says the server sends a LOW or HIGH to the virtual pin when the start/end time occurs.

how do i code this? is the value of the vpin stored as a variable?

like this:


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "YourAuthToken";

char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

BLYNK_WRITE(V5)
{
  // You'll get HIGH/1 at startTime and LOW/0 at stopTime.
  // this method will be triggered every day
  // until you remove widget or stop project or
  // clean stop/start fields of widget
  timerOne = param.asInt();
  Serial.print("Got a value: ");
  Serial.println(param.asStr());
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);

  timer.setInterval(15 * 1000L, relaysTimerOne); // check timer status every X seconds
}

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

void relaysTimerOne()
{
  Serial.print(currentTime);
  Serial.println(F(": checking for timers"));

  if (timerOne == HIGH) //
  {
    digitalWrite(solenoidOne, LOW); // LOW means OPEN
    Blynk.virtualWrite(V11, 255); //FLOW led Blynk app
    Serial.print(F("relaysTimerOne() = timerOne OPEN : "));
    Serial.println(timerOne);
  }
  else if (timerOne == LOW)
  {
    digitalWrite(solenoidOne, HIGH); // HIGH means CLOSED
    Blynk.virtualWrite(V11, 0); //FLOW led Blynk app
    Serial.print(F("(relaysTimerOne() = timerOne CLOSED : "));
    Serial.println(timerOne);
  }
}

its not triggering the solenoid and i know i am missing something, but it is not well documented?

i get serial print of:

Got a value: 83760

but what does this mean? can i convert it? w

or could i be using the more complicated timer input widget?

Hi Dave, Merry Christmas!

So, you’re saving the integer value from the vPin to a variable called timerOne but then instead of printing-out the value of timerOne you’re printing-out a string version of the same data.
Incidentally, timerOne isnt declared as a global (or local for that matter) variable, so your code as posted won’t compile.

why not change this:

to this:

Serial.println(timerOne);

and declare int timerOne; at the top of your code.

Pete.

timerOne is declared as an int (but i forgot to add it to the code i posted)

it prints our a number regardless of if it is int or string

my question is:

as per here: https://examples.blynk.cc/?board=ESP8266&shield=ESP8266%20WiFi&example=Widgets%2FTimer

it says the server sends a LOW or HIGH to the virtual pin when the start/end time occurs.

how do i code this? is the value of the vpin stored as a variable?

the example says:

// You’ll get HIGH/1 at startTime and LOW/0 at stopTime.
// this method will be triggered every day
// until you remove widget or stop project or
// clean stop/start fields of widget

i don’t get high/low - i get a number that is not one or zero.

Are you sure that you’ve used the Timer widget and not the Time Input widget?

Pete.

am i allowed to swear here?

$^%@^$%$@#^&&&**((&(&*%%$@

i’ve been using the fkn wrong widget.

grrrr.

Ha Ha Ha.

Too much home-brewed hooch on Xmas day?

Pete.

1 Like

i started this last week, but must have forgotten what i had in mind…

been bashing ma head all arvo!

needed a reality check, thanks - hopefully i can get back on track now!

we’re now at level 2 water restrictions, so now need a smart irrigation system…

:pray: :cloud_with_rain:

YAY!

its worked! thanks Pete.

and all our rain prayers are being sent to the firegrounds… it’s been a hell of a summer already :hot_face:

but say if i also wanted to a have a “time remaining” countdown, could i get that from the TimeLib functions?

EDIT - and seems you cant cancel a timer? that’s not great.

maybe i have to use the Blynk Timer?

The problem is that you don’t know the time remaining with the Timer widget, it just sends a “0” when its time to turn off.

You’d need to use the Time Input widget, with start and stop time enabled, and the RTC widget, and you could then do some simple maths.

The numbers you were seeing before are seconds since midnight, so with Stop time enabled you’d get two parameters which will be start time in seconds since midnight and stop time in seconds since midnight.
If you convert the current time (obtained via the RTC widget) into seconds since midnight then it’s up to you to manually check if the On time has been met and turn your relays on, then check to see if the Off time has been met and turn them off again.
On time remaining will be off time minus current time, converted from seconds into minutes and seconds.

Time until the next On time will be the remainder of today, plus the time from midnight until the next start time, converted into HH:MM:SS unless you have multiple timers to give several on/off cycles per day.

You can also turn on days of the week if you want different timing cycles on weekends for example.

Have fun!

Pete.

1 Like