"SONOFF Clone" - Mini-ESP8266 Power AC Relay Controller

@Jamin

HI
here is part of my sketch for a (+ve) activated Relay

/******************************************************************************
 *
 *                             switch.h
 *
 *****************************************************************************/

  BlynkTimer timer;

  int SwitchState, timer1, SwitchDelay;

  WidgetBridge gate(vPIN_BRIDGE_GATE);

  BLYNK_CONNECTED() {
gate.setAuthToken("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
  }

  void Switch_OFF() {
digitalWrite(RELAY_PIN, 0);
Blynk.virtualWrite(vPIN_BUTTON_MANUAL, 0);
Blynk.virtualWrite(vPIN_LED, 0);
  }

  void Switch_ON() {
digitalWrite(RELAY_PIN, 1);
Blynk.virtualWrite(vPIN_BUTTON_MANUAL, 1);
Blynk.virtualWrite(vPIN_LED, 255);
  }

  void Switch_Toggle(bool state) {
digitalWrite(RELAY_PIN, state);
SwitchState = digitalRead(RELAY_PIN);
if (SwitchState) { SwitchState = 255;
Blynk.virtualWrite(vPIN_LED, SwitchState);
  }else{  SwitchState = 0; 
Blynk.virtualWrite(vPIN_LED, SwitchState);
  }
  }

  BLYNK_WRITE(vPIN_BUTTON_TIMEOUT) { // remote delay Switch
if ((digitalRead(RELAY_PIN))== 0)  
  Switch_ON();
  timer.setTimeout(SwitchDelay, Switch_OFF);
}

  BLYNK_WRITE(vPIN_BUTTON_MANUAL) { // manual button
Switch_Toggle(param.asInt());
  }

  BLYNK_WRITE(vPIN_TIMER) { // timer Switch
if (param.asInt()) {
  Switch_ON();
  gate.virtualWrite(vPIN_BRIDGE_GATE, param.asInt());
} else {
  Switch_OFF();
}
  }

  BLYNK_WRITE(vPIN_SLIDER_TIMEOUT) {
SwitchDelay = param[0].asInt() * 60000;
Blynk.syncVirtual(vPIN_BUTTON_TIMEOUT);
  }
/*---------------------------------------------------------------------------*/

My Smart Plug
Thanks to Jamin

3 Likes