Help with delay sending notifications

Hello people, when I receive a permanent 1 in the “pinEntradaSirena” input of the esp8266, I need it not to send me notifications immediately, but if about 5 seconds have passed before that time, it does not send any notification… can you help me. From already thank you very much.
I need to be able to implement this delay so that the system only sends me notifications only when the 1 is maintained for more than 5 seconds, before that time I don’t need notifications of that input.

> //Placa versión: Lolin WeMos D1 R1 3.0.2
> //Versión Biblioteca Blynk: 1.1.0
> 
> 
> 
> // Fill-in information from your Blynk Template here
> 
> 
> #define BLYNK_TEMPLATE_ID "TMPL2FNX-JgNz"
> #define BLYNK_DEVICE_NAME "panelwifi503"
> 
> #define BLYNK_FIRMWARE_VERSION "0.1.10"
> 
> #define BLYNK_PRINT Serial
> // #define BLYNK_DEBUG
> 
> #define APP_DEBUG
> 
> // Uncomment your board, or configure a custom board in Settings.h
> // #define USE_SPARKFUN_BLYNK_BOARD
> //  #define USE_NODE_MCU_BOARD
> // #define USE_WITTY_CLOUD_BOARD
> #define USE_WEMOS_D1_MINI
> 
> #include "BlynkEdgent.h"
> #include <Ticker.h>
> Ticker ticker;
> // #include <RCSwitch.h>
> // RCSwitch mySwitch = RCSwitch();
> 
> ///////////PINES SIRINA2///////
> int pinEntradaSirena = 12; //GPIO12 = D6
> int pinPGM_Pulso = 14;      //GPIO14 = D5
> int pinEstado = 13;       //GPIO 13 = D7
> //////////////////////////////
> 
> const byte ledPin = 16;
> bool alarm_mode = false;
> bool verificador = false;
> bool variable = false;
> 
> int contconexion = 0;
> int conteoReactivacion = 0;
> int estado_1 = 0;
> int estado_2 = 0;
> int cont = 0;
> String mensaje = "";
> bool ledTestigo = LOW;
> //int VirtualPinA = 3;
> // int resetact = 1;
> int resetestado = 1;
> int historialDisparo = 0;
> int estadoinicial = 0;
> int latchButton;
> int latchFlag;
> WidgetLCD lcd_estado(V5);
> 
> 
> unsigned long previousMillis = 0;
> unsigned long momentoDisparoAlarma = 0;
> bool estaAlarmaActivada = false, estaAlarmaActivadaAnterior = false;
> bool estaSirenaSonando = false, estaSirenaSonandoAnterior = false;
> 
> bool notificacionEnviada = false;
> 
> BlynkTimer timer;
> 
> 
> //===== Botón de enclavamiento temporizado =====
> BLYNK_WRITE(V6)
> { // Widget de botón configurado como interruptor
>   
>     Blynk.setProperty(V6, "color", "#12a370"); // RED   //COLOR FONDO DE BOTON, ON
>     Blynk.setProperty(V6, "label", ""); // ON
>   
>   latchButton = param.asInt();
>   if (latchButton == 1 && latchFlag == 0)
>   {
>     latchFlag = 1; // Impide que se presione el botón más de una vez mientras el relé está activado
>     // ----- Comience su cosa cronometrada aquí
>     digitalWrite(pinPGM_Pulso, HIGH); // Activate digital pin
>     // -----
>     timer.setTimeout(1500L, []() { // liberación del botón de enganche después de 1.5 segundos
>       // ----- Detén tu cosa cronometrada aquí
>       digitalWrite(pinPGM_Pulso, LOW); //Desactivar pin digital
>       
>       // -----
>       Blynk.virtualWrite(V6, 1); // Restaurar el botón de enclavamiento en ON hasta que finalice el temporizador
>       
>       Blynk.setProperty(V6, "color", "#12a370"); // RED  //COLOR FONDO DE BOTON, ON
>       Blynk.setProperty(V6, "label", ""); // ON
>       
>       latchFlag = 0;             // se restablece para permitir la siguiente interacción
>     });                          // Final Función temporizador 
>   }
>   else
>   {
>     if (latchButton == 0 && latchFlag == 1)
>     { // Si intenta apagar el botón antes de que se acabe el tiempo
>       Blynk.virtualWrite(V6, 1); // Restaurar el botón de enclavamiento en ON hasta que finalice el temporizador
>     }
>   }
> }
> 
> 
> 
> //Esta función se ejecuta cada vez que Blynk pasa de "desconectado" a "conectado", ya sea por reconexión a WiFi/internet.
> //Dentro de ella forzamos la actualización de los pines virtuales en función de los GPIOs sin enviar eventos.
> BLYNK_CONNECTED() {
>   Blynk.virtualWrite(V1, !digitalRead(pinEstado));
>   Blynk.virtualWrite(V0, digitalRead(pinEntradaSirena)?"SONANDO ACTUALMENTE":"");
>   lcd_estado.clear();  
> }
> 
> //Esto funcionaba pero ya no
> BLYNK_APP_CONNECTED()
>   {
>   Serial.println("App Abierta.");
>   }
> 
> BLYNK_APP_DISCONNECTED()
>   {
>   Serial.println("App Cerrada.");
>   } 
> 
> void setup() {
>   delay(50);
>   pinMode(pinEntradaSirena, INPUT_PULLUP); // Da 1 cuando se dispara la alarma
>   pinMode(pinPGM_Pulso, OUTPUT);           // Entrega un pulso de 1,5s para activar desactivar la alarma
>   pinMode(pinEstado, INPUT_PULLUP);        // Lee si la alarma está activada, evento "alarma activada"
>   Blynk.virtualWrite(V6, 1); // set coloured button to default ON state
>   //mySwitch.enableTransmit(2); //pin donde se conecta al modulo el rf de la alarma.
>   Serial.begin(115200);
>   
>   lcd_estado.clear();
>   lcd_estado.print(5, 0, "SIRINA");
>   
>   BlynkEdgent.begin();
> }
> 
> void loop() {
>   BlynkEdgent.run();
>   timer.run();
>   //Serial.flush();
> 
>    /******* LED TESTIGO   *****************/
>   if(millis() - previousMillis >= 1000) {        //Esta función se ejecuta una vez cada 1000 miliSegundos, basado en ejemplo Digital\BlynkWithoutDelay
>     previousMillis = millis();                  //Al usar este método dentro del loop evitamos el uso de interrupciones.
>     ledTestigo =! ledTestigo;                   //Alternamos el estado, si estaba encendiDo lo apagamos y visceversa.
>     Blynk.virtualWrite(3, 1023*ledTestigo);    //Si el led esta en 0 la cuenta da 0, y si estaba en 1 la cuenta da 1023; encendiendo el Led Virtual en Blynk
> 
>        
>     if(digitalRead(pinEstado)) {
>       lcd_estado.print(0, 0, "    ACTIVADO    ");
>       lcd_estado.print(0, 1, " HOGAR PROTEGIDO ");
>     }
>     else {
>       lcd_estado.print(0, 0, " DESACTIVADO    "); 
>       lcd_estado.print(0, 1, " SIN PROTECCION ");
>     }
>   }
> 
> /******* ALARMA ACTIVADA/DESACTIVADA   *****************/
>   estaAlarmaActivada = digitalRead(pinEstado);
>   if(estaAlarmaActivada != estaAlarmaActivadaAnterior and estaSirenaSonando == false) {     //Analizamos si la alarma cambió de estado,
>   estaAlarmaActivadaAnterior = estaAlarmaActivada;                                          //Y si lo hizo actualizamos Blynk
>   
>     if(estaAlarmaActivada) {
>       Blynk.virtualWrite(V1, 0);
>      serialDebug("estado","activada");
>      Blynk.logEvent("alarma_activada");
>       
> 
>      // Blynk.setProperty(V6, "color", "#ff0000");        //Rojo
>     //  Blynk.setProperty(V6, "label", "DESACTIVAR");
>   }
> 
>     else {
>      Blynk.virtualWrite(V1, 1);
>      serialDebug("estado","desactivada");
>      Blynk.logEvent("alarma_desactivada");
>    
>  //   Blynk.setProperty(V6, "color", "#00ff00");          //Verde
>   //    Blynk.setProperty(V6, "label", "ACTIVAR ALARMA");
>      
>     }
>   }
> 
> 
>  /******* SIRENA   *****************/
>   estaSirenaSonando = digitalRead(pinEntradaSirena);
>   if(estaSirenaSonando != estaSirenaSonandoAnterior) {   //Analizamos si la sirena cambió de estado (sonando o no)
>     estaSirenaSonandoAnterior = estaSirenaSonando;      //y si cambió de estado debemos analizar si la alarma estaba activada o no
>     
>     if(estaSirenaSonando == false) {
>       Blynk.virtualWrite(V0, 0);
>       serialDebug("sirena","normal");
>     }
> 
>     else {                                    
>       Blynk.virtualWrite(V0, 1);
>       Blynk.logEvent("disparo_de_alarma");
>       momentoDisparoAlarma = millis();
>       serialDebug("sirena","SONANDO");
>      
>       
>       if (estaAlarmaActivada == false) {
>           //Serial.println("Sonando, alarma desactivada");
>           //Serial.println("{\"alerta\":\"ENVIADA\"}");
>           Blynk.virtualWrite(V2, "NORMAL");
>           Blynk.logEvent("alarma_desactivada");
>       }
>       else {
>         Blynk.virtualWrite(V2, "ALERTA");
>         Blynk.logEvent("alarma_activada");
>         //Serial.println("{\"alerta\":\"no\"}");
>       }
>     }
>   }
> 
>   if(digitalRead(pinEntradaSirena) and millis() - momentoDisparoAlarma >=30*1000){  //Si la sirena está sonando cada 30 segundos enviamos la notificacion a blynk (total blynk la limita)
>     momentoDisparoAlarma = millis();
>     Blynk.logEvent("disparo_de_alarma");
>     Serial.println("disparo de alarma");
>   }
> }
> 
> void serialDebug(String key, String value) {
>     Serial.println("{\""+key+"\":\""+value+"\"}");
> }

please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly. Triple backticks look like this: ```

thanks corrected

Https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean

As far as event triggers, you will be given only 100 triggers per day per device , if you want notifications every 5 seconds or so, you will run out of quota.

You need to utilise event notifications carefully.

You can change the settings in the web dashboard where you created the event. I don’t exactly remember the term, but it should be like trigger interval.

Example:

So if you set it to one hour interval, if you have multiple triggers in that hour, you will get only one notification. Rest all will be ignored.

I think I was not clear, I have solved the limits of the notifications. What I want to solve is that when receiving a 1 through the “pinEntradaSirena” pin, the notifications are sent after 5 seconds of having entered that 1 in the “pinEntradaSirena” pin because now it is sending notifications immediately upon receiving the 1 and I need it to have that delay when receiving that signal

I will try to explain better, the equipment is being used as a home alarm communicator, and the “pinEntradaSirena” input is the one that receives the signal from the burglar alarm siren… but that same siren also sounds when activated and deactivate the alarm, and I need that pin “EntradaSirena” only send notifications after 5 seconds… to make sure that it only sends for theft… since in that state of theft the siren sounds for more than 5 seconds ( 5 minutes) and not for activation and deactivation of the alarm, which are shorter touches, but just like this, it sends me erroneous notifications for theft…

You can write a logic,

If the digital pin is high for x seconds, then trigger notification.

This is a snippet by chatGPT

void loop() {
  int inputState = digitalRead(INPUT_PIN); // read the input pin state
  
  if (inputState == HIGH) { // if the input pin is high
    if (inputStartTime == 0) { // if this is the first time the input pin became high
      inputStartTime = millis(); // record the start time
    }
    
    if (millis() - inputStartTime < ON_DURATION) { // if the elapsed time is less than the on duration
      digitalWrite(LED_PIN, HIGH); // turn on the LED
    } else { // if the elapsed time is equal or greater than the on duration
      digitalWrite(LED_PIN, LOW); // turn off the LED
    }
  } else { // if the input pin is low
    digitalWrite(LED_PIN, LOW); // turn off the LED
    inputStartTime = 0; // reset the start time
  }
}

You can use the same logic in your case.

@ale24cba lest start with the way that you’ve posted your code to the forum.
You originally used Blockquotes, then added triple backticks. Unfortunately, you did this without turning-off Blockquotes, so now every line of code has a “>” symbol in front of it, from the Blockquotes.

Please edit your initial post and fix this, by re-pasting your code between triple backticks, without using Blockquotes.

Your code is far more complex than it needs to be, and that makes it difficult to follow (and the blockquotes don’t help).

I doubt very much that this statement is true…

Your code initialises a BlynkTimer object, but you are oly using this for a single timeout timer, instead of using it to solve the problem you’re having and to remove the clutter from your void loop.

The solution to your problem is simple…

Use BlynkTimer to call a function once every second.
In that function you read the alarm pin, and if the alarm is sounding you set a flag and you increment a counter
If the alarm is silent you un-set the flag, and zero your counter.

Within the same function you then check if the flag is set, and the counter >= 5
If this is the case then the alarm has been sounding for more than 5 seconds.

Pete.