Blynk notification question

My compliments to the developers and the community … I am enjoying the process of creating user friendly applications linked to smart phones. It seems much easier that prior efforts using web servers. But then a lot of this is still new to me.

A question about Notifications and emails. I have successfully created notifications and emails using the Blynk.notify() and functions.

The question becomes how to send the notifications only once, rather than repeatedly every time my timer calls the function to check for that condition.

My logic I am using is that I have a series of functions that check sensor data or power conditions. Those functions are called with the timer.setInterval() method. Right now, the 6 functions I am using are called every 15 seconds. All of that occurs within the “Setup” section of the code. Within those functions, if a condition is met (power is off, or temp is too high), I send a notification using Blynk.notify. Those functions also push the data to the Blynk Server using Blynk.virtual.write(). All of the code is working, I am just looking for a logic that perhaps rememberers the last “condition” that triggered the notify and only sends another notification when perhaps an hour has passed, or the “condition” has been changed. For example the power went off, then an hour later it came back on. I do not want to get a notification every 15 seconds. But I do want a notification that power has been restored.

Thoughts and comments would be appreciated.

The environment is Mac OS Sierra 10.12.6 … Arduino MKR1000 … Arduino 1.8.3 … Blynk 2.9.8
Would be happy to post the entire code, or snippets if needed.


What im about to suggest might be total crap as i am sleepy as hell but il give it a try.
How about when (for example) when temp is to high you set a virtual pin to high and then you say that when this pin is high send email.
So that the email is only send when the status of the vpin changes and the vpin changes when set temp is reached or not reached.
I hope this makes sense

Basicly what you need to do is code up some resettable “flags” with If() that, combined with boolean logic, allows an action only once (or however many times) within a given timeframe and/or condition.

There is no one way of doing it, and how elegant it looks/functions will depend on your coding experience.

Agreed -
I think both of you are thinking as I am. If the “high temp” condition occurs within the current call of the function, I can perhaps set a “flag” that prevents me from sending another notice or email until that “flag” changes. I use that in some other parts of the code by creating two variables “currentState” and “lastState” … then compare the two after the function has completed the first part of its task, but prior to sending a notice. I will look at some other code examples and see if there is a more “elegant” way of doing it. My coding functions, but it is rather like a “blunt club” sometimes. Will share the snippet when I finish.

Thanks again. Will post other questions and solutions as they arise. I already have one about a “while” loop that seems to be causing the Blynk software to go offline, but that is for another topic.

Got it …
Here is the snippet of code that seems to work well.
Let me know if you have any suggestions. Lots of comments, but just so I can follow it myself later.

Thanks again for the suggestions.

// A function to check for voltage at the powerSensorPin (D6)
void powerSensorStatus()

// Update the current state from the prior state that had been set during the previous call  
priorState = currentState;  

  // Insert code here to check for power outage based on a second "Wall wart"
  // power supply.   If the power fails no voltage will be seen on Digital pin 6
  // If the digitalRead is "1" ... the circuit is closed and power is on
  // If the digitalRead is "0" ... power has been lost to the unprotected
  // circuits ... but the WiFi and Arduino will still work because of the UPS backup
  // set the powerSensorOn LED to LOW and the powerSensorOff to HIGH
  // turn on the buzzer as well ... digital pin 5

  powerStatus = digitalRead(powerSensorPin);

  // Save the current state of the powerSensorPin to a variable
  // Compare the current state to what was the prior state
  // If the state has changed, and powerStatus is LOW
  currentState = powerStatus;

  if (powerStatus == 0)
    // power is OFF .. Turn ON the Red LED , turn OFF the Green LED, turn ON the buzzer
    digitalWrite(powerSensorOff, HIGH);
    digitalWrite(powerSensorOn, LOW);
    digitalWrite(buzzerPin, HIGH);
    // if the power is off and the current state has changed, send an alert and an email to display current powerStatus
    if (priorState != currentState)
      Blynk.notify("Power is OFF");"Subject: Power Status", "Power status has changed to OFF");
      //Blynk.setProperty(V4, "color", "#e80606");  // RED color;
    // power is ON .. Turn OFF the Red LED , turn ON the Green LED, turn OFF the buzzer
    digitalWrite(powerSensorOff, LOW);
    digitalWrite(powerSensorOn, HIGH);
    digitalWrite(buzzerPin, LOW);
    // Send commands to Blynk to change LED indicators
    //Blynk.setProperty(V4, "color", "#0c990c");  // Green color
    // At this time the setProperty is not working for the iOS ...
    // So I am using two LEDS a red and a green to display an on/off condition
    // if the power is ON and the current state has changed, send an alert and an email to display current powerStatus
    if (priorState != currentState)
      Blynk.notify("Power is ON");"Subject: Power Status", "Power status has changed to ON");
      //Blynk.setProperty(V4, "color", "#e80606");  // RED color


  // Print to Serial monitor for troubleshooting
  Serial.print("Current State ");
  Serial.print("Prior State ");


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

You can also use Eventor if you are on Android.
Am I correct @Dmitriy, that this is how notifications work?

Yes eventor does it aswell