Help with notifications in the code

Hello people ! I was finally able to transfer my code from Blynk legacy to Blynk Iot!
I had a problem, but I don’t know how to solve it, my knowledge is very basic, now with the restriction of 100 events per day, I discovered a “fault” that was always in the code… the device is an alarm event communicator It has an input that reads the status of the alarm that changes, every time the alarm center is activated or deactivated it sends a notification “ALARMA ACTIVADA” or “ALARMA DESACTIVADA” the problem is that when the alarm center sounds at that The status pin toggles it turning that status input on and off as a result, it sends a lot of notifications along with the “alarm shot” notification, therefore I quickly run out of 100 daily notifications, I need someone to advise me, to make it sound when it rings The alarm center sends notifications only “DISPARO DE ALARMA” and that in this situation does not send “ALARMA ACTIVADA” or “ALARMA DESACTIVADA” they do not work.
to avoid overloading with unnecessary notifications. From already thank you very much.

 // Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "TMPLezps5ITN"
#define BLYNK_DEVICE_NAME "SIRINA2"

#define BLYNK_FIRMWARE_VERSION        "0.1.0"

#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"
//for LED status
#include <Ticker.h>
Ticker ticker;
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();

const byte ledPin = 16;
bool alarm_mode = false ;
bool verificador = false;
bool variable = false;
int jumper = 16;
int EntradaSirena = 5;
int buzzer = 15;
int estado = 12;
int alarm_led = 4;
int alarm_led_off = 0;
int contconexion = 0;
int conteoReactivacion = 0;
int estado_1 = 0;
int estado_2 = 0;
int cont = 0;
String mensaje = "";
int ledState = LOW;             // ledState used to set the LED
int VirtualPinA = 3;
int resetact = 1;
int resetestado = 1;
int historialDisparo = 0;
int estadoinicial = 0;
//callback notifying us of the need to save config

void ledState1()
{
   if (ledState == LOW) {
      ledState = HIGH;
      Blynk.virtualWrite(VirtualPinA, 0);
     
    } else {
      ledState = LOW;
      Blynk.virtualWrite(VirtualPinA, 1023);
     
    }
  }


BlynkTimer timer;
void myTimerEvent() {

  estado_1=digitalRead(estado);//lee el estado y lo guarda en la variable mensaje
  while((estado_1!=estado_2)&&(cont!=1)){//sale del bucle cuando el valor de mensaje es 1
  estado_2=digitalRead(estado);//lee el estado y lo guarda en la variable mensaje
  
   if(digitalRead(estado) == HIGH){
    Blynk.virtualWrite(V1, 1);
    if (resetestado != 1) // cuando se reset el equipo no envia "alarma activada"
  
    Blynk.logEvent("alarma_activada");
    resetestado =  0; 
 
  cont++;
   }else{
   Blynk.virtualWrite(V1, 0);

   Blynk.logEvent("alarma_desactivada");
  cont++;
   } 
estado_1=estado_2;
}
   cont=0;
  if(digitalRead(jumper) == HIGH){
    Serial.println('1');
    variable = true;
  }else{
    Serial.println('0');
    variable = false;
  }
  if (digitalRead(EntradaSirena) == 0) {
    Blynk.virtualWrite(V0, "NORMAL");
    delay(5000);   // Tiempo de demora al recibir señal de disparo
  }
  if (digitalRead(EntradaSirena) == 1) {
   Blynk.virtualWrite(V0, "ALERTA");
   Blynk.logEvent("disparo_de_alarma");
   
   historialDisparo = 1;
   delay(500);
  }else{
         if (historialDisparo == 1){ 
          Blynk.logEvent("alarma_desactivada");
          historialDisparo = 0;
         }
  } 
}

BLYNK_WRITE(V1) {
  Serial.println(param.asInt());
  switch (param.asInt()) {
    case 1: {
       if (resetact != 1) 
      mySwitch.send(5234600, 24); 
      resetact =  0;  
       
      if(variable == true){
        alarm_mode = true;
        digitalWrite(alarm_led, HIGH);
      }else{
       if (resetact != 1) 
        { 
         alarm_mode = true;
         digitalWrite(alarm_led, HIGH);
         delay(500); // tiempo de pulso de activacion de alarma
        
         alarm_mode = false;
         digitalWrite(alarm_led, LOW);
        }
        resetact =  0;  
      }
        break;
      }
    case 2: {
        alarm_mode = false;
        // digitalWrite(buzzer, LOW);
        digitalWrite(alarm_led, LOW);
       
        break;
    }    
  }
}

void setup()
{
  pinMode(EntradaSirena, INPUT_PULLUP);
  pinMode(buzzer, OUTPUT);
  pinMode(alarm_led, OUTPUT);
  pinMode(alarm_led_off, OUTPUT);
  pinMode(estado, INPUT_PULLUP);
  pinMode(jumper, INPUT);
 // pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
 
    
  mySwitch.enableTransmit(2); //pin donde se conecta al modulo el rf de la alarma.
     
//start ticker with 0.5 because we start in AP mode and try to connect
  //ticker.attach(0.6, tick);
 
  // Debug console
  Serial.begin(115200);
  Serial.println();

  timer.setInterval(1000L, myTimerEvent);
  timer.setInterval(1000L, ledState1); //timer will run every sec 

  BlynkEdgent.begin();
  }

void loop() {
  BlynkEdgent.run();
  timer.run();
}

How are these notifications send and seen by you?
How can your D1 Mini distinguish between these various messages?

Pete.

HELLO ! Pete, when the siren input is 1, it sends notifications to my cell that the alarm is going off.

 if (digitalRead(EntradaSirena) == 0) {
    Blynk.virtualWrite(V0, "NORMAL");
    delay(5000);   // Tiempo de demora al recibir señal de disparo
  }
  if (digitalRead(EntradaSirena) == 1) {
   Blynk.virtualWrite(V0, "ALERTA");
   Blynk.logEvent("disparo_de_alarma");

and the state of the alarm (ALARM ENABLED OR DISABLED) is known by the “status” pin

if(digitalRead(estado) == HIGH){
    Blynk.virtualWrite(V1, 1);
    if (resetestado != 1) // cuando se reset el equipo no envia "alarma activada"
  
    Blynk.logEvent("alarma_activada");
    resetestado =  0; 
 
  cont++;
   }else{
   Blynk.virtualWrite(V1, 0);

   Blynk.logEvent("alarma_desactivada");
  cont++;

I hope Pete that with this information you can guide me to find the solution, thank you very much in advance

So why don’t you simply change the second piece of code so that you don’t send these notifications?

Pete.

My knowledge is very basic pete… excuse me. how would it be? I don’t understand

Remove these two lines of code.

Pete.

I can’t pete because I need those notifications to know that the alarm has been activated or deactivated (on or off) with the remote control, but when the alarm sounds for example due to theft, it alerts me to the alarm trigger notifications, but at the same time also The other alarm activation/deactivation notifications begin to arrive. That is because the pin that I read to know the status, which is 0, 1, but when the system sounds for theft, that pin flashes like a beacon and that is where it starts to send those unwanted notifications, in short, I need that when the alarm send the “alarm trigger” notifications do not send me the other two activation / deactivation.

So you only want the activated/deactivated alerts if the estado pin is HIGH? Like this…

if (digitalRead(EntradaSirena) == 0 && digitalRead(estado) == HIGH))

Pete.

Of course, Pete, how can I implement what you tell me in my code…?? So now I try!

pete tried to implement but couldn’t get it to work it keeps sending “Alarm on” , “Alarm off” notifications when alarm goes off…

Did you do both if statements?

Pete.

Gracias Pete

Hello good here I am still solving problems with my old code that worked fine with the previous blynk and with the new one I found some limitations, I have a problem with the events I reach the maximum limit very quickly, and reading I think I found the problem but I don’t know how solve it my knowledge is very basic in programming. I have an output of an atmega328 that when triggering an action sends a permanent HIGH of 5 minutes to the input "EntradaSirena = 5; " of the esp8266 therefore it does not HIGH sending notifications and as I read somewhere that causes the problem that I have with my event limits, I read over there that fellow pete wrote to set a flag to limit junk notifications, but in my case the value is only high for 5 minutes and after that time is low, I was checking and I think one of the One way is to put setTimeout but I honestly don’t know how to implement it in my code. I hope you can help me in advance, thanks.

 // Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "TMPLunOk9YJk"
#define BLYNK_DEVICE_NAME "Sirina1"
#define BLYNK_FIRMWARE_VERSION        "0.1.9"

#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();

const byte ledPin = 16;
bool alarm_mode = false ;
bool verificador = false;
bool variable = false;
int jumper = 16;
int EntradaSirena = 5;
int estado = 13;
int PGM_PULSO = 14;
int contconexion = 0;
int conteoReactivacion = 0;
int estado_1 = 0;
int estado_2 = 0;
int cont = 0;
String mensaje = "";
int ledState = LOW;             // ledState used to set the LED
int VirtualPinA = 3;
//int resetact = 1;
int resetestado = 1;
int historialDisparo = 0;
int estadoinicial = 0;
int latchButton;
int latchFlag;
void ledState1()

{
  if (ledState == LOW) {
  ledState = HIGH;
  Blynk.virtualWrite(VirtualPinA, 0);  
} else {
  ledState = LOW;
  Blynk.virtualWrite(VirtualPinA, 1023);  
}
  }
  

BlynkTimer timer;
void myTimerEvent() {

estado_1=digitalRead(estado);//lee el estado y lo guarda en la variable mensaje
  while((estado_1!=estado_2)&&(cont!=1)){//sale del bucle cuando el valor de mensaje es 1
  estado_2=digitalRead(estado);//lee el estado y lo guarda en la variable mensaje
   if(digitalRead(estado) == HIGH){
Blynk.virtualWrite(V1, 0);
Blynk.logEvent("alarma_activada");
  cont++;
   }else{
   Blynk.virtualWrite(V1, 1);
   Blynk.logEvent("alarma_desactivada");
  cont++;
   } 
estado_1=estado_2;
}
   cont=0;
  if(digitalRead(jumper) == HIGH){
Serial.println('1');
variable = true;
  }else{
Serial.println('0');
variable = false;
  }
  if (digitalRead(EntradaSirena) == 0) {
Blynk.virtualWrite(V0, "NORMAL");
  }
  if (digitalRead(EntradaSirena) == 1)
  {
Blynk.virtualWrite(V0, "ALERTA");
Blynk.logEvent("disparo_de_alarma");

  if (digitalRead(estado) == 1) {
Blynk.virtualWrite(V2, "NORMAL");
 Blynk.logEvent("alarma_desactivada");
  }
  if (digitalRead(estado) == 0)
  {
Blynk.virtualWrite(V2, "ALERTA");
Blynk.logEvent("alarma_activada");
  
 }
if (alarm_mode == true) 
{
}
  }
}
//===== Timeed latching button =====
BLYNK_WRITE(V1) {  // Button Widget set as switch
  latchButton = param.asInt();
  if (latchButton == 1 && latchFlag == 0) {
latchFlag = 1;  // Keeps from allowing button press more then once while relay activated
// ----- Start your timed thing here
digitalWrite(PGM_PULSO, HIGH); // Activate digital pin
// -----
timer.setTimeout(1500L, []() {  // Timed Lambda Function - Latching Button release after 5 seconds
  // ----- Stop your timed thing here
  digitalWrite(PGM_PULSO, LOW); // Deactivate digital pin
  // -----
  Blynk.virtualWrite(V1, 0);  // Reset Latching Button to OFF
  latchFlag = 0;  // resets to allow next interaction
});  // END Timer Function
  } else {
if (latchButton == 0 && latchFlag == 1) {  // If you try to tun off the button before time is up
  Blynk.virtualWrite(V1, 1);  // Restore Latching Button ON until timer is finished
}
  }
}
void setup()
{
  pinMode(EntradaSirena, INPUT_PULLUP);
  pinMode(PGM_PULSO, OUTPUT);
  pinMode(estado, INPUT_PULLUP);
  pinMode(jumper, INPUT);
//  mySwitch.enableTransmit(2); //pin donde se conecta al modulo el rf de la alarma.
  Serial.begin(115200);
  Serial.println();

  timer.setInterval(1000L, myTimerEvent);
  timer.setInterval(1000L, ledState1); //timer will run every sec 

  BlynkEdgent.begin();
  }

void loop() {
  BlynkEdgent.run();
  timer.run();
}

@ale24cba please don’t keep creating new topics about the same subject. I’ve merged your new on in with this one, but next time I’ll simply delete the new one.

Rather than drip-feeding snippets of information about how your alarm system works, along with overly complicated and poorly documented code, you’d be far better taking the time to fully explain the operation of your alarm, and your requirements in terms of Blynk functality.

Pete.

If pete is on the same topic Events, but they are different problems…! in this case how to solve the massive sending of events to blynk, when the incoming signal is a permanent stop in this case for 5 minutes

The solution is simple and explained as well as I possibly can in my events and flag variables tutorial.
when the output goes HIGH send one notification and set a flag. Don’t send any more notifications while the output remains high (flag set) then clear the flag when the output goes LOW.

Pete.