 }
 
 void setup() {
+  EEPROM.begin(sizeof(EEpromData));
+  EEPROM.get(0,EEpromData);
   pinMode(PIN_RELAY, OUTPUT);
-  digitalWrite(PIN_RELAY, LOW);
+  //digitalWrite(PIN_RELAY, LOW);
+  if (EEpromData.initialState)
+  {
+    digitalWrite(PIN_RELAY,1);
+  } else {
+    digitalWrite(PIN_RELAY,0);
+    EEpromData.initialState=0;
+  }
 
   // Setup button timers (all in milliseconds / ms)
   // (These are default if not set, but changeable for convenience)

// Milliseconds to wait per cycle for a held command.
const int waitInterval = 100;

// Associate the PIN_BUTTON GPIO with the ClickButton library
ClickButton button1(PIN_BUTTON, LOW, CLICKBTN_PULLUP);

// Register our two HomieNode instances
HomieNode relayNode("relay", "relay");
HomieNode buttonNode("button", "button");

bool RelayHandler(const HomieRange& range, const String& value) {
  /*

  Homie.setLedPin(PIN_LED, HIGH); // Status LED
  // This is a full reset, and will wipe the config
  Homie.setResetTrigger(PIN_BUTTON, LOW, 30000);
  Homie.setSetupFunction(setupHandler);
  Homie.setLoopFunction(loopHandler);
  relayNode.advertise("relayState").settable(RelayHandler);
  relayNode.advertise("relayTimer").settable(relayTimerHandler);
  relayNode.advertise("relayInitMode").settable(relayInitModeHandler);
  watchDogNode.advertise("tick").settable(watchdogTickHandler);
  watchDogNode.advertise("timeOut").settable(watchdogTimeOutHandler);
  keepAliveNode.advertise("tick").settable(keepAliveTickHandler);
  keepAliveNode.advertise("timeOut").settable(keepAliveTimeOutHandler);

  Homie.onEvent(onHomieEvent);
  Homie.setup();
}

