Google Home / Fritzbox phone notify you when someone rings the door bell

I am trying to figure out to get notified via Google Home / Fritzbox phone when someone rings the door bell.
Therefore I use NodeMCU LUA AMICA V2 Modul with ESP8266E. Which should be outside in the door bell connected to the door bell switch.

I have got inspired by this articel. This articel only shows the code for fritzbox phone notification.
https://www.reichelt.com/magazin/en/build-smart-doorbell-arduino/

This code I combined with "esp8266-google-home-notifier.h" for following action:

a) If someone presses the door bell button, ESP8266E sends a notification via google home mini like "Someone rings the door bell".

b) If someone presses the door bell button for the second time, ESP8266E sends a notification via google home mini like "Someone rings the door bell" again.

c) If someone presses the door bell button for the third time, ESP8266E activite Fitzbox and rings all connected phones and hang up after e.g. 4 times.

Therefore I created this source code (the LEDs are just for development purpose and shows in which state the controller actually is), see below.

During the test following issue came up. Everything works fine. Pressing two times the button google home mini notify the message. After the third time, Fritzbox sends me phone call.

Issue:
If i press the button for the fourth time. I got a message: "connection failed". Means google home mini is not available.

Sometimes I got an error message if calling Fritzbox "[action] got an unauthenticated error. Using the new nonce and trying again in 3s.".

The thing is nofication via google home mini (stand alone) works fine. Also notification via fritzbox (stand alone) works fine.

If i combine both: google home mini and fritzbox, always these two failures occure.

Example: Connection failed to google home mini
12:29:25.757 -> WiFi connected..!
12:29:25.757 -> Got IP: 192.168.2.176
12:29:25.757 -> Connecting to
12:29:25.791 -> Stangl
12:29:25.791 -> Connect to Google
12:29:25.791 -> connecting to Google Home...
12:29:26.772 -> found Google Home(192.168.2.133:8009)
12:29:32.195 -> Initialize TR-064 connection
12:30:23.131 -> Fritzbox call
12:30:23.131 -> taster_counter
12:30:23.131 -> Call **621
12:30:27.230 -> Dial Hangup
12:30:37.711 -> connection failed

#include <Bounce2.h>
#include <ESP8266WiFi.h>
#include <esp8266-google-home-notifier.h>
#include <tr064.h>


//**********************************************************
const int taster = D7;
const int rot = D6;
const int gruen = D8;

int tasterstatus = 0;
int tasterstatusAlt = 0;
int taster_counter = 0;
//***************************************************************

const char* ssid     = "Wifi-Network"; <- must be changed
const char* password = "12345678"; <- must be changed


const char GoogleHomeName[] = "Büro";  //Must match the name on Google Home APP

/* Put IP Address details */
const IPAddress local_ip(192, 168, 2, 160);
const IPAddress gateway(192, 168, 2, 1);
const IPAddress subnet(255, 255, 255, 0);
const IPAddress DNS(gateway);

const char DEVICE_NAME[] = "Door bell";

//fritzbox
const char USER[] = "admin";
const char PASSWORD[] = "fritzbox password"; // <-- ändern
const char FRITZBOX_IP[] = "192.168.2.1"; //<- fitzbox IP
const int FRITZBOX_PORT = 49000;

TR064 tr064_connection(FRITZBOX_PORT, FRITZBOX_IP, USER, PASSWORD);

// Instantiate a Bounce object
Bounce debouncer = Bounce();

//Google
GoogleHomeNotifier ghn;
void connectToGH() {

Serial.println("connecting to Google Home...");
if (ghn.device(GoogleHomeName, "de") != true) {
 
  Serial.println(ghn.getLastError());
  TRACE();
  return;
}
Serial.print("found Google Home(");
Serial.print(ghn.getIPAddress());
Serial.print(":");
Serial.print(ghn.getPort());
Serial.println(")");
}

//**********************************************************************

void setup() {
Serial.begin(115200);
pinMode(taster, INPUT);
pinMode(rot, OUTPUT);
pinMode(gruen, OUTPUT);

  // After setting up the button, setup the Bounce instance :
debouncer.attach(taster);
debouncer.interval(100); // interval in ms

  //connect to your local wi-fi network
WiFi.hostname(DEVICE_NAME);
WiFi.begin(ssid, password);
WiFi.config(local_ip, gateway, subnet, DNS); 

//check wi-fi is connected to wi-fi network
while (WiFi.status() != WL_CONNECTED) {
  delay(500);
  Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected..!");
Serial.print("Got IP: ");  Serial.println(WiFi.localIP());
Serial.println("Connecting to ");
Serial.println(ssid);

Serial.println("Connect to Google");
connectToGH();
ghn.notify("Microcontroller gestartet!");

Serial.println("Initialize TR-064 connection");
tr064_connection.init();
}

//*************************************************************************************
void loop() {
// Update the Bounce instance :
debouncer.update();

// Get the updated value :
tasterstatus = debouncer.read();

 if ( debouncer.fell() )
{

  if (taster_counter<2)
  {
  digitalWrite(rot, HIGH);
  digitalWrite(gruen, LOW);
 taster_counter++;
  ghn.notify("Hey, es klingelt jemand an der Tür!");
    }
  else
  { digitalWrite(rot, LOW);
    digitalWrite(gruen, HIGH);
    taster_counter=0;
     Serial.println("Fritzbox call");
     Serial.println("taster_counter");
      String tr064_service = "urn:dslforum-org:service:X_VoIP:1";                     
  Serial.println("Call **621");
   
   // Telephone number **621 vor calling phones
 String call_params[][2] = {{"NewX_AVM-DE_PhoneNumber", "**621"}};
    tr064_connection.action(tr064_service, "X_AVM-DE_DialNumber", call_params, 1);
     
   // Wait 4 seconds until hang up
  // 16000 ~ 4x ring bell
   delay(4000);
 
tr064_connection.action(tr064_service, "X_AVM-DE_DialHangup"); //hier: [action]<error> nonce/realm request not successful!
    Serial.println("Dial Hangup");
   delay (5000);
  }   
}
}

Im not familiar with Fritzbox, but have you tried coding in a disconnect all, and then reconnect to google home? It could be that its struggling with working out which one to talk to while both connected?

Either that or maybe Google Home accesses via a different port, and you override which port when you connect to Fritzbox and it doesn't switch back?

Not a straight answer but might give you a few things to try

Spice

Thanks for your reply.

Are there any runtime issues which I have to consider on ESP8266?

Fritzbox is on port: 49000.
Google home mini is on port: 8009

Wifi disconnection could bring me a step further. I will try it.

I was figering out where the failure message come from. there it comes from google home.
But I do not know what to do.

There it comes from google home.
connection failed
libraries\esp8266-google-tts-master\src\google-tts.cpp

String GoogleTTS::getTKK() {
  unsigned long current = millis();
  bool bClientCreated = false;
  // WiFiClientSecure client;
  if (m_pClient == nullptr) {
    m_pClient = new WiFiClientSecure();
#if defined(ARDUINO_ARCH_ESP8266) && !defined(ARDUINO_ESP8266_RELEASE_BEFORE_THAN_2_5_0)
    m_pClient->setFingerprint(FINGERPRINT_GTRANS);
#endif
    bClientCreated = true;
  }
  if (!m_pClient->connect(HOST_GTRANS, 443)) {
    Serial.println([b]"connection failed"[/b]);
    if (bClientCreated == true) {
      delete m_pClient;
      m_pClient = nullptr;
    }
    return "_ERROR";
  }

There it comes from Fritzbox.
[action] nonce/realm request not successful!

Fritzbox: libraries\Arduino-TR-064-SOAP-Library-master\src

String TR064::action(String service, String act, String params[][2], int nParam) {
    deb_println("[action] with parameters", DEBUG_VERBOSE);
    
    String status = "unauthenticated";
    String xmlR = "";
    int tries = 0; // Keep track on the number of times we tried to request.
    while (status == "unauthenticated" && tries < 3) {
        ++tries;
        while ((_nonce == "" || _realm == "") && tries <= 3) {
            deb_println("[action] no nonce/realm found. requesting...", DEBUG_INFO);
            // TODO: Is this request supported by all devices or should we use a different one here?
            String a[][2] = {{"NewAssociatedDeviceIndex", "1"}};
            xmlR = action_raw("urn:dslforum-org:service:WLANConfiguration:1", "GetGenericAssociatedDeviceInfo", a, 1);
            takeNonce(xmlR);
            if (_nonce == "" || _realm == "") {
                ++tries;
                deb_println("[action]<error> nonce/realm request not successful!", DEBUG_ERROR);
                deb_println("[action]<error> Retrying in 5s", DEBUG_ERROR);
                delay(5000);
            }
        }

hak5:
a) If someone presses the door bell button, ESP8266E sends a notification via google home mini like "Someone rings the door bell".

As far as I know, ESP8266 cannot actively trigger Google Home. Only Google Home can triggers ESP8266. If some one know the way to make ESP8266 actively trigger Google Home, please share with me!

Yes, ESP8266 can trigger Google Home. Copy me source code and remove the part with Fritzbox and it will work.