BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

The push notification keeps getting issued repeatedly

Hello

I want the notification to be appeared only when the value in the relay status changes, but in my code below the notification always spamming, i’ve tried solving with other topic code but still get stuck, help me please…

i used
esp8266
dht11
relay 2ch

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <UniversalTelegramBot.h>
#include "DHT.h"
#include "CTBot.h"
#define DHTPIN 2     // Digital pin connected to the DHT sensor

// Uncomment whatever type you're using!
#define DHTTYPE DHT11   // DHT 11
//#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)
#define FAN_PIN 4   // FAN RELAY
#define PUMP_PIN 5   // POMPA RELAY
WidgetLED FAN(V5);
WidgetLED PUMP(V6);

CTBot myBot;
String token = "2080144648:AAFBnMJUxdtCZjbiuO5ZwzqLxZ4Xdh445L0";
//const int id = *****;
char auth[] = "XAE0-62HjrvCDL3nVASDBKes3X2z7yr_";
char ssid[] = "minions";
char pass[] = "haniya12";


float humDHT = 0;
float tempDHT = 0;
int Kipas = 0;
int Pompa = 0;
bool kipasNotifyFLAG, pompaNotifyFLAG;

void resetkipasNotifyFLAG() 
{
  kipasNotifyFLAG = 0;
}


// Initialize DHT sensor.
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;



void setup() {
  Serial.begin(9600);
  pinMode(FAN_PIN, OUTPUT);
  digitalWrite(FAN_PIN, LOW);
  pinMode(PUMP_PIN, OUTPUT);
  digitalWrite(PUMP_PIN, LOW);
  Serial.println(F("DHTxx test!"));
  dht.begin();
  Blynk.begin( auth, ssid , pass );
  myBot.wifiConnect(ssid, pass);
  myBot.setTelegramToken(token);
}

BLYNK_WRITE(V3)
{
  Kipas = param.asInt();                        // assigning incoming value from pin V3 to a variable

  Serial.print(" The Threshhold value is: ");
  Serial.println(Kipas);
  Serial.println();

}

BLYNK_WRITE(V4)
{
  Pompa = param.asInt();                        // assigning incoming value from pin V3 to a variable

  Serial.print(" The Threshhold value is: ");
  Serial.println(Pompa);
  Serial.println();
}

void loop() {

  Blynk.run();


  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  humDHT = dht.readHumidity();
  // Read temperature as Celsius (the default)
  tempDHT = dht.readTemperature();

  // Check if any reads failed and exit early (to try again).
  if (isnan(humDHT) || isnan(tempDHT))
  {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  Serial.print(F("Temperature: "));
  Serial.print(tempDHT);
  Serial.print(F("°C "));
  Serial.println();
  Serial.print(F("Humidity: "));
  Serial.print(humDHT);
  Serial.print(F("%"));
  Serial.println();

  Serial.println("***********************");
  Serial.println();

    
    if (Kipas >= tempDHT && !kipasNotifyFLAG )       // Compare Threshold value from Blynk and DHT Temperature value.
  {
    kipasNotifyFLAG = 1;
    timer.setTimeout(2000L, resetkipasNotifyFLAG);
    digitalWrite(FAN_PIN, HIGH);
    Blynk.notify ("KIPAS MATI");
    FAN.off();
  }

  else
  {
    kipasNotifyFLAG = 0;
    timer.setTimeout(2000L, resetkipasNotifyFLAG);
    digitalWrite(FAN_PIN, LOW);
    Blynk.notify ("KIPAS NYALA");
    FAN.on();
  }

  if (Pompa <= humDHT)
  {
    digitalWrite(PUMP_PIN, HIGH);
    PUMP.off();
  }
  else
  {
    digitalWrite(PUMP_PIN, LOW);
    PUMP.on();
  }


  Blynk.virtualWrite(V1, tempDHT);
  Blynk.virtualWrite(V2, humDHT);
}

You should start by reading this:

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

You need to move most of your code out of the void loop and into a function that’s called with a timer, and remove the delay.

You are currently using a timeout timer, and I really cant see what it’s intended purpose is, but you aren’t servicing your timer object with a timer.run() command in the void loop.

Pete.