   // state on the relayState topic.
   if (value == "ON") {
     digitalWrite(PIN_RELAY, HIGH);
-    relayNode.setProperty("relayState").send("ON");
+    if ( Homie.isConnected() ) { relayNode.setProperty("relayState").send("ON"); }
     Serial.println("Relay is on");
   } else if (value == "OFF") {
     digitalWrite(PIN_RELAY, LOW);
-    relayNode.setProperty("relayState").send("OFF");
+    if ( Homie.isConnected() ) { relayNode.setProperty("relayState").send("OFF"); }
     Serial.println("Relay is off");
   } else {
     Serial.print("Unknown value: ");

    };
  }

  Homie.loop();
}

  // 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);
