         relayNode.setProperty("relayState").send("ON");
         buttonNode.setProperty("event").setRetained(false).send("SINGLE");
       }
+      // Read the new state, and use it to set the initial startup state
+      String PIN_STATE = String(digitalRead(PIN_RELAY));
+      relayNode.setProperty("relayInitMode").send(PIN_STATE);
       Serial.println("SINGLE click");
     }
 

#include <EEPROM.h>

#define FW_NAME "homie-sonoff-touch"
#define FW_VERSION "2.0.7"

// Disable this if you don't want the relay to turn on with any single tap event


  //digitalWrite(PIN_RELAY, LOW);
  if (EEpromData.initialState)
  {
    Serial.println("Startup: Relay On");
    digitalWrite(PIN_RELAY,HIGH);
  } else {
    Serial.println("Startup: Relay Off");
    digitalWrite(PIN_RELAY,LOW);
    EEpromData.initialState=0;
  }

