WeMos D1 (ESP-8266) Doorbell

I want to control my doorbell and door-opener with a ESP-12 or WeMos.

Control the doorbell and door-opener is the first step for my next Project. So i open my HT 2003 GVS and check how it works. At the end two points are interesting. On the left site is a small metal slab. If i press down the button to open the door this part go down and connect to Pins. The other point is the summer if someone rings. The summer works with 12V AC. So the plan was the following:

Use a Relay and some wire to connect a Relay to the door-opener. The input for the Relay comes from the WeMos D1 mini. The connections to the summer go to the input of a 12V/AC Relay. If the Relay switch this input can read at the WeMos D1. So i have access to both function.

After the plan was done i setup everything. First I connect the output from the doorbell (12V AC) to the input of a 12 V/AC Relai. On the other side I connect 3.3 V to one output of the Relai and the other end to the D2 input pin. So if someone rings the bell I can read it at the WeMos. To control the Door-Opener i connect a Reilai (like in this Post) and put the output to the pins of the summer. At the end they work correct if a connection between exists.

The Software is really easy and also works with my HandlerCloud Library.


HandlerCloud hCloud;

int lastMessage = 0;
int openCount = 10000;

void setup() {
  // put your setup code here, to run once:
  pinMode(D2, INPUT);
  pinMode(D1, OUTPUT);
  digitalWrite(D1, LOW);
void doorCalback(char* topic, byte* payload, unsigned int length) {
  Serial.println("Incomming Clalback");
  String msg = "";
  for (int i = 0; i < length; i++) {
    msg = msg + String((char)payload[i]);
  String t = String(topic);
    openCount = 0;
  digitalWrite(D1, HIGH);
  Serial.println("Open Door");

void loop() {
  // put your main code here, to run repeatedly:
  int val = digitalRead(D2);
  if(val==HIGH && lastMessage == 0)
    lastMessage = 1;
    hCloud.publishMessage("soeren/door/bell", "1");
  if(val==LOW && lastMessage == 1)
    lastMessage = 0;
    hCloud.publishMessage("soeren/door/bell", "0");
  if(openCount < 50) {
  } else if(openCount != 10000) {
    openCount= 10000;
    Serial.println("CLOSE DOOR");
    hCloud.publishMessage("soeren/door/open", "0");
    digitalWrite(D1, LOW);
    //analogWrite(D1, 255);

 First i set D1 to output and D2 to input (inverse from the Plan) and start the MainLoop. In the lastMessage i save if i already send a "the doorbell is rining" notification via MQTT. So if i dont send it but the connection via the relai is stable I publish a MQTT-Message. After the relai is close the connection i publish again a "Stop Rining" MQTT-Message. 

If i want to open the door I just neet to send a "1" to the Topic "soeren/door/open". The script count the Secounds and after 5 (which is very very long, maybe i will set it to 3) secounds it stop pushing the door-open button (relai) and send a "0" to the same topic. 

With this solution i can let my light blink if someone rings or send myself a chat-notification.