Hi mates!
I have done a small project to replace the “Elro KT100 Thermostat” and use Blynk instead for a friend of mine.
This is the ugly device to be replaced:
The controller works together with two different schedulers (Monday-Friday and Saturday-Sunday).
The main tab is like this:
In this tab you can see the two schedulers. My colleague will be able to activate/deactivate them or press the On/Off button to run the system manually without any scheduler.
The system remembers the last choice when you pressed Manual/Auto button so once you leave the system in “Auto” again, there’s no need to select the schedulers.
The On/Off button is the new “Styled button” so it changes according temperature and status:
-Scheduler is ON and the Relay is activated (the temperature is low):
-Scheduler is ON and the Relay is deactivated (the temperature is high):
-Scheduler is OFF and the Relay is deactivated. The system is waiting for a new “day”:
-System is Off (On/Off button has been pressed)
-System is in Manual mode and Relay is activated (the temperature is low):
-System is in Manual mode and Relay is deactivated (the temperature is high):
Using the setup “tab” my colleague will be be able to adjust the sensor to modify its values (rudimentary calibration), fix the temperature he wants at home, adjust the hysteresis to turn on-off the heater and fix a temperature in which the system will send a notification to advise the temperature is low than “x” degrees.
At the same time, there’s a label showing that the Sensor is OK or not according its status (3 “bad” readings and the system is stopped automatically…safety first!)
Other “tab” to Reboot the ESP if needed.
The board I’m using for this purpose is the Lolin NodeMCU 1.0, the temperature sensor is the well-known ds18b20 and a small Relay board:
The ds18b20 goes to Pin D7 and the Relay to Pin D1
The code is the next one:
(Remember, I’m NOT a coder… the code can be improved but to be honest I’m quite happy as it is right now)
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <TimeLib.h>
#include <ArduinoOTA.h> // for local OTA updates
#define TestLED 5 // on board LED pin assignment
#define BLYNK_GREEN "#23C48E"
#define BLYNK_BLUE "#04C0F8"
#define BLYNK_YELLOW "#ED9D00"
#define BLYNK_RED "#D3435C"
#define BLYNK_DARK_BLUE "#5F7CD8"
BlynkTimer timer;
//********************* CLOCK DETAILS *********************************************
#include <WidgetRTC.h>//Blynk
WidgetRTC rtc;
//*********************************************************************************
//********************* ds18b20 DETAILS ******************************************
#include <OneWire.h> //ds18b20 Temp
#include <DallasTemperature.h> //ds18b20 Temp
#define Pin D7// pin DATA ds18b20
OneWire oneWire(Pin); // OneWire PIN DATA
DallasTemperature sensors(&oneWire); // DallasTemperature library
//*******************************************************************************
//********************* SECTION TO COMPLETE WITH YOUR DETAILS *************
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
char ssid[] = "xxxxxxxxxxxx";
char pass[] = "xxxxxxxxxxxxxxxxx";
char cloudserver[16] = "blynk-cloud.com";
char localserver[16] = "xxx.xxx.xxx.xxx";
char OTAhost[] = "OTA-Heater"; // Optional, but very useful
//*********************************************************************************
//********************** variables*************************************************
long startsecondswd; // weekday start time in seconds
long stopsecondswd; // weekday stop time in seconds
long nowseconds; // time now in seconds
bool isFirstConnect = true;
String displaycurrenttimepluswifi;
int wifisignal;
int manual=0;
int manualpoweron;
int oldstatus;
int mondayfriday;
int saturdaysunday;
int mon_fri_relay = 0;
int sat_sun_relay = 0;
int mondayfridayactive;
int saturdaysundayactive;
int warning=0;
int stopsystem=0;
int low_notify=0;
unsigned int myServerTimeout = 3500; // 3.5s server connection timeout (SCT)
unsigned int myWiFiTimeout = 7500; // 3.2s WiFi connection timeout (WCT)
unsigned int functionInterval = 7500; // 7.5s function call frequency (FCF)
unsigned int blynkInterval = 25000L; // 25.0s check server frequency (CSF)
float temp;
float adjustment;
float newtemp;
float desiredtemp;
float hysteresis;
float limitinf;// histéresis inferior
float limitsup;// histéresis superior
float notification_temperature;
String displaycurrenttime;
char Date[16];
char Time[16];
//*********************************************************************************
void setup()
{
pinMode(TestLED, OUTPUT);
digitalWrite(TestLED, LOW); // set LED OFF
Serial.begin(115200);
Serial.println("\n Starting");
if(WiFi.status() == 6){
Serial.println("\tWiFi not connected yet.");
}
timer.setInterval(blynkInterval, checkBlynk); // check connection to server per blynkInterval
timer.setInterval(1000L, activetoday); // check every 1s if schedule should run today
timer.setInterval(5000L, clockvalue); // check value for time
timer.setInterval(5000L, sendWifi); // Wi-Fi singal
timer.setInterval(4000L, CheckTemp); // Check Temperature
timer.setInterval(4000L, Heartbeat); // Heartbeat
timer.setInterval(20000L, CheckSensorTemp); //Check Sensor Temp
unsigned long startWiFi = millis();
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED){
delay(2000);
if(millis() > startWiFi + myWiFiTimeout){
Serial.println("\tCheck the WiFi router. ");
break;
}
Blynk.config(auth, localserver,8080);
checkBlynk();
}
rtc.begin(); //RTC CLOCK BEGIN
sensors.begin();// Sensor ds18b20
ArduinoOTA.setHostname(OTAhost); // for local OTA updates
ArduinoOTA.begin(); // for local OTA updates
}
void reconnectBlynk() {
if (!Blynk.connected()) {
if(Blynk.connect()) {
BLYNK_LOG("Reconnected");
Blynk.syncVirtual(V4,V5,V6,V7);
delay(50);
Blynk.syncVirtual(V1,V2,V8,V9);
delay(50);
Blynk.syncVirtual(V12,V14,V15,V16);
delay(50);
} else {
BLYNK_LOG("Not reconnected");
}
}
}
BLYNK_CONNECTED()
{
if (isFirstConnect) {
timer.setTimeout(100, notify_start);
isFirstConnect = false;
}
}
void notify_start ()
{
Blynk.notify("Heater Starting!!");
Blynk.virtualWrite(V8, " ");
Blynk.virtualWrite(V20, " ");
Blynk.syncVirtual(V4,V5,V6,V7);
delay(50);
Blynk.syncVirtual(V1,V2,V8,V9);
delay(50);
Blynk.syncVirtual(V12,V14,V15);
delay(50);
Blynk.syncVirtual(V16,V21);
delay(50);
}
BLYNK_WRITE(V10)
{
adjustment = param.asFloat();
}
BLYNK_WRITE(V16)
{
hysteresis = param.asFloat();
limitinf = (desiredtemp-hysteresis);
Blynk.virtualWrite(V14, limitinf);
delay(20);
limitsup = (desiredtemp+hysteresis);
Blynk.virtualWrite(V15, limitsup);
}
BLYNK_WRITE(V12)
{
desiredtemp = param.asFloat();
Blynk.virtualWrite(V22, desiredtemp);
limitinf = (desiredtemp-hysteresis);
Blynk.virtualWrite(V14, limitinf);
delay(20);
limitsup = (desiredtemp+hysteresis);
Blynk.virtualWrite(V15, limitsup);
}
BLYNK_WRITE(V1) // Manual/Auto selection
{
if (param.asInt()==1) {
manual=1;
checklastbuttonpressed ();
mondayfriday=0;
saturdaysunday=0;
Blynk.setProperty (V2,"offLabel", "OFF");
Blynk.setProperty (V2,"offBackColor","#ED9D00") ; //Yellow color
Blynk.virtualWrite(V5, 0);
Blynk.virtualWrite(V7, 0);
} else {
restorelastbuttonpressed ();
manual=0;
Blynk.setProperty (V2,"offLabel", "OFF");
Blynk.setProperty (V2,"offBackColor","#ED9D00") ; //Yellow color
Blynk.virtualWrite(V2, 0);
digitalWrite(TestLED, LOW); // set LED OFF
Blynk.virtualWrite(V21, 0);
}
}
BLYNK_WRITE(V2) // ON-OFF Manual
{
if (param.asInt()==1) { // On/off button
manualpoweron=1;
Blynk.setProperty (V2,"onLabel", "ON");
Blynk.setProperty (V2,"onBackColor","#ED9D00") ; //Yellow color
if (manual==0){ //Automatic mode
checklastbuttonpressed ();
manual=1;
mondayfriday=0;
saturdaysunday=0;
Blynk.virtualWrite(V1, 1);
Blynk.virtualWrite(V5, 0);
Blynk.virtualWrite(V7, 0);
Blynk.virtualWrite(V2, 1); //Turn ON Button Widget
} else { //Manual Mode
mondayfriday=0;
saturdaysunday=0;
Blynk.virtualWrite(V1, 1);
Blynk.virtualWrite(V5, 0);
Blynk.virtualWrite(V7, 0);
Blynk.virtualWrite(V2, 1); //Turn ON Button Widget
}
}else {
manualpoweron=0;
if (manual==0){ //Automatic mode
Blynk.setProperty (V2,"offLabel", "OFF");
Blynk.setProperty (V2,"offBackColor","#ED9D00") ; //Yellow color
checklastbuttonpressed ();
manual=1;
mondayfriday=0;
saturdaysunday=0;
Blynk.virtualWrite(V1, 1);
Blynk.virtualWrite(V5, 0);
Blynk.virtualWrite(V7, 0);
digitalWrite(TestLED, LOW); // set LED OFF
Blynk.virtualWrite(V2, 0); //Turn OFF Button Widget
Blynk.virtualWrite(V21, 0);
} else {
Blynk.setProperty (V2,"offLabel", "OFF");
Blynk.setProperty (V2,"offBackColor","#ED9D00") ; //Yellow color
mondayfriday=0;
saturdaysunday=0;
Blynk.virtualWrite(V1, 1);
Blynk.virtualWrite(V5, 0);
Blynk.virtualWrite(V7, 0);
digitalWrite(TestLED, LOW); // set LED OFF
Blynk.virtualWrite(V2, 0); //Turn OFF Button Widget
Blynk.virtualWrite(V21, 0);
}
}
}
BLYNK_WRITE(V5) // Monday-Friday selected
{
if (param.asInt()==1) {
timer.setTimeout(20, resetManual);
timer.setTimeout(20, checklastbuttonpressed);
mondayfriday=1;
}
else {
mondayfriday=0;
timer.setTimeout(20, resetManual);
}
}
BLYNK_WRITE(V7) // Saturday-Sunday selected
{
if (param.asInt()==1) {
timer.setTimeout(20, resetManual);
timer.setTimeout(20, checklastbuttonpressed);
saturdaysunday=1;
} else {
saturdaysunday=0;
timer.setTimeout(20, resetManual);
}
}
void resetManual()
{
manual=0;
Blynk.virtualWrite(V1, 0); //Turn OFF Manual Mode Widget
Blynk.virtualWrite(V2, 0); //Turn OFF Button Widget Device
digitalWrite(TestLED, LOW); // set LED OFF
Blynk.virtualWrite(V21, 0);
}
void Heartbeat()
{
Blynk.virtualWrite(V18,"\xE2\x97\x89"); //Heartbeat at VPIN 18
timer.setTimeout(2000L,[](){Blynk.virtualWrite(V18,"\xE2\x97\x8E");});
}
void CheckSensorTemp()
{
sensors.requestTemperatures(); //Read sensor temp
float sensortemp = sensors.getTempCByIndex(0);
if(sensortemp >= 0.0) {
warning =0;
stopsystem=0;
Serial.println("Sensor OK. NO Warnings");
Blynk.virtualWrite(V20, "Sensor OK. NO Warnings");
}
if(sensortemp <= 0.0) {
if(warning==0){
Blynk.notify("Sensor failed. First Warning");
Serial.println("Sensor failed. First Warning");
Blynk.virtualWrite(V20, "Sensor failed. First Warning");
}
if(warning==1){
Blynk.notify("Sensor failed. Second Warning");
Serial.println("Sensor failed. Second Warning");
Blynk.virtualWrite(V20, "Sensor failed. Second Warning");
}
if(warning==2){
stopsystem=1;
Blynk.notify("Stopping System");
Serial.println("Stopping System");
Blynk.virtualWrite(V1, 0);
Blynk.virtualWrite(V2, 0);
Blynk.virtualWrite(V5, 0);
Blynk.virtualWrite(V7, 0);
mondayfriday=0;
saturdaysunday=0;
manual=0;
digitalWrite(TestLED, LOW);
Blynk.virtualWrite(V17, "--.--");
Blynk.virtualWrite(V20, "Sensor failed. System stopped");
}
if (warning <= 2) {warning++;}
else warning = 3;// Warning sequence = 3 so system is locked.
}
}
void CheckTemp()
{
sensors.requestTemperatures(); //Read sensor temp
temp = sensors.getTempCByIndex(0);
newtemp = temp+adjustment;
if (warning == 3) {Blynk.virtualWrite(V17, "--:--");}
else {Blynk.virtualWrite(V17, newtemp);}
if((stopsystem==0) && (manual==0) && (newtemp >= limitsup) && (mondayfriday==1) && (mon_fri_relay==1)){
Serial.println("Cooling");
Blynk.virtualWrite(V2, 1);
Blynk.setProperty (V2,"onLabel", "ON > Cooling");
Blynk.setProperty (V2,"onBackColor","#04C0F8") ; //Blue color "#04C0F8"
digitalWrite(TestLED, LOW);
Blynk.virtualWrite(V21, 0);
}
if((stopsystem==0) && (manual==0) && (newtemp <= limitinf) && (mondayfriday==1) && (mon_fri_relay==1)) {
Serial.println("Heating");
Blynk.virtualWrite(V2, 1);
Blynk.setProperty (V2,"onLabel", "ON > Heating");
Blynk.setProperty (V2,"onBackColor","#D3435C") ; //Red color
digitalWrite(TestLED, HIGH);
Blynk.virtualWrite(V21, 1);
}
if((stopsystem==0) && (manual==0) && (newtemp >= limitsup) && (saturdaysunday==1) && (sat_sun_relay==1)){
Serial.println("Cooling");
Blynk.virtualWrite(V2, 1);
Blynk.setProperty (V2,"onLabel", "ON > Cooling");
Blynk.setProperty (V2,"onBackColor","#04C0F8") ; //Blue color "#04C0F8"
digitalWrite(TestLED, LOW);
Blynk.virtualWrite(V21, 0);
}
if((stopsystem==0) && (manual==0) && (newtemp <= limitinf) && (saturdaysunday==1) && (sat_sun_relay==1)) {
Serial.println("Heating");
Blynk.virtualWrite(V2, 1);
Blynk.setProperty (V2,"onLabel", "ON > Heating");
Blynk.setProperty (V2,"onBackColor","#D3435C") ; //Red color
digitalWrite(TestLED, HIGH);
Blynk.virtualWrite(V21, 1);
}
if((stopsystem==0) && (manual==0) && (mon_fri_relay==0) && (mondayfridayactive==1) && (mondayfriday==1)){
Serial.println("Waiting");
Blynk.virtualWrite(V2, 0);
Blynk.setProperty (V2,"offLabel", "OFF > Waiting");
Blynk.setProperty (V2,"offBackColor","#5F7CD8") ; //Dark blue color
digitalWrite(TestLED, LOW);
Blynk.virtualWrite(V21, 0);
}
if((stopsystem==0) && (manual==0) && (sat_sun_relay==0) && (saturdaysundayactive==1) && (saturdaysunday==1)){
Serial.println("Waiting");
Blynk.virtualWrite(V2, 0);
Blynk.setProperty (V2,"offLabel", "OFF > Waiting");
Blynk.setProperty (V2,"offBackColor","#5F7CD8") ; //Dark blue color
digitalWrite(TestLED, LOW);
Blynk.virtualWrite(V21, 0);
}
if((stopsystem==0) && (manual==1) && (manualpoweron==1) && (newtemp <= limitinf)){
Serial.println("Manual Heating");
Blynk.setProperty (V2,"onLabel", "Manual > Heating");
Blynk.setProperty (V2,"onBackColor","#D3435C") ; //Red color
digitalWrite(TestLED, HIGH);
Blynk.virtualWrite(V21, 1);
}
if((stopsystem==0) && (manual==1) && (manualpoweron==1) && (newtemp >= limitsup)){
Serial.println("Manual Cooling");
Blynk.setProperty (V2,"onLabel", "Manual > Cooling");
Blynk.setProperty (V2,"onBackColor","#04C0F8") ; //Blue color "#04C0F8"
digitalWrite(TestLED, LOW);
Blynk.virtualWrite(V21, 0);
}
if ((newtemp <= notification_temperature) && (low_notify==0)){
timer.setTimeout(500L, [](){Blynk.notify("Low temperature at home!!");});
low_notify=1;
}
if ((newtemp > (notification_temperature + 0.25)) && (low_notify==1)){ //adding small hysteresis to avoid multiple messages
low_notify=0;
}
}
BLYNK_WRITE(V19)
{
notification_temperature = param.asFloat();
low_notify=0;
}
void checkBlynk()
{
if (WiFi.status() == WL_CONNECTED)
{
unsigned long startConnecting = millis();
while(!Blynk.connected()){
Blynk.connect();
if(millis() > startConnecting + myServerTimeout){
Serial.print("Unable to connect to server. ");
break;
}
}
}
if (WiFi.status() != 3) {
Serial.print("\tNo WiFi. ");
}
Serial.printf("\tChecking again in %is.\n", blynkInterval /1000);
Serial.println();
}
void sendWifi()
{
wifisignal = map(WiFi.RSSI(), -105, -40, 0, 100);
Blynk.virtualWrite(V3, wifisignal);
}
void clockvalue() // Digital clock display of the time
{
int gmthour = hour();
if (gmthour == 24){
gmthour = 0;
}
String displayhour = String(gmthour, DEC);
int hourdigits = displayhour.length();
if(hourdigits == 1){
displayhour = "0" + displayhour;
}
String displayminute = String(minute(), DEC);
int minutedigits = displayminute.length();
if(minutedigits == 1){
displayminute = "0" + displayminute;
}
displaycurrenttime = displayhour + ":" + displayminute;
Blynk.virtualWrite(V13, displaycurrenttime);
}
BLYNK_WRITE(V9) // Reset
{
if (param.asInt()==1) {
timer.setTimeout(2000, reset_esp);
}
}
void reset_esp()
{
Blynk.virtualWrite(V8, "Rebooting");
delay(3000);
ESP.restart();
delay(5000);
}
void activetoday() // check if schedule should run today
{
if(year() != 1970){
if (mondayfriday==1) {
Blynk.syncVirtual(V4); // sync timeinput widget
}
if (saturdaysunday==1) {
Blynk.syncVirtual(V6); // sync timeinput widget
}
}
}
void checklastbuttonpressed ()
{
if((mondayfriday==1)&&(saturdaysunday==0)){ oldstatus=1; }
if((mondayfriday==0)&&(saturdaysunday==1)){ oldstatus=2; }
if((mondayfriday==1)&&(saturdaysunday==1)){ oldstatus=3; }
if((mondayfriday==0)&&(saturdaysunday==0)){ oldstatus=4; }
}
void restorelastbuttonpressed ()
{
if(oldstatus==1){ mondayfriday=1; saturdaysunday=0; Blynk.virtualWrite(V5, 1); Blynk.virtualWrite(V7, 0); }
if(oldstatus==2){ mondayfriday=0; saturdaysunday=1; Blynk.virtualWrite(V5, 0); Blynk.virtualWrite(V7, 1); }
if(oldstatus==3){ mondayfriday=1; saturdaysunday=1; Blynk.virtualWrite(V5, 1); Blynk.virtualWrite(V7, 1); }
if(oldstatus==4){ mondayfriday=0; saturdaysunday=0; Blynk.virtualWrite(V5, 0); Blynk.virtualWrite(V7, 0); }
}
BLYNK_WRITE(V4)//Monday-Friday
{
if (mondayfriday==1) {
sprintf(Date, "%02d/%02d/%04d", day(), month(), year());
sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());
TimeInputParam t(param);
Serial.print("M-F Checked schedule at: ");
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
Serial.println("Monday-Friday ACTIVE today");
mondayfridayactive=1;
if (t.hasStartTime()) // Process start time
{
Serial.println(String("Start: ") + t.getStartHour() + ":" + t.getStartMinute());
}
if (t.hasStopTime()) // Process stop time
{
Serial.println(String("Stop : ") + t.getStopHour() + ":" + t.getStopMinute());
}
// Display timezone details, for information purposes only
Serial.println(String("Time zone: ") + t.getTZ()); // Timezone is already added to start/stop time
for (int i = 1; i <= 7; i++) { // Process weekdays (1. Mon, 2. Tue, 3. Wed, ...)
if (t.isWeekdaySelected(i)) {
Serial.println(String("Day ") + i + " is selected");
}
}
nowseconds = ((hour() * 3600) + (minute() * 60) + second());
startsecondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
//Serial.println(startsecondswd); // used for debugging
if(nowseconds >= startsecondswd){
Serial.print("Monday-Friday STARTED at");
Serial.println(String(" ") + t.getStartHour() + ":" + t.getStartMinute());
if(nowseconds <= startsecondswd + 90){ // 90s on 60s timer ensures 1 trigger command is sent
mon_fri_relay=1;
// code here to switch the relay ON
}
}
else{
Serial.println("Monday-Friday Device NOT STARTED today");
mondayfridayactive=0;
mon_fri_relay=0;
}
stopsecondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
//Serial.println(stopsecondswd); // used for debugging
if(nowseconds >= stopsecondswd){
mon_fri_relay=0;
Serial.print("Monday-Friday STOPPED at");
Serial.println(String(" ") + t.getStopHour() + ":" + t.getStopMinute());
if(nowseconds <= stopsecondswd + 90){ // 90s on 60s timer ensures 1 trigger command is sent
mon_fri_relay=0;
// code here to switch the relay OFF
}
}
else{
if(nowseconds >= startsecondswd){
mon_fri_relay=1;
Serial.println("Monday-Friday is ON");
}
}
}
else{
Serial.println("Monday-Friday INACTIVE today");
mondayfridayactive=0;
// nothing to do today, check again in 30 SECONDS time
}
Serial.println();
}
}
BLYNK_WRITE(V6) //Saturday-Sunday
{
if (saturdaysunday==1) {
sprintf(Date, "%02d/%02d/%04d", day(), month(), year());
sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());
TimeInputParam t(param);
Serial.print("S-S Checked schedule at: ");
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
Serial.println("Saturday-Sunday ACTIVE today");
if (t.hasStartTime()) // Process start time
{
Serial.println(String("Start: ") + t.getStartHour() + ":" + t.getStartMinute());
}
if (t.hasStopTime()) // Process stop time
{
Serial.println(String("Stop : ") + t.getStopHour() + ":" + t.getStopMinute());
}
// Display timezone details, for information purposes only
Serial.println(String("Time zone: ") + t.getTZ()); // Timezone is already added to start/stop time
for (int i = 1; i <= 7; i++) { // Process weekdays (1. Mon, 2. Tue, 3. Wed, ...)
if (t.isWeekdaySelected(i)) {
Serial.println(String("Day ") + i + " is selected");
}
}
nowseconds = ((hour() * 3600) + (minute() * 60) + second());
startsecondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
if(nowseconds >= startsecondswd){
Serial.print("Saturday-Sunday STARTED at");
Serial.println(String(" ") + t.getStartHour() + ":" + t.getStartMinute());
if(nowseconds <= startsecondswd + 90){ // 90s on 60s timer ensures 1 trigger command is sent
sat_sun_relay=1;
// code here to switch the relay ON
}
}
else{
Serial.println("Saturday-Sunday NOT STARTED today");
sat_sun_relay=0;
}
stopsecondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
//Serial.println(stopsecondswd); // used for debugging
if(nowseconds >= stopsecondswd){
sat_sun_relay=0;
Serial.print("Saturday-Sunday STOPPED at");
Serial.println(String(" ") + t.getStopHour() + ":" + t.getStopMinute());
if(nowseconds <= stopsecondswd + 90){ // 90s on 60s timer ensures 1 trigger command is sent
sat_sun_relay=0;
// code here to switch the relay OFF
}
}
else{
if(nowseconds >= startsecondswd){
sat_sun_relay=1;
Serial.println("Saturday-Sunday is ON");
}
}
}
else{
Serial.println("Saturday-Sunday INACTIVE today");
// nothing to do today
}
Serial.println();
}
}
void loop()
{
if (Blynk.connected()) {
Blynk.run();
}
timer.run();
ArduinoOTA.handle(); // for local OTA updates
}
QR:
That’s all, hope you like it!!
Regards!
Edit:
Small improvement added to amend notification when temperature is low at home.
NEW EDIT: Changing the QR to a new one