I am using the output of the comparator at this pin to get logic to control my cct
here is the brief code
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>
//#include <EasyBlynk8266.h>
#include <ESP8266WiFi.h>
#include <WidgetRTC.h>
#include <TimeLib.h>
#include <SPI.h>
//#include "ZMPT101B.h"
//ZMPT101B voltageSensor(A0);
BlynkTimer timer;
WidgetRTC rtc;
const int swPin = 3; //Rx as GPIO
const int wapPin = 1; //Tx as GPIO
const int slPin = 2;
const int genPin = 0;
byte swState = HIGH;
byte slState = HIGH;
int i;
int autom;
int blynkslond;
int blynksloffd;
unsigned long previousmillis = 0;
void clockDisplay();
char ssid[] = "Meeaaaaow";
char pass[] = "Messey007";
char auth[] = "xxx";
void setup()
{Serial.begin(9600);
pinMode(swPin, OUTPUT);
pinMode(slPin, OUTPUT);
// pinMode(wapPin, FUNCTION_3);
// pinMode(swPin, FUNCTION_3);
// pinMode(wapPin,INPUT);
// pinMode(genPin,INPUT);
pinMode(wapPin,INPUT_PULLUP);
pinMode(genPin,INPUT_PULLUP);
digitalWrite(swPin, HIGH);
digitalWrite(slPin, HIGH);
//digitalWrite(genPin, HIGH);
Blynk.begin(auth, ssid, pass, IPAddress(192,168,0,101), 8080);
// Serial.println("Calibrating... Ensure that no current flows through the sensor at this moment");
// delay(100);
// voltageSensor.calibrate();
// currentSensor.calibrate();
// Serial.println("Done!");
//
setSyncInterval(10 * 60); // Sync interval in seconds (10 minutes)
timer.setInterval(1000L, clockDisplay);
} // Display digital clock every 10 seconds
void loop()
{Blynk.run();
timer.run();}
BLYNK_CONNECTED()
{rtc.begin();
Blynk.syncVirtual(V6); // Switch Pin
Blynk.syncVirtual(V7); // Self Pin
Blynk.syncVirtual(V10);}
BLYNK_WRITE(V6)
{int sw = param.asInt();
if (autom == 0)
{if (sw == 0)
{digitalWrite(swPin, LOW);
if (digitalRead(swPin) == LOW)
{Blynk.virtualWrite(V2, 0);}}
else
{digitalWrite(swPin, HIGH);
if (digitalRead(swPin) == HIGH)
{Blynk.virtualWrite(V2, 255);}}}}
BLYNK_WRITE(V7)
{int sl = param.asInt();
if (autom == 0)
{if (sl == 0)
{digitalWrite(slPin, LOW);
if (digitalRead(slPin) == LOW)
{Blynk.virtualWrite(V3, 0);}}
else
{digitalWrite(slPin, HIGH);
if (digitalRead(slPin) == HIGH)
{Blynk.virtualWrite(V3, 255);}}}}
BLYNK_WRITE(V8)
{blynkslond = param.asInt();} // Blynk self on duration
BLYNK_WRITE(V9)
{blynksloffd = param.asInt();} // Blynk self off duration
BLYNK_WRITE(V10)
{autom = param.asInt();}
void clockDisplay()
{String currentTime = String(hour()) + ":" + minute() + ":" + second();
String currentDate = String(day()) + " " + month() + " " + year();
Serial.print("Current time: ");
Serial.print(currentTime);
Serial.print(" ");
Serial.print(currentDate);
Serial.println();
Blynk.virtualWrite(V0, currentTime);
Blynk.virtualWrite(V1, currentDate);
/*unsigned long currentmillis = millis();
unsigned long onduration = blynkon*1023UL;
unsigned long offduration = blynkoff*1023UL;
if (autom == 0)
{if (testled == HIGH)
{if (currentmillis - previousmillis >= onduration)
{Blynk.virtualWrite(V6, 255);
testled = LOW;
previousmillis = currentmillis;}}
else if (testled == LOW)
{if (currentmillis - previousmillis >= offduration)
{Blynk.virtualWrite(V6, 0);
testled = HIGH;
previousmillis = currentmillis;}}}*/
if (autom == 1)
{if (digitalRead(wapPin) == LOW && digitalRead(genPin) == HIGH)
{digitalWrite(swPin, HIGH); // Switch off
if (digitalRead(swPin) == HIGH)
{Blynk.virtualWrite(V2, 0);} // Switch light off
digitalWrite(slPin, HIGH); // Self off
if (digitalRead(slPin) == HIGH)
{Blynk.virtualWrite(V3, 0);} // Self light off
if (digitalRead(wapPin) == HIGH)
{Blynk.virtualWrite(V4, 255);} // Wapda light on
time_t stoppedat = now();
Blynk.virtualWrite(V14, stoppedat);}
else if (digitalRead(wapPin) == HIGH && digitalRead(genPin) == HIGH)
{if (digitalRead(wapPin) == LOW)
{Blynk.virtualWrite(V4, 0); // Wapda light off
Blynk.notify("Alert! Wapda is down");}
digitalWrite(swPin, LOW); // Switch on
if (digitalRead(swPin) == LOW)
{Blynk.virtualWrite(V2, 255);} // Switch light on
delay(500);
for (i=0; i<=2; i++)
{digitalWrite(slPin, LOW); // Self on
if (digitalRead(slPin) == LOW)
{Blynk.virtualWrite(V3, 255);} // Self light on
delay(500);
digitalWrite(slPin, HIGH); // Self off
if (digitalRead(slPin) == HIGH)
{Blynk.virtualWrite(V3, 0);} // Self light off
delay(500);}}
else if (digitalRead(wapPin) == HIGH && digitalRead(genPin) == LOW)
{if (digitalRead(genPin) == HIGH)
{Blynk.virtualWrite(V5, 255); // Generator light on
Blynk.notify("Genertor is running");}
digitalWrite(swPin, LOW); // Switch on
if (digitalRead(swPin) == LOW)
{Blynk.virtualWrite(V3, 255);} // Switch light on
digitalWrite(slPin, HIGH); // Self off
if (digitalRead(slPin) == HIGH)
{Blynk.virtualWrite(V3, 0);} // Self light off
// string startedat;
// breakTime(tin, startedat);
time_t startedat = now();
Blynk.virtualWrite(V13, startedat);}
else if (digitalRead(wapPin) == LOW && digitalRead(genPin) == LOW)
{if (digitalRead(wapPin) == HIGH)
{Blynk.virtualWrite(V4, 255); // Wapda light on
Blynk.notify("Wapda is Up");}
delay(2000);
digitalWrite(swPin, HIGH); // Switch off
if (digitalRead(swPin) == HIGH)
{Blynk.virtualWrite(V3, 0);} // Switch light off
digitalWrite(slPin, HIGH); // Self off
if (digitalRead(slPin) == HIGH)
{Blynk.virtualWrite(V3, 0);} // Self light off
// string startedat;
// breakTime(tin, startedat);
time_t startedat = now();
Blynk.virtualWrite(V13, startedat);}}
}
// if (digitalRead(wapPin) == LOW || digitalRead(genPin) == LOW) {i = 0;}}*/
/*// if (ana)
// float U = voltageSensor.getVoltageAC();
// float I = currentSensor.getCurrentAC();
// float P = U;
// Serial.println(String("U = ") + U + " V");}
// Serial.println(String("I = ") + I + " A");
// Serial.println(String("P = ") + P + " Watts");*/