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