   // Save click codes in function, as click codes are reset at next Update()
   if(button1.clicks != 0) function = button1.clicks;
 
+  // These are single event button presses.
+  // Handle them and reset function back to 0
   if ( function > 0 ) {
     Serial.println("One-shot");
     if ( function == 1 ) {

    function = 0;
  }

  if ( function < 0 ) {
    if ( function == -1 ) {
      Homie.setNodeProperty(buttonNode, "event", "SINGLEHELD", 0);


int function = 0;

// 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(String value) {
  /*
  Here we handle incoming requests to set the state of the relay
  Set the RELAY_PIN to the appropriate level, and additionally set the
  state on the relayState topic.
  */
  if (value == "ON") {
    digitalWrite(PIN_RELAY, HIGH);
    Homie.setNodeProperty(relayNode, "relayState", value);
