Tiny help with blynk notify occurances

so my code has a 6 min loop where it looks at temps and decided to open vetns.

each time it decides to do something i want it to have the option to tell me via blynk.notify, but ONLY if it hasnt just told me, i.e. only tell me if you made a different decsion to teh one you just previously made. if you decide the same thing, dont tell me.

so i have tried this:

decide things
          if ((blynkNotify == 1) && (bedsVentNotify < 1))
          {
            Blynk.notify(String((currentTime) + (" MCU just decided this for the bedroom vent")));
            bothVentsNotify = 0;
            livingVentNotify = 0;
            bedsVentNotify = 1;
            nilVentNotify = 0;
          }
do other stuff

with these variables up front:

bool blynkNotify = 1; //this is the switch for sending notifications to Blynk
int blynkNotifySwitch, roofNotify, houseNotify, externNotify;

but every loop it sends the blynk.notify - regrdless of the variables value?

i also have tried (bedsVentNotify == 0) and (!bedsVentNotify)

now i know this is not a pure blynk issue, but can someone give me a tip as to why its not working?

here’s a big chunk of the code if you want to see the blynk.notify in context:

void outletComparisonCool()
{ // compares the outlet temps and decides if the inlet air should be sent AND to which rooms
  if (debug)
  {
    Serial.println(F("STARTING cooling outlet selection function "));
    terminal.print(F("**"));
    terminal.print(currentTime);
    terminal.println(F(": STARTING cooling outlet selection function "));
    terminal.flush();
    Serial.println(F("------------"));
  }
  Blynk.syncVirtual(V26);
  Blynk.syncVirtual(V7);
  Blynk.syncVirtual(V11);
  if ((notBedsOutlet == 0) && (notLivingOutlet == 0) && ((coolestInlet + inletUplift) < medianBed2Temp)  && ((coolestInlet + inletUplift) < medianTempLivingRoom))
  { //AUTO outlet selector is set to 'both' and both rooms warmer than chosen inlet = both could be cooled if the DP is OK
    if (debug)
    {
      Serial.println(F("outletComparisonCool() just run - BOTH rooms selected for cooling"));
      terminal.print(currentTime);
      terminal.println(F(": outletComparisonCool() just run - BOTH rooms selected for cooling."));
      terminal.flush();
      Serial.println(F("------------"));
    }
    if ((medianBed2DewPoint > adjustedInletDewPoint) && (medianDewPointLivingRoom > adjustedInletDewPoint))
    { //both rooms DP OK
      if (debug)
      {
        Serial.println(F("COMBO outletDpComparisonCool() just run - BOTH rooms DP OK"));
        terminal.print(currentTime);
        terminal.println(F(": COMBO outletDpComparisonCool() just run - BOTH rooms DP OK."));
        terminal.flush();
        Serial.println(F("------------"));
      }
      if (((medianTempLivingRoom + outletUplift) > targetTemp) && ((medianBed2Temp + outletUplift) > targetTemp))
      { //both outlet rooms need cooling
        if (BME280Sensor01Temp > (medianBed2Temp + preVentPurgeUplift)) // BME280Sensor01Temp is internal plenum temp, which is nearly ALWAYS quite high after a hot day, so should eb purged before putting it into teh sleeping areas
        {
          if (debug)
          {
            Serial.println(F("preVentPurgeFunction activated, opening living vents!"));
            Serial.println(F("------------"));
            terminal.print(currentTime);
            terminal.print(F("preVentPurgeFunction activated, opening living vents!"));
            terminal.print(F("BME280Sensor01Temp: "));
            terminal.print(BME280Sensor01Temp);
            terminal.print(F(" medianBed2Temp: "));
            terminal.print(medianBed2Temp);
            terminal.print(F(" preVentPurgeUplift: "));
            terminal.println(preVentPurgeUplift);
            terminal.flush();
          }
          if (blynkNotify == 1)
          {
            Blynk.notify(String(currentTime + (" : preVentPurgeFunction run - FAN is ON")));
          }
          preVentPurgeFunction();
        }
        else
        {
          digitalWrite(chosenInletVent, HIGH); //opens chosen inlet vent
          digitalWrite(nonChosenInletVent1, LOW); //closes other inlet vents
          digitalWrite(nonChosenInletVent2, LOW); //closes other inlet vents
          digitalWrite(livingVent, HIGH);
          livingVentOpen = 1;    // used to decide on living room extraction fan operation
          Blynk.virtualWrite(V10, 255); // LVR LED on Blynk app
          digitalWrite(bedroomsVent, HIGH); // open bed rooms vent
          Blynk.virtualWrite(V8, 255); // BED LED on Blynk app
          digitalWrite(upstairsFan, LOW); //remember that LOW means ON for this relay setup
          Blynk.virtualWrite(V28, 255); //fan LED on Blynk app
          Blynk.virtualWrite(V20, 0); //living error LED on Blynk app
          Blynk.virtualWrite(V21, 0); //beds error LED on Blynk app
          Blynk.virtualWrite(V78, LOW); //isCool WARN LED on Blynk app
          if (debug)
          {
            Serial.println(F("outlet to target cool comparison run just run - BOTH rooms need cooling, opening vents!"));
            terminal.print(currentTime);
            terminal.println(F(": outlet to target cool comparison run just run - BOTH rooms need cooling, opening vents!"));
            terminal.flush();
            Serial.println(F("------------"));
          }
          if ((blynkNotify == 1) && (bothVentsNotify < 1))
          {
            Blynk.notify(String(currentTime + (" : outletComparisonCool > both vents selected, FAN is ON")));
            bothVentsNotify = 1;
            livingVentNotify = 0;
            bedsVentNotify = 0;
            nilVentNotify = 0;
          }
          medianTempLivingRoomPrevious = medianTempLivingRoom;
          medianBed2TempPrevious = medianBed2Temp;
          isCoolingCheckLivingTimer = timer.setTimeout(3L * 60000L, isCoolingCheckLiving);
          isCoolingCheckBedsTimer = timer.setTimeout(3L * 60500L, isCoolingCheckBeds);
        }
      }
      else if (((medianTempLivingRoom + outletUplift) > targetTemp) && ((medianBed2Temp + outletUplift) < targetTemp))
      { //only livingroom needs cooling
        digitalWrite(chosenInletVent, HIGH); //opens chosen inlet vent
        digitalWrite(nonChosenInletVent1, LOW); //closes other inlet vents
        digitalWrite(nonChosenInletVent2, LOW); //closes other inlet vents
        digitalWrite(livingVent, HIGH);
        livingVentOpen = 1;    // used to decide on living room extraction fan operation
        Blynk.virtualWrite(V10, 255); // LVR LED on Blynk app
        digitalWrite(bedroomsVent, LOW); // open bed rooms vent
        Blynk.virtualWrite(V8, 0); // BED LED on Blynk app
        digitalWrite(upstairsFan, LOW); //remember that LOW means ON for this relay setup
        Blynk.virtualWrite(V28, 255); //fan LED on Blynk app
        Blynk.virtualWrite(V20, 0); //living error LED on Blynk app
        Blynk.virtualWrite(V21, 255); //beds error LED on Blynk app
        Blynk.virtualWrite(V78, LOW); //isCool WARN LED on Blynk app
        if (debug)
        {
          Serial.println(F("outlet to target cool comparison run just run - only LIVING room needs cooling"));
          terminal.print(currentTime);
          terminal.println(F(": outlet to target cool comparison run just run - only LIVING room needs cooling, opening vent!"));
          terminal.flush();
          Serial.println(F("------------"));
        }
        if ((blynkNotify == 1) && (livingVentNotify < 1))
        {
          Blynk.notify(String(currentTime + (" : outletComparisonCool > living vent selected, FAN is ON")));
          bothVentsNotify = 0;
          livingVentNotify = 1;
          bedsVentNotify = 0;
          nilVentNotify = 0;
        }
        medianTempLivingRoomPrevious = medianTempLivingRoom;
        isCoolingCheckLivingTimer = timer.setTimeout(3L * 60000L, isCoolingCheckLiving);
      }
      else if (((medianTempLivingRoom + outletUplift) < targetTemp) && ((medianBed2Temp + outletUplift) > targetTemp))
      { //only bed rooms need cooling
        if (BME280Sensor01Temp > (medianBed2Temp + preVentPurgeUplift)) // BME280Sensor01Temp is internal plenum temp, which is nearly ALWAYS quite high after a hot day, so should eb purged before putting it into teh sleeping areas
        {
          if (debug)
          {
            Serial.println(F("preVentPurgeFunction activated, opening living vents!"));
            Serial.println(F("------------"));
            terminal.print(currentTime);
            terminal.print(F("preVentPurgeFunction activated, opening living vents!"));
            terminal.print(F("BME280Sensor01Temp: "));
            terminal.print(BME280Sensor01Temp);
            terminal.print(F(" medianBed2Temp: "));
            terminal.print(medianBed2Temp);
            terminal.print(F(" preVentPurgeUplift: "));
            terminal.println(preVentPurgeUplift);
            terminal.flush();
          }
                    if (blynkNotify == 1)
          {
            Blynk.notify(String(currentTime + (" : preVentPurgeFunction run - FAN is ON")));
          }
          preVentPurgeFunction();
        }
        else
        {
          digitalWrite(chosenInletVent, HIGH); //opens chosen inlet vent
          digitalWrite(nonChosenInletVent1, LOW); //closes other inlet vents
          digitalWrite(nonChosenInletVent2, LOW); //closes other inlet vents
          digitalWrite(livingVent, LOW);
          livingVentOpen = 0;    // used to decide on living room extraction fan operation
          Blynk.virtualWrite(V10, 0); // LVR LED on Blynk app
          digitalWrite(bedroomsVent, HIGH); // open bed rooms vent
          Blynk.virtualWrite(V8, 255); // BED LED on Blynk app
          digitalWrite(upstairsFan, LOW); //remember that LOW means ON for this relay setup
          Blynk.virtualWrite(V28, 255); //fan LED on Blynk app
          Blynk.virtualWrite(V20, 255); //living error LED on Blynk app
          Blynk.virtualWrite(V21, 0); //beds Error LED on Blynk app
          Blynk.virtualWrite(V78, LOW); //isCool WARN LED on Blynk app
          if (debug)
          {
            Serial.println(F("outlet to target cool comparison run just run - only BEDS rooms need cooling, opening vent!"));
            terminal.print(currentTime);
            terminal.println(F(": outlet to target cool comparison run just run - only BEDS rooms need cooling, opening vent!"));
            terminal.flush();
            Serial.println(F("------------"));
          }
          if ((blynkNotify == 1) && (bedsVentNotify < 1))
          {
            Blynk.notify(String((currentTime) + (" : outletComparisonCool > beds vent selected, FAN is ON")));
            bothVentsNotify = 0;
            livingVentNotify = 0;
            bedsVentNotify = 1;
            nilVentNotify = 0;
          }
          medianBed2TempPrevious = medianBed2Temp;
          isCoolingCheckBedsTimer = timer.setTimeout(3L * 60500L, isCoolingCheckBeds);
        }
      }
      else if (((medianTempLivingRoom + outletUplift) < targetTemp) && ((medianBed2Temp + outletUplift) < targetTemp))
      { //neither rooms need cooling
        digitalWrite(livingVent, LOW);
        livingVentOpen = 0;    // used to decide on living room extraction fan operation
        Blynk.virtualWrite(V10, 0); // LVR LED on Blynk app
        digitalWrite(bedroomsVent, LOW); // open bed rooms vent
        Blynk.virtualWrite(V8, 0); // BED LED on Blynk app
        digitalWrite(upstairsFan, HIGH); //remember that LOW means ON for this relay setup
        Blynk.virtualWrite(V28, 0); //fan LED on Blynk app
        Blynk.virtualWrite(V20, 255); //living error LED on Blynk app
        Blynk.virtualWrite(V21, 255); //beds error LED on Blynk app
        digitalWrite(roofVent, LOW);
        Blynk.virtualWrite(V5, 0); //rof LED on Blynk app
        digitalWrite(houseVent, LOW);
        Blynk.virtualWrite(V4, 0); //hse LED on Blynk app
        digitalWrite(externVent, LOW);
        Blynk.virtualWrite(V6, 0); //ext LED on Blynk app
        Blynk.virtualWrite(V27, 255); //nil LED on Blynk app
        Blynk.virtualWrite(V78, LOW); //isCool WARN LED on Blynk app
        if (debug)
        {
          Serial.println(F("outlet to target cool comparison run just run - NEITHER rooms need cooling! shut all vents."));
          terminal.print(currentTime);
          terminal.println(F(": outlet to target cool comparison run just run - NEITHER rooms need cooling, shut all vents!"));
          terminal.flush();
          Serial.println(F("------------"));
        }
        if ((blynkNotify == 1) && (nilVentNotify < 1))
        {
          Blynk.notify(String((currentTime) + (" : outletComparisonCool > nil vent selected, FAN is OFF")));
          bothVentsNotify = 0;
          livingVentNotify = 0;
          bedsVentNotify = 0;
          nilVentNotify = 1;
        }
      }
    }
    else if ((medianBed2DewPoint > adjustedInletDewPoint) && (medianDewPointLivingRoom < adjustedInletDewPoint))
    { //only BED rooms DP OK
      if (debug)
      {
        Serial.println(F("COMBO outletDpComparisonCool just run - only BED rooms DP OK"));
        terminal.print(currentTime);
        terminal.println(F(": COMBO outletDpComparisonCool just run - only BED rooms DP OK"));
        terminal.flush();
        Serial.println(F("------------"));
      }
      if (((medianBed2Temp + outletUplift) > targetTemp))
      { //bed rooms needs cooling
        if (BME280Sensor01Temp > (medianBed2Temp + preVentPurgeUplift)) // BME280Sensor01Temp is internal plenum temp, which is nearly ALWAYS quite high after a hot day, so should eb purged before putting it into teh sleeping areas
        {
          if (debug)
          {
            Serial.println(F("preVentPurgeFunction activated, opening living vents!"));
            Serial.println(F("------------"));
            terminal.print(currentTime);
            terminal.print(F("preVentPurgeFunction activated, opening living vents!"));
            terminal.print(F("BME280Sensor01Temp: "));
            terminal.print(BME280Sensor01Temp);
            terminal.print(F(" & medianBed2Temp: "));
            terminal.print(medianBed2Temp);
            terminal.print(F(" & preVentPurgeUplift: "));
            terminal.println(preVentPurgeUplift);
            terminal.flush();
          }
                    if (blynkNotify == 1)
          {
            Blynk.notify(String(currentTime + (" : preVentPurgeFunction run - FAN is ON")));
          }
          preVentPurgeFunction();
        }
        else
        {
          digitalWrite(chosenInletVent, HIGH); //opens chosen inlet vent
          digitalWrite(nonChosenInletVent1, LOW); //closes other inlet vents
          digitalWrite(nonChosenInletVent2, LOW); //closes other inlet vents
          digitalWrite(livingVent, LOW);
          livingVentOpen = 0;    // used to decide on living room extraction fan operation
          Blynk.virtualWrite(V10, 0); // LVR LED on Blynk app
          digitalWrite(bedroomsVent, HIGH); // open bed rooms vent
          Blynk.virtualWrite(V8, 255); // BED LED on Blynk app
          digitalWrite(upstairsFan, LOW); //remember that LOW means ON for this relay setup
          Blynk.virtualWrite(V28, 255); //fan LED on Blynk app
          Blynk.virtualWrite(V20, 255); //living error LED on Blynk app
          Blynk.virtualWrite(V21, 0); //beds error LED on Blynk app
          Blynk.virtualWrite(V78, LOW); //isCool WARN LED on Blynk app
          if (debug)
          {
            Serial.println(F("BEDS ONLY 'outlet to target' cool comparison run just run -  BEDS rooms need cooling, opening vent!"));
            terminal.print(currentTime);
            terminal.println(F(": BEDS ONLY 'outlet to target' cool comparison run just run -  BEDS rooms need cooling, opening vent!"));
            terminal.flush();
            Serial.println(F("------------"));
          }
          if ((blynkNotify == 1) && (bedsVentNotify < 1))
          {
            Blynk.notify(String((currentTime) + (" : outletComparisonCool > beds vent selected, FAN is ON")));
            bothVentsNotify = 0;
            livingVentNotify = 0;
            bedsVentNotify = 1;
            nilVentNotify = 0;
          }
          medianBed2TempPrevious = medianBed2Temp;
          isCoolingCheckBedsTimer = timer.setTimeout(3L * 60500L, isCoolingCheckBeds);
        }
      }
      else if (((medianBed2Temp + outletUplift) < targetTemp))
      { //bed rooms dont need cooling
        digitalWrite(livingVent, LOW);
        livingVentOpen = 0;    // used to decide on living room extraction fan operation
        Blynk.virtualWrite(V10, 0); // LVR LED on Blynk app
        digitalWrite(bedroomsVent, LOW); // open bed rooms vent
        Blynk.virtualWrite(V8, 0); // BED LED on Blynk app
        digitalWrite(upstairsFan, HIGH); //remember that LOW means ON for this relay setup
        Blynk.virtualWrite(V28, 0); //fan LED on Blynk app
        Blynk.virtualWrite(V20, 255); //living error LED on Blynk app
        Blynk.virtualWrite(V21, 255); //beds error LED on Blynk app
        digitalWrite(roofVent, LOW);
        Blynk.virtualWrite(V5, 0); //rof LED on Blynk app
        digitalWrite(houseVent, LOW);
        Blynk.virtualWrite(V4, 0); //hse LED on Blynk app
        digitalWrite(externVent, LOW);
        Blynk.virtualWrite(V6, 0); //ext LED on Blynk app
        Blynk.virtualWrite(V27, 255); //nil LED on Blynk app
        Blynk.virtualWrite(V78, LOW); //isCool WARN LED on Blynk app
      }
      if (debug)
      {
        Serial.println(F("BEDS ONLY 'outlet to target' cool comparison run just run -  BEDS rooms do NOT need cooling! shut all vents"));
        terminal.print(currentTime);
        terminal.println(F(": BEDS ONLY 'outlet to target' cool comparison run just run -  BEDS rooms do NOT need cooling, shut all vents!"));
        terminal.flush();
        Serial.println(F("------------"));
      }
      if ((blynkNotify == 1) && (nilVentNotify < 1))
      {
        Blynk.notify(String((currentTime) + (" : outletComparisonCool > nil vents selected, FAN is OFF")));
        bothVentsNotify = 0;
        livingVentNotify = 0;
        bedsVentNotify = 0;
        nilVentNotify = 1;
      }
    }

following loops in my code drives me loopy, let alone others code :crazy_face:

But if I follow correctly, and assuming…

bedsVentNotify = 0 // means NOT notified

bedsVentNotify = 1 // means notified ALREADY

The you want to start of your init with…

int bedsVentNotify = 0;

…and your check to be…

if ((blynkNotify == 1) && (bedsVentNotify == 0))

Then after said notification, set the flag to 1 and a timeout timer for x amount of time before resetting the flag back to 0.

// Check condition and notification flag
  // if conditions are correct
  bedsVentNotify = 1;
  // Timed Lambda Function
    timer.setTimeout(16000L, []() {  // Timeoute delay for 16 seconds - adjust as required
    bedsVentNotify = 0;  // Then reset notification flag
    });  // END Timer Function
  // do notification and stuff
// End condition loop

@Gunner I don’t think @Dave1829 wants a timer to re-trigger the notification, he wants some system condition. His code is bit too messy for me to look at :slight_smile:

2 Likes

How/where is your bedsVentNotify variable being initialised?

Pete.

1 Like

I just included the re-trigger option as that is generally a wanted thing… but yes, otherwise hard to tell if it was meant to be a one shot notification or not.

@Dave1829 If was only a one-shot notification, then simply remove the reset timer function.

I also recommend clearly labeling any flags as such… e.g bedsVentNotifyFLAG… easier to visually track.

I think he was mistakenly using the bool instead of the int

@Dave1829 Incidentally, when using bool, I think the state is listed as true or false, not 1 or 0

Technically bool FALSE == 0 but bool TRUE is != 0 (not specifically 1).

I meant that you use the words true/false not the numbers 1/0 when setting and comparing a bool variable in your code, with the exception of the ! in which case you use neither, but just compare the bool variable against itself.

It’s normal to use true and false but “numbers” are fine, see https://www.le.ac.uk/users/rjm1/cotter/page_37.htm

Or specifically the number zero is fine, forget about any other numbers.

Tested and TRUE :stuck_out_tongue_winking_eye:

I think it is described as such (in the Arduino programming world) for distinction between a bool value and a pin state… you know, for us neophyte types :slight_smile:

1 Like

OK, thanks!

That’s what I thought…

There must be another reason the controller thinks bedsnotify is seemingly always zero or FALSE

I’ll set up some serial debugging…

I haven’t given an initial state, so will try this but once it gets defined in the code it should stay 1 or 0… At least that’s how all my other variables seem to work?

Awww crap!

Maybe it isn’t?

But how does it compile?

Maybe I did a bad cut /paste in my OP and left out the bedsnotify integer?

But if it’s not there it explains everything! Doh!

The variable must be declared somewhere, otherwise it wouldn’t compile. Just interested what variable type it is and whether it’s being declared/redeclared as a local variable in multiple places, or whether it’s a global variable.

Pete.

yep, it should be there globally as an int

(they were all bool when i started, but i changed to int as i was unsure of the syntax but @Gunner & paul have helped on that issue - i will be reverting the notifyFLAGs to bool when i get back to my code…)

but i will find out what/where it is in a few hours when i get home tonight…

1 Like

well well well @costas has done it again…

// huh? “I’ll show him!”

// removes all of the crud&crap™ from mycode®,

// finds missing curly brace!!!

thanks!!

2 Likes