   return true;
 }
 
+void loopHandler() {
+  int buttonState = debouncer.read();
 
-void loopHandler() {
-  //digitalWrite(PIN_RELAY, HIGH);
+  if (buttonState != lastbuttonState) {
+     Serial.print("Button is now: ");
+     Serial.println(buttonState ? "open" : "close");
+
+     if (Homie.setNodeProperty(buttonNode, "open", buttonState ? "true" : "false", true)) {
+       lastbuttonState = buttonState;
+     } else {
+       Serial.println("Sending failed");
+     }
+  }
 }
 
 void setup() {
   pinMode(PIN_RELAY, OUTPUT);
   digitalWrite(PIN_RELAY, LOW);
 
-  Serial.println("Enabling touch switch interrupt");
-  //attachInterrupt(digitalPinToInterrupt(PIN_BUTTON), buttonChangeCallback, CHANGE);
+  pinMode(PIN_BUTTON, INPUT);
+  digitalWrite(PIN_BUTTON, HIGH);
+  debouncer.attach(PIN_BUTTON);
+  debouncer.interval(50);
 
   Homie.setFirmware(FW_NAME, FW_VERSION);
   Homie.setLedPin(PIN_LED, HIGH); // Status LED

#include <Homie.h>

#define FW_NAME "homie-sonoff-touch"
#define FW_VERSION "0.0.5alpha"

/* Magic sequence for Autodetectable Binary Upload */
const char *__FLAGGED_FW_NAME = "\xbf\x84\xe4\x13\x54" FW_NAME "\x93\x44\x6b\xa7\x75";

  Homie.setLoopFunction(loopHandler);
  relayNode.subscribe("relayState", RelayHandler);
  Homie.registerNode(relayNode);
  Homie.registerNode(buttonNode);
  Homie.setup();
}

void loop() {
  Homie.loop();
  debouncer.update();
}
