Maximum number of BLYNK_WRITE?

Hey all. I have a fairly extensive project utilizing nodeMCU (ESP8266) modules throughout the house to control my pool, act as a security system, and turn electronics on and off. I have one “master” NodeMCU that interfaces with blynk, and the rest of them use MQTT to publish information to the master and get information from the master.

Last night I made some very slight modifications to my master program adding a few more blynk.virtualwrites and a few BLYNK_WRITE (using the timer widget). After these modifications my master module has been going offline/online randomly and every time I log into the app for the first time I get a “device offline” banner at the top for the first 1-2 seconds.

I rolled it back to the previous code and the problems went away. I am wondering if there’s a maximum number of virtual pins that I have exceeded, or if there is a maximum number of BLYNK_WRITE commands that blynk can handle before dropping.

For the ESP8266, keep the virtualWrites (per 100ms) below 5.

I’d fully recommend upgrading to the ESP32 to overcome this as I have now done on all my more intensive projects.

Another option is to split the timers up so no virtualWrites are conflicting with a span on 1000ms.

I use it on my power monitor project because of how much data there is to send each second. The ESP would simple disconnect.

Here’s the working code:

#include <BlynkSimpleEsp8266.h>
#include <ESP8266WiFi.h>
#include <PubSubClient.h>

#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>



//Blynk Auth
char auth[] = "";
char ssid1[] = "";
char pass[] = "";

//PubSub Stuff
const char* ssid = "";
const char* password = "";
const char* mqtt_server = "m12.cloudmqtt.com";
const int mqtt_port = 16552;
const char *mqtt_user = "";
const char *mqtt_pass = "";
const char *mqtt_client_name = "GarageMCU"; // Client connections cant have the same connection name

WiFiClient espClient;
PubSubClient client(espClient);

//Global Variables
const int openerPin = 13;  //marked as D7 on the board
const int sensorPin = 12; //marked as D6 on the board
String previousTemp = "0";
int oldStatus = 2;
int masterAlarm = 0;
int scarlettAlarm = 0;
int garageAlarm = 0;
int gatesAlarm = 0;
int frontAlarm = 0;
int sliderAlarm = 0;

//Blynk Services
BlynkTimer timer;
WidgetLCD lcd(V0);
WidgetLED frontLED(V35);
WidgetLED sliderLED(V36);
WidgetLED gatesLED(V37);
WidgetLED garageLED(V32);
WidgetLED scarlettLED(V33);
WidgetLED masterLED(V34);
WidgetLED openerLED(V10);

//Functions
void setup_wifi() {

  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
	delay(500);
	Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void reconnect() 
{
  // Loop until we're reconnected
  while (!client.connected()) {
	Serial.print("Attempting MQTT connection...");
	// Attempt to connect
	if (client.connect(mqtt_client_name, mqtt_user, mqtt_pass)) {
	  Serial.println("connected");
	  // Once connected, publish an announcement...
	  client.publish("Device_Status", "GarageMCU Rebooted");
	  // ... and resubscribe
	  client.subscribe("Current_Temperature");
	  client.subscribe("Pool_Mode");
	  client.subscribe("Door_Status");
	  client.subscribe("Device_Status");      
	} else {
	  Serial.print("failed, rc=");
	  Serial.print(client.state());
	  Serial.println(" try again in 5 seconds");
	  // Wait 5 seconds before retrying
	  delay(5000);
	}
  }
}

void callback(char* topic, byte* payload, unsigned int length) 
{
  Serial.print("Message arrived [");
  String newTopic = topic;
  Serial.print(topic);
  Serial.print("] ");
  payload[length] = '\0';
  String newPayload = String((char *)payload);
  Serial.println(newPayload);
  Serial.println();
  if (newTopic == "Current_Temperature") 
  {
	lcd.print(15, 0, "F");
	lcd.print(13, 0, newPayload);
	lcd.print(0,1, "                 ");
	Blynk.virtualWrite(V24, newPayload);
  }
  if (newTopic == "Pool_Mode")
  {
	if (newPayload == "SPA")
	{
	  Blynk.virtualWrite(V22, 1);
	  lcd.print(0, 0, "SPA ");
	}
	if (newPayload == "POOL")
	{
	  Blynk.virtualWrite(V22, 0);
	  lcd.print(0, 0, "POOL");        
	}
  }
  if (newTopic == "Door_Status")
  {
	if(newPayload == "Garage Open")
	{
	  Blynk.virtualWrite(12, "Garage Open");
	  if(garageAlarm == 1)
	  {
		Blynk.notify("The Garage Door Has Opened");
		client.publish("Alarms","Garage Alarm");
	  }
	}
	if(newPayload == "Garage Closed")
	{
	  Blynk.virtualWrite(12, "Garage Closed");
	}
	if(newPayload == "Scarlett Open")
	{
	  Blynk.virtualWrite(13, "Scarlett Door Open");
	  if(scarlettAlarm == 1)
	  {
		Blynk.notify("Scarlett's Door Has Opened!");
		client.publish("Alarms","Scarlett Alarm");
	  }
	}
	if(newPayload == "Scarlett Closed")
	{
	  Blynk.virtualWrite(13, "Scarlett Door Closed");
	  if(scarlettAlarm == 1)
	  {
		Blynk.notify("Scarlett's Door Has Closed!");
	  }
	}
	if(newPayload == "Master Open")
	{
	  Blynk.virtualWrite(14, "Master Door Open");
	  if(masterAlarm == 1)
	  {
		Blynk.notify("Master Door Has Opened!");
		client.publish("Alarms","Master Alarm");      
	  }
	}
	if(newPayload == "Master Closed")
	{
	  Blynk.virtualWrite(14, "Master Door Closed");
	  if(masterAlarm == 1)
	  {
		Blynk.notify("Master Door Has Closed!");    
	  }
	}
	if(newPayload == "Zeier Gate Open")
	{
	  Blynk.virtualWrite(15, "Zeier Gate Open");
	  if(gatesAlarm == 1)
	  {
		Blynk.notify("Zeier Gate Open!"); 
		client.publish("Alarms","Gate Alarm");     
	  }
	}
	if(newPayload == "Zeier Gate Closed")
	{
	  Blynk.virtualWrite(15, "Zeier Gate Closed");
	  if(gatesAlarm == 1)
	  {
		Blynk.notify("Zeier Gate Has Closed!");     
	  }
	}
	if(newPayload == "Equipment Gate Open")
	{
	  Blynk.virtualWrite(15, "Equipment Gate Open");
	  if(gatesAlarm == 1)
	  {
		Blynk.notify("Equipment Gate Open!"); 
		client.publish("Alarms","Gate Alarm");     
	  }
	}
	if(newPayload == "Equipment Gate Closed")
	{
	  Blynk.virtualWrite(15, "Equipment Gate Closed");
	  if(gatesAlarm == 1)
	  {
		Blynk.notify("Equipment Gate Has Closed!");   
	  }
	}     
	if(newPayload == "Front Door Open")
	{
	  Blynk.virtualWrite(16, "Front Door Open");
	  if(frontAlarm == 1)
	  {
		Blynk.notify("Front Door Open!");   
		client.publish("Alarms","Front Door Alarm");   
	  }
	}
	if(newPayload == "Front Door Closed")
	{
	  Blynk.virtualWrite(16, "Front Door Closed");
	  if(frontAlarm == 1)
	  {
		Blynk.notify("Front Door Closed!");     
	  }
	}
	if(newPayload == "Sliding Door Open")
	{
	  Blynk.virtualWrite(17, "Sliding Door Open");
	  if(sliderAlarm == 1)
	  {
		Blynk.notify("Sliding Door Open!");   
		client.publish("Alarms","Slider Alarm");   
	  }
	}
	if(newPayload == "Sliding Door Closed")
	{
	  Blynk.virtualWrite(17, "Sliding Door Closed");
	  if(sliderAlarm == 1)
	  {
		Blynk.notify("Sliding Door Has Closed!");    
	  }
	}  
  }
}

//Timer Functions


void getGarageDoorState()
{
  int newStatus = digitalRead(sensorPin);
  if(newStatus != oldStatus && newStatus == 1)
  {
	client.publish("Door_Status","Garage Open");
	oldStatus = newStatus;
  }
  if(newStatus != oldStatus && newStatus == 0)
  {
	client.publish("Door_Status","Garage Closed");
	oldStatus = newStatus;
  }
}

void checkIn()
{
  client.publish("Device_Status","Garage MCU OK!");
}

void alarmStatus()
{
  if(masterAlarm == 0)
  {
	masterLED.off();
	Blynk.virtualWrite(V4, 0);
  }
  if(masterAlarm == 1)
  {
	masterLED.on();
	Blynk.virtualWrite(V4, 1);
  }
  if(garageAlarm == 0)
  {
	garageLED.off();
	Blynk.virtualWrite(V2, 0);
  }
  if(garageAlarm == 1)
  {
	garageLED.on();
	Blynk.virtualWrite(V2, 1);
  }
  if(gatesAlarm == 0)
  {
	gatesLED.off();
	Blynk.virtualWrite(V9, 0);
  }
  if(gatesAlarm == 1)
  {
	gatesLED.on();
	Blynk.virtualWrite(V9, 1);
  }
  if(frontAlarm == 0)
  {
	frontLED.off();
	Blynk.virtualWrite(V8, 0);
  }
  if(frontAlarm == 1)
  {
	frontLED.on();
	Blynk.virtualWrite(V8, 1);
  }
  if(sliderAlarm == 0)
  {
	sliderLED.off();
	Blynk.virtualWrite(V10, 0);
  }
  if(sliderAlarm == 1)
  {
	sliderLED.on();
	Blynk.virtualWrite(V10, 1);
  }
  if(scarlettAlarm == 0)
  {
	scarlettLED.off();
	Blynk.virtualWrite(V3, 0);
  }
  if(scarlettAlarm == 1)
  {
	scarlettLED.on();
	Blynk.virtualWrite(V3, 1);
  }
}


//Blynk Writes
BLYNK_WRITE(V20)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1)
  {
	if (! client.publish("Commands","Pool_Light")) 
	{
	lcd.print(0,1, "Command Failed ");
	}
	else 
	{
	lcd.print(0,1, "Pool Light Sent");
	}
  }
}

BLYNK_WRITE(V21)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1)
  {
	if (! client.publish("Commands","Spa_Light")) 
	{
	lcd.print(0,1, "Command Failed ");
	}
	else 
	{
	lcd.print(0,1, "Spa Light Sent ");
	}
  }
}

BLYNK_WRITE(V22)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1)
  {
	if (! client.publish("Commands","SPA")) 
	{
	lcd.print(0,1, "Command Failed ");
	}
	else 
	{
	lcd.print(0,1, "Mode: SPA Sent ");
	}
  }
  if (pinValue == 0)
  {
	if (! client.publish("Commands","POOL")) 
	{
	lcd.print(0,1, "Command Failed ");
	}
	else 
	{
	lcd.print(0,1, "Mode: POOL Sent");
	}
  }
}

BLYNK_WRITE(V2)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1 && garageAlarm == 0)
  {
	garageAlarm = 1;
	garageLED.on();
  }
  if (pinValue == 0 && garageAlarm == 1)
  {
	garageAlarm = 0;
	garageLED.off();
  }
}

BLYNK_WRITE(V8)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1 && frontAlarm == 0)
  {
	frontAlarm = 1;
	frontLED.on();
  }
  if (pinValue == 0 && frontAlarm == 1)
  {
	frontAlarm = 0;
	frontLED.off();
  }
}

BLYNK_WRITE(V9)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1 && gatesAlarm == 0)
  {
	gatesAlarm = 1;
	gatesLED.on();
  }
  if (pinValue == 0 && gatesAlarm == 1)
  {
	gatesAlarm = 0;
	gatesLED.off();
  }
}

BLYNK_WRITE(V3)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1 && scarlettAlarm == 0)
  {
	scarlettAlarm = 1;
	scarlettLED.on();
  }
  if (pinValue == 0 && scarlettAlarm == 1)
  {
	scarlettAlarm = 0;
	scarlettLED.off();
  }
}

BLYNK_WRITE(V10)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1 && sliderAlarm == 0)
  {
	sliderAlarm = 1;
	sliderLED.on();
  }
  if (pinValue == 0 && sliderAlarm == 1)
  {
	sliderAlarm = 0;
	sliderLED.off();
  }
}

BLYNK_WRITE(V4)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1 && masterAlarm == 0)
  {
	masterAlarm = 1;
	masterLED.on();
  }
  if (pinValue == 0 && masterAlarm == 1)
  {
	masterAlarm = 0;
	masterLED.off();
  }
}

BLYNK_WRITE(V7)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1)
  {
	digitalWrite(openerPin, HIGH);
	openerLED.on();
	delay(800);
	digitalWrite(openerPin, LOW);
	openerLED.off();
  }
}


BLYNK_WRITE(V5)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1)
  {
	client.publish("Commands","Patio Light On");
  }
  if (pinValue == 0)
  {
	client.publish("Commands","Patio Light Off");
  }
}

BLYNK_WRITE(V6)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1)
  {
	client.publish("Commands","Patio Fan On");
  }
  if (pinValue == 0)
  {
	client.publish("Commands","Patio Fan Off");
  }
}

BLYNK_WRITE(V1)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1)
  {
	client.publish("Alarms","Clear Alarms");
  }
}

BLYNK_WRITE(V11)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1)
  {
	garageAlarm = 1;
	gatesAlarm = 1;
	frontAlarm = 1;
	sliderAlarm = 1;    
  }
}

BLYNK_WRITE(V18)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1)
  {
	masterAlarm = 0;
	scarlettAlarm = 0;
	garageAlarm = 0;
	gatesAlarm = 0;
	frontAlarm = 0;
	sliderAlarm = 0;
  }
}

void setup() 
{
  Serial.begin(115200);
  setup_wifi();
  client.setServer(mqtt_server, 16552);
  client.setCallback(callback);
  ArduinoOTA.setHostname("garageMCU");
  ArduinoOTA.begin(); 

  Blynk.config(auth);
  
  pinMode(sensorPin, INPUT);
  pinMode(openerPin, OUTPUT);

  
  // timer setup in millis
  timer.setInterval(1000, getGarageDoorState);
  timer.setInterval(1000, alarmStatus);
  timer.setInterval(60000, checkIn);
  lcd.clear();


//  Blynk.virtualWrite(V2, 0);
//  Blynk.virtualWrite(V3, 0);
//  Blynk.virtualWrite(V4, 0);
//  Blynk.virtualWrite(V8, 0);
//  Blynk.virtualWrite(V9, 0);
//  Blynk.virtualWrite(V10, 0);
//  
//  frontLED.off();
//  sliderLED.off();
//  gatesLED.off();
//  garageLED.off();
//  scarlettLED.off();
//  masterLED.off();
//  openerLED.off();

  Blynk.notify("Device Reboot, All Alarms Off!"); 
  

}

void loop() 
{
  if (!client.connected()) 
  {
	reconnect();
  }
  client.loop();
  ArduinoOTA.handle();
  Blynk.run();
  timer.run(); 
  ArduinoOTA.handle();
  
}

And the busted code:

#include <BlynkSimpleEsp8266.h>
#include <ESP8266WiFi.h>
#include <PubSubClient.h>

#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>



//Blynk Auth
char auth[] = "";
char ssid1[] = "";
char pass[] = "";

//PubSub Stuff
const char* ssid = "";
const char* password = "";
const char* mqtt_server = "m12.cloudmqtt.com";
const int mqtt_port = 16552;
const char *mqtt_user = "";
const char *mqtt_pass = "";
const char *mqtt_client_name = "GarageMCU"; // Client connections cant have the same connection name

WiFiClient espClient;
PubSubClient client(espClient);

//Global Variables
const int openerPin = 13;  //marked as D7 on the board
const int sensorPin = 12; //marked as D6 on the board
String previousTemp = "0";
int oldStatus = 2;
int masterAlarm = 0;
int scarlettAlarm = 0;
int garageAlarm = 0;
int gatesAlarm = 0;
int frontAlarm = 0;
int sliderAlarm = 0;

//Blynk Services
BlynkTimer timer;
WidgetLED frontLED(V35);
WidgetLED sliderLED(V36);
WidgetLED gatesLED(V37);
WidgetLED gateLED(V29);
WidgetLED garageLED(V32);
WidgetLED scarlettLED(V33);
WidgetLED masterLED(V34);
WidgetLED openerLED(V10);
WidgetLED timerLED(V38);
WidgetLED bedtimeLED(V30);

//Functions
void setup_wifi() {

  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
	delay(500);
	Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void reconnect() 
{
  // Loop until we're reconnected
  while (!client.connected()) {
	Serial.print("Attempting MQTT connection...");
	// Attempt to connect
	if (client.connect(mqtt_client_name, mqtt_user, mqtt_pass)) {
	  Serial.println("connected");
	  // Once connected, publish an announcement...
	  client.publish("Device_Status", "GarageMCU Rebooted");
	  // ... and resubscribe
	  client.subscribe("Current_Temperature");
	  client.subscribe("Pool_Mode");
	  client.subscribe("Door_Status");
	  client.subscribe("Device_Status");      
	} else {
	  Serial.print("failed, rc=");
	  Serial.print(client.state());
	  Serial.println(" try again in 5 seconds");
	  // Wait 5 seconds before retrying
	  delay(5000);
	}
  }
}

void callback(char* topic, byte* payload, unsigned int length) 
{
  Serial.print("Message arrived [");
  String newTopic = topic;
  Serial.print(topic);
  Serial.print("] ");
  payload[length] = '\0';
  String newPayload = String((char *)payload);
  Serial.println(newPayload);
  Serial.println();
  if (newTopic == "Current_Temperature") 
  {
	Blynk.virtualWrite(V24, newPayload);
  }
  if (newTopic == "Pool_Mode")
  {
	if (newPayload == "SPA")
	{
	  Blynk.virtualWrite(V22, 1);
	  Blynk.setProperty(V24, "label", "Current Mode: SPA");
	}
	if (newPayload == "POOL")
	{
	  Blynk.virtualWrite(V22, 0);
	  Blynk.setProperty(V24, "label", "Current Mode: POOL");      
	}
  }
  if (newTopic == "Door_Status")
  {
	if(newPayload == "Garage Open")
	{
	  Blynk.virtualWrite(12, "Garage Open");
	  if(garageAlarm == 1)
	  {
		Blynk.notify("The Garage Door Has Opened");
		client.publish("Alarms","Garage Alarm");
	  }
	}
	if(newPayload == "Garage Closed")
	{
	  Blynk.virtualWrite(12, "Garage Closed");
	}
	if(newPayload == "Scarlett Open")
	{
	  Blynk.virtualWrite(13, "Scarlett Door Open");
	  if(scarlettAlarm == 1)
	  {
		Blynk.notify("Scarlett's Door Has Opened!");
		client.publish("Alarms","Scarlett Alarm");
	  }
	}
	if(newPayload == "Scarlett Closed")
	{
	  Blynk.virtualWrite(13, "Scarlett Door Closed");
	  if(scarlettAlarm == 1)
	  {
		Blynk.notify("Scarlett's Door Has Closed!");
	  }
	}
	if(newPayload == "Master Open")
	{
	  Blynk.virtualWrite(14, "Master Door Open");
	  if(masterAlarm == 1)
	  {
		Blynk.notify("Master Door Has Opened!");
		client.publish("Alarms","Master Alarm");      
	  }
	}
	if(newPayload == "Master Closed")
	{
	  Blynk.virtualWrite(14, "Master Door Closed");
	  if(masterAlarm == 1)
	  {
		Blynk.notify("Master Door Has Closed!");    
	  }
	}
	if(newPayload == "Exercise Open")
	{
	  Blynk.virtualWrite(26, "Exercise Door Open");
	}
	if(newPayload == "Exercise Closed")
	{
	  Blynk.virtualWrite(26, "Exercise Door Closed");
	}
	if(newPayload == "Zeier Gate Open")
	{
	  Blynk.virtualWrite(15, "Zeier Gate Open");
	  if(gatesAlarm == 1)
	  {
		Blynk.notify("Zeier Gate Open!"); 
		client.publish("Alarms","Gate Alarm");     
	  }
	}
	if(newPayload == "Zeier Gate Closed")
	{
	  Blynk.virtualWrite(15, "Zeier Gate Closed");
	  if(gatesAlarm == 1)
	  {
		Blynk.notify("Zeier Gate Has Closed!");     
	  }
	}
	if(newPayload == "Equipment Gate Open")
	{
	  Blynk.virtualWrite(23, "Equipment Gate Open");
	  if(gatesAlarm == 1)
	  {
		Blynk.notify("Equipment Gate Open!"); 
		client.publish("Alarms","Gate Alarm");     
	  }
	}
	if(newPayload == "Equipment Gate Closed")
	{
	  Blynk.virtualWrite(23, "Equipment Gate Closed");
	  if(gatesAlarm == 1)
	  {
		Blynk.notify("Equipment Gate Has Closed!");   
	  }
	}     
	if(newPayload == "Front Door Open")
	{
	  Blynk.virtualWrite(16, "Front Door Open");
	  if(frontAlarm == 1)
	  {
		Blynk.notify("Front Door Open!");   
		client.publish("Alarms","Front Door Alarm");   
	  }
	}
	if(newPayload == "Front Door Closed")
	{
	  Blynk.virtualWrite(16, "Front Door Closed");
	  if(frontAlarm == 1)
	  {
		Blynk.notify("Front Door Closed!");     
	  }
	}
	if(newPayload == "Sliding Door Open")
	{
	  Blynk.virtualWrite(17, "Sliding Door Open");
	  if(sliderAlarm == 1)
	  {
		Blynk.notify("Sliding Door Open!");   
		client.publish("Alarms","Slider Alarm");   
	  }
	}
	if(newPayload == "Sliding Door Closed")
	{
	  Blynk.virtualWrite(17, "Sliding Door Closed");
	  if(sliderAlarm == 1)
	  {
		Blynk.notify("Sliding Door Has Closed!");    
	  }
	}  
  }
}

//Timer Functions


void getGarageDoorState()
{
  int newStatus = digitalRead(sensorPin);
  if(newStatus != oldStatus && newStatus == 1)
  {
	client.publish("Door_Status","Garage Door Open");
	oldStatus = newStatus;
  }
  if(newStatus != oldStatus && newStatus == 0)
  {
	client.publish("Door_Status","Garage Door Closed");
	oldStatus = newStatus;
  }
}

void checkIn()
{
  client.publish("Device_Status","Garage MCU OK!");
}

void alarmStatus()
{
  if(masterAlarm == 0)
  {
	masterLED.off();
	Blynk.virtualWrite(V4, 0);
  }
  if(masterAlarm == 1)
  {
	masterLED.on();
	Blynk.virtualWrite(V4, 1);
  }
  if(garageAlarm == 0)
  {
	garageLED.off();
	Blynk.virtualWrite(V2, 0);
  }
  if(garageAlarm == 1)
  {
	garageLED.on();
	Blynk.virtualWrite(V2, 1);
  }
  if(gatesAlarm == 0)
  {
	gateLED.off();
	gatesLED.off();
	Blynk.virtualWrite(V9, 0);
  }
  if(gatesAlarm == 1)
  {
	gateLED.on();
	gatesLED.on();
	Blynk.virtualWrite(V9, 1);
  }
  if(frontAlarm == 0)
  {
	frontLED.off();
	Blynk.virtualWrite(V8, 0);
  }
  if(frontAlarm == 1)
  {
	frontLED.on();
	Blynk.virtualWrite(V8, 1);
  }
  if(sliderAlarm == 0)
  {
	sliderLED.off();
	Blynk.virtualWrite(V10, 0);
  }
  if(sliderAlarm == 1)
  {
	sliderLED.on();
	Blynk.virtualWrite(V10, 1);
  }
  if(scarlettAlarm == 0)
  {
	scarlettLED.off();
	Blynk.virtualWrite(V3, 0);
  }
  if(scarlettAlarm == 1)
  {
	scarlettLED.on();
	Blynk.virtualWrite(V3, 1);
  }
}


//Blynk Writes
BLYNK_WRITE(V20)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1)
  {
	if (! client.publish("Commands","Pool_Light")) 
	{
	Blynk.virtualWrite(V25, "Command Failed");
	delay(1000);
	Blynk.virtualWrite(V25, " ");
	}
	else 
	{
	Blynk.virtualWrite(V25, "Pool Light Sent");
	delay(1000);
	Blynk.virtualWrite(V25, " ");
	}
  }
}

BLYNK_WRITE(V21)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1)
  {
	if (! client.publish("Commands","Spa_Light")) 
	{
	Blynk.virtualWrite(V25, "Command Failed");
	delay(1000);
	Blynk.virtualWrite(V25, " ");
	}
	else 
	{
	Blynk.virtualWrite(V25, "Spa Light Sent");
	delay(1000);
	Blynk.virtualWrite(V25, " ");
	}
  }
}

BLYNK_WRITE(V22)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1)
  {
	if (! client.publish("Commands","SPA")) 
	{
	Blynk.virtualWrite(V25, "Command Failed");
	delay(1000);
	Blynk.virtualWrite(V25, " ");
	}
	else 
	{
	Blynk.virtualWrite(V25, "Mode: SPA Sent");
	delay(1000);
	Blynk.virtualWrite(V25, " ");
	}
  }
  if (pinValue == 0)
  {
	if (! client.publish("Commands","POOL")) 
	{
	Blynk.virtualWrite(V25, "Command Failed");
	delay(1000);
	Blynk.virtualWrite(V25, " ");
	}
	else 
	{
	Blynk.virtualWrite(V25, "Mode: POOL Sent");
	delay(1000);
	Blynk.virtualWrite(V25, " ");
	}
  }
}

BLYNK_WRITE(V2)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1 && garageAlarm == 0)
  {
	garageAlarm = 1;
	garageLED.on();
  }
  if (pinValue == 0 && garageAlarm == 1)
  {
	garageAlarm = 0;
	garageLED.off();
  }
}

BLYNK_WRITE(V8)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1 && frontAlarm == 0)
  {
	frontAlarm = 1;
	frontLED.on();
  }
  if (pinValue == 0 && frontAlarm == 1)
  {
	frontAlarm = 0;
	frontLED.off();
  }
}

BLYNK_WRITE(V9)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1 && gatesAlarm == 0)
  {
	gatesAlarm = 1;
	gatesLED.on();
	gateLED.on();
  }
  if (pinValue == 0 && gatesAlarm == 1)
  {
	gatesAlarm = 0;
	gatesLED.off();
	gateLED.on();
  }
}

BLYNK_WRITE(V3)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1 && scarlettAlarm == 0)
  {
	scarlettAlarm = 1;
	scarlettLED.on();
  }
  if (pinValue == 0 && scarlettAlarm == 1)
  {
	scarlettAlarm = 0;
	scarlettLED.off();
  }
}

BLYNK_WRITE(V10)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1 && sliderAlarm == 0)
  {
	sliderAlarm = 1;
	sliderLED.on();
  }
  if (pinValue == 0 && sliderAlarm == 1)
  {
	sliderAlarm = 0;
	sliderLED.off();
  }
}

BLYNK_WRITE(V4)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1 && masterAlarm == 0)
  {
	masterAlarm = 1;
	masterLED.on();
  }
  if (pinValue == 0 && masterAlarm == 1)
  {
	masterAlarm = 0;
	masterLED.off();
  }
}

BLYNK_WRITE(V7)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1)
  {
	digitalWrite(openerPin, HIGH);
	openerLED.on();
	delay(800);
	digitalWrite(openerPin, LOW);
	openerLED.off();
  }
}


BLYNK_WRITE(V5)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1)
  {
	client.publish("Commands","Patio Light On");
  }
  if (pinValue == 0)
  {
	client.publish("Commands","Patio Light Off");
  }
}

BLYNK_WRITE(V6)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1)
  {
	client.publish("Commands","Patio Fan On");
  }
  if (pinValue == 0)
  {
	client.publish("Commands","Patio Fan Off");
  }
}

BLYNK_WRITE(V1)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1)
  {
	client.publish("Alarms","Clear Alarms");
  }
}

BLYNK_WRITE(V11)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1)
  {
	garageAlarm = 1;
	gatesAlarm = 1;
	frontAlarm = 1;
	sliderAlarm = 1;    
  }
}

BLYNK_WRITE(V18)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1)
  {
	masterAlarm = 0;
	scarlettAlarm = 0;
	garageAlarm = 0;
	gatesAlarm = 0;
	frontAlarm = 0;
	sliderAlarm = 0;
  }
}

BLYNK_WRITE(V28)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1)
  {
	gatesAlarm = 1;
	frontAlarm = 1;
	sliderAlarm = 1;
	timerLED.on();
  }
  if (pinValue == 0)
  {
	gatesAlarm = 0;
	frontAlarm = 0;
	sliderAlarm = 0;
	timerLED.off();
  }
}

BLYNK_WRITE(V19)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1)
  {
	scarlettAlarm = 1;
	bedtimeLED.on();
  }
  if (pinValue == 0)
  {
	scarlettAlarm = 0;
	bedtimeLED.off();
  }
}

void setup() 
{
  Serial.begin(115200);
  setup_wifi();
  client.setServer(mqtt_server, 16552);
  client.setCallback(callback);
  ArduinoOTA.setHostname("garageMCU");
  ArduinoOTA.begin(); 

  Blynk.config(auth);
  
  pinMode(sensorPin, INPUT);
  pinMode(openerPin, OUTPUT);

  
  // timer setup in millis
  timer.setInterval(1000, getGarageDoorState);
  timer.setInterval(1000, alarmStatus);
  timer.setInterval(60000, checkIn);



//  Blynk.virtualWrite(V2, 0);
//  Blynk.virtualWrite(V3, 0);
//  Blynk.virtualWrite(V4, 0);
//  Blynk.virtualWrite(V8, 0);
//  Blynk.virtualWrite(V9, 0);
//  Blynk.virtualWrite(V10, 0);
//  
//  frontLED.off();
//  sliderLED.off();
//  gatesLED.off();
//  garageLED.off();
//  scarlettLED.off();
//  masterLED.off();
//  openerLED.off();

  Blynk.notify("Device Reboot, All Alarms Off!"); 
  

}

void loop() 
{
  if (!client.connected()) 
  {
	reconnect();
  }
  client.loop();
  ArduinoOTA.handle();
  Blynk.run();
  timer.run(); 
  ArduinoOTA.handle();
  
}

I don’t think I have many instances of blynk.virtualwrites overlapping. They are usually in response to triggers from the MQTT, and that doesn’t happen super often.