In an attempt to understand how to use Advanced Time Input I searched and found @Costas Scheduler.ino-Thank you.
I attempted to modify it for a Wemos D1 Mini with the relay shield attached. Keep in mind that I am not an experienced programmer. I am using the latest Blynk app on iOS.
The issue is that no matter what time I set the Time Input to in the future, I never get a respons from the relay when the Start time begins. I have selected a Start Time, Finish Time and Day of the Week. I added a button widget to the dashboard which is also programmed to D1 and I can operate the relay. My Time Input is assigned to V0 as in the example.
I have attached the code I am using below. Any suggestions would be appreciated.
// Scheduler.ino by Costas 22 March 2017
// Include library hack so scheduler is off when no days selected
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#define BLYNK_DEBUG
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
const int relayPin = D1;
unsigned int clockHour;
unsigned int clockMinute;
unsigned int clockSecond;
unsigned long daySeconds;
unsigned int dayNumber; // 1 Monday through to 7 Sunday, like Blynk day numbers
bool activeToday = false;
long start1seconds, stop1seconds;
bool scheduler = true; // default is scheduler on but it will be checked every 10s
bool schedulerStatusChanged = false; // check if status has changed
char auth[] = "xxxxxx";
char ssid[] = "xxxxxx";
char pass[] = "xxxxxx";
//char server[] = "xxxxxxxx";
SimpleTimer timer;
BLYNK_WRITE(V0) { // Weekday timer
activeToday = false;
TimeInputParam t(param);
unsigned int countondays = 0;
for (int i = 1; i <= 7; i++) { // Process weekdays (1. Mon, 2. Tue, 3. Wed, ... 7. Sun)
if (t.isWeekdaySelected(i)) {
countondays++;
if(i == dayNumber){
activeToday = true; // set false at start of function
}
Serial.println(String("Day ") + i + " is selected");
}
}
if (countondays == 0) {
scheduler = false;
}
else{
scheduler = true;
}
if (scheduler != schedulerStatusChanged){
schedulerStatusChanged = scheduler;
if(scheduler == false){
Serial.println(F("Scheduler1 currently disabled"));
Blynk.virtualWrite(V1,"Scheduler1 currently disabled\n");
}
if((scheduler == true) && (activeToday == true)){
Serial.println(F("Scheduler1 active today"));
Blynk.virtualWrite(V1,"Scheduler1 active today\n");
}
if((scheduler == true) && (activeToday != true)){
Serial.println(F("Scheduler1 not active today"));
Blynk.virtualWrite(V1,"Scheduler1 not active today\n");
}
}
if(scheduler == true){
if (t.hasStartTime()) // Process start time
{
start1seconds = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
}
else if (t.isStartSunrise())
{
Serial.println(F("Start at sunrise"));
}
else if (t.isStartSunset())
{
Serial.println(F("Start at sunset"));
}
if (t.hasStopTime()) // Process stop time
{
stop1seconds = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
}
else if (t.isStopSunrise())
{
Serial.println(F("Stop at sunrise"));
}
else if (t.isStopSunset())
{
Serial.println(F("Stop at sunset"));
}
}
}
void timeChecker()
{
if(activeToday == true){
if((daySeconds >= start1seconds)&&(daySeconds <= start1seconds + 10)){
digitalWrite(relayPin, LOW); // LED ON or relay active LOW ON
Serial.println(F("Device ON"));
}
if((daySeconds >= stop1seconds)&&(daySeconds <= stop1seconds + 10)) {
digitalWrite(relayPin, HIGH); // LED or relay active LOW OFF
Serial.println(F("Device OFF"));
}
}
}
void setup(){
Serial.begin(115200);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW);
Blynk.begin(auth, ssid, pass);
timer.setInterval(10000L, timeChecker); // check every 10s if any weekday scheduled events
}
void loop()
{
Blynk.run();
timer.run();
}