Sending a lot of SMS alert and email


#1

Hello,

I hope I’m in the right place for my question,

I created a project and alerts, the problem is that several tens of sms are sent per second until the state has changed.

The number of sms create problems with my wives, lol.

can we manage the number of sending of notification?

Thank you for your really great application!


Controlling "off the shelf" Smart sockets
Trigger issues - multiple alerts and no hystersis
#2

this is known bug and team is working on solving it. till then I can provide a workaround, so can you post the code you are using.


#3

Ok thanks for the return

Here are:

I am not professional the code may not be the best :wink:

//#define CAYENNE_DEBUG       // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "blabla";
char password[] = "blabla";
char clientID[] = "blabla";

#include <Stepper.h>
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);
#define VIRTUAL_CHANNELA 2
int  Steps2Take = 0;

int HumiditeTerre;
#define CapteurTerre 0
#define VIRTUAL_CHANNEL 1

void setup() {
  Serial.begin(9600);
  Cayenne.begin(username, password, clientID);
  myStepper.setSpeed(60);
  pinMode(CapteurTerre, INPUT);
  
}

void loop() {
  Cayenne.loop();
  int HumiditeTerre = analogRead(CapteurTerre);
  Serial.print("HumiditeTerre : ");
  Serial.println(HumiditeTerre);
  Cayenne.virtualWrite(1, HumiditeTerre, "soil_moist", "p");
  Steps2Take  = 1024;
 
}
CAYENNE_IN(VIRTUAL_CHANNELA)
{

    myStepper.step(Steps2Take);

}

#4

changed the main part of the code to avoid trigger flooding, but you need to set the trigger value of the humidity in the code.

int y;
int x;
int a;

int trigger = ;// you need to set this value
unsigned long lastMillis = 0;

void loop() {
  Cayenne.loop();
  int HumiditeTerre = analogRead(CapteurTerre);
  Serial.print("HumiditeTerre : ");
  Serial.println(HumiditeTerre);
  send_data();
  trigger();
}
void send_data()
{
  if (HumiditeTerre > trigger)
  {
    a = 1;
    if (millis() - lastMillis > 10000) {
      lastMillis = millis();
      Cayenne.virtualWrite(1, HumiditeTerre, "soil_moist", "p");
    }
  }
}
void trigger()
{
  if (HumiditeTerre <= trigger)
  {
    if (millis() - lastMillis > 10000)
    {
      lastMillis = millis();
      Cayenne.virtualWrite(1, HumiditeTerre, "soil_moist", "p");
    }
    if ( a == 1)
    {
      Serial.println("Sending trigger");
      Cayenne.virtualWrite(3, HumiditeTerre, "soil_moist", "p");
      a = 0;
    }
  }
} 

Upload this code and set a trigger for channel 3.


Crazy notifications
Trigger settings don't save
#5

The code is clever and solves the problem
thank you,
:+1:


#6

Hi Thanks for pointing me to this from my question. This looks something similar to what i was doing with blynk, i.e setting flags and so i understand how something like this works from a code level. However don’t completely understand how this code actually activates a trigger. As far as i can tell if the codes trigger value is true then it VirtualWrites to channel 3? but that seems to be another sensor value? Would this code work if you did a virtualWrite to a custom widget that would just ‘show its on/off state’ thereby sending 1 notification?
thanks for your time


#7

yes that can work too. give it a try and let me know.


#8

ok. and what about my questions regarding your code? ‘’ However don’t completely understand how this code actually activates a trigger. As far as i can tell if the codes trigger value is true then it VirtualWrites to channel 3? but that seems to be another sensor value? ‘’

sorry just trying to understand why your doing it that way. Im new to coding…


#9

you have to set the trigger value. eg if humidity is less than 35;

int trigger 35= ;// you need to set this value

I have two functions which are called from the main loop.

send_data();
 trigger();

this function sends data to channel 2 if humidity is greater than the trigger and set a = 1;

void send_data()  
{
  if (HumiditeTerre > trigger)
  {
    a = 1;
    if (millis() - lastMillis > 10000) {
      lastMillis = millis();
      Cayenne.virtualWrite(1, HumiditeTerre, "soil_moist", "p");
    }
  }
}

this function sends data to channel 2 when humidity is less than the trigger and also send data to channel 3 and sets a =0. so till humidity does not rise higher than the trigger, it won’t send data to channel 3.

void trigger()
{
  if (HumiditeTerre <= trigger)
  {
    if (millis() - lastMillis > 10000)
    {
      lastMillis = millis();
      Cayenne.virtualWrite(1, HumiditeTerre, "soil_moist", "p");
    }
    if ( a == 1)
    {
      Serial.println("Sending trigger");
      Cayenne.virtualWrite(3, HumiditeTerre, "soil_moist", "p");
      a = 0;
    }
  }
} 

Now that you have sent data to channel 3 only once, you set a trigger on the cayenne dashboard to channel 3. this will avoid the trigger flooding issue.
this is the best i can explain the code working , i hope it helps you out. revert back if any problem.