Virtual Pin Initialization on ESP8266 12E

My issue is from when my ESP8266 first starts up or loses power and re-initializes. I am using the Arduino IDE to write the software for the ESP8266. I am using virtual pin V1 on the button in the app. My GPIO pin #16 needs to be low until triggered by the blynk app but for some reason Blynk sets it high at the beginning. This is bad because it will be hooked to my garage door which means it will open the door if I lose power and it’s restored while I’m away. The code I have works fine once I’ve pushed the button on the app. It’s just the beginning that’s getting me! Any help would be awesome!. See my code below:

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "#######";
const int relayPin = 16;
int state = LOW;

void setup()
  pinMode(relayPin, OUTPUT);
  Blynk.begin(auth, "ssid", "password");
  Blynk.virtualWrite(V1, LOW);
  digitalWrite(relayPin, state);

  BLYNK_LOG("Got a value: %s", param.asStr());
  // You can also use:
  // int i = param.asInt() or
  // double d = param.asDouble()
  int i = param.asInt();
  if(i == 0){
    state = HIGH;
  }else if(i == 1){
    state = LOW; 
  digitalWrite(relayPin, state);

void loop()

@fm3391 Try setting the initial state to HIGH. Someone (or Google) else might be able to clarify better, but a lot of times (perhaps always?), the ESP modules use HIGH/LOW in the complete opposite way of an Arduino microcontroller.

Blynk.virtualWrite(V1, LOW) in setup will have no effect (it needs to be done in BLYNK_CONNECTED).
Alternatively, you could look into Sync API (syncAll, syncVirtual) but, be careful with projects related to security!

Got it! Thanks zeeko! Don’t know why I didn’t think about that especially since I was doing that in my BLYNK_WRITE method. I agree zhymanskyy, security is a priority which is why I am trying to test as much as possible with as many test scenarios as I can think of!