Can't get timer.setTimeout() to work

Hi, I am currently implementing a simple logic module where an imaginary electric iron will be turned off in 3 seconds under two different conditions (when it’s flat and it’s on [tracker =2]).

I have referred to many of the solved solutions but couldn’t make it work still… Any help would be much appreciated!

void TimerEvent()
{
// other code above....
else if (tracker == 2){
    Blynk.logEvent("electric_iron", "Iron flat and ON! Turning off in 3 seconds...");
    Serial.println("Iron on, 3 seconds off");
    Blynk.virtualWrite(V0, 1);
    digitalWrite(IRON_LED, HIGH);

   /// this is the part that is making my device disconnect......
       timer.setTimeout(3000L, []()
       {
    //   When timer completes, turn off everything
       Blynk.logEvent("electric_iron", "Iron turned off after 3 seconds...");
       Blynk.virtualWrite(V0, 0);
       digitalWrite(IRON_LED, LOW);
       Serial.println("Iron turned off after 3 seconds...");
     });
    }
}

Here’s the full code for your reference…

// ** ----------------   Constants   --------------- **
#define IRON_LED 13
#define IRON_POWER 5
#define VIBRATIONS 6
#define IS_FLAT 7

// ** ---------------- Blynk Constants and libraries -------------- **
#define BLYNK_TEMPLATE_ID "TMPL6o_AtNPvi"
#define BLYNK_TEMPLATE_NAME "Electric Iron Notifications"
#define BLYNK_AUTH_TOKEN "s5mJlSMgMTcEgZJaaGbGg_u8DUMasUyI"
#define BLYNK_PRINT Serial
#define ESP8266_BAUD 9600

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(8, 9); // RX, TX
ESP8266 wifi(&EspSerial);
BlynkTimer timer;

// ** ----------------- Blynk token and wifi credentials ------------- **
char auth[] = "my_token";
char ssid[] = "my_ssid";
char pass[] = "my_pass";

// Timer constants
const unsigned long TIMER_DURATION_FLAT = 3000; // 3000 milliseconds = 3 seconds
const unsigned long TIMER_DURATION_STAND = 6000; // 60000 milliseconds = 60 seconds

// ** ----------------   Variables   --------------- **
int IRON_POW = 0;
int VIBR = 0;
int FLAT = 0;
int tracker = 0;
unsigned long previousMillis = 0;
bool isFlat = false;
unsigned long flatStartTime = 0;

// Serial monitor output flag
bool stateChanged = false;

// Serial monitor constants for previous states
int prev_1 = 0;
int prev_2 = 0;
int prev_3 = 0;

// ** ----------------   END   --------------- **


int IronState()
{
    //pinMode(IRON_LED, OUTPUT);
  pinMode(IRON_POWER, INPUT_PULLUP);
  pinMode(VIBRATIONS, INPUT_PULLUP);
  pinMode(IS_FLAT, INPUT_PULLUP);

  // Read state of rocker switch
  IRON_POW = digitalRead(IRON_POWER);
  VIBR = digitalRead(VIBRATIONS);
  FLAT = digitalRead(IS_FLAT);

  if (IRON_POW == HIGH) {
    tracker = 0; 
  }
  // * ----------------- IRON is ON, CONDITIONS -------------- *
  else{
    // * --------------------- USER USING IT ------------------ *
    if (IRON_POW == LOW && VIBR == LOW && FLAT == LOW){
      tracker = 1;
    }
    // * -----------------------IRON is ON, NOT Using It, It's Flat ------------ *
    else if ((IRON_POW == LOW && VIBR == HIGH && FLAT == LOW) && (prev_1 == LOW && prev_2 == LOW && prev_3 == LOW)){
      tracker = 2;
    }
    // * ----------------- IRON is ON, NOT Using It, It's Standing ------------- *
    else if ((IRON_POW == LOW && FLAT == HIGH) && (prev_1 == LOW && prev_2 == LOW && prev_3 == LOW)){
      tracker = 3;
    }
  }
  return tracker;
}


// ** ---------- New Function for TimerEvent (Notifications) ------------ **
void TimerEvent()
{
  //Every second I will read the LED output state, if it's 
  tracker = IronState();

  if (tracker == 0){
    Blynk.logEvent("electric_iron", "Iron is OFF");
    Serial.println("Iron is OFF.");
    Blynk.virtualWrite(V0, 0);
    digitalWrite(IRON_LED, LOW);
  }
  else if (tracker == 1){
    Blynk.logEvent("electric_iron", "Someone's using the Iron...");
    Serial.println("Iron is ON.");
    Blynk.virtualWrite(V0, 1);
    digitalWrite(IRON_LED, HIGH);
  }
  else if (tracker == 2){
    Blynk.logEvent("electric_iron", "Iron flat and ON! Turning off in 3 seconds...");
    Serial.println("Iron on, 3 seconds off");
    Blynk.virtualWrite(V0, 1);
    digitalWrite(IRON_LED, HIGH);
    timer.setTimeout(3000L, []()
    {
      // When timer completes, turn off everything
      Blynk.logEvent("electric_iron", "Iron turned off after 3 seconds...");
      Blynk.virtualWrite(V0, 0);
      digitalWrite(IRON_LED, LOW);
      Serial.println("Iron turned off after 3 seconds...");
    });
    }
  }
  else if (tracker == 3){
    Blynk.logEvent("electric_iron", "Iron idle and ON! Turning off in 6 seconds...");
  }

}

void setup() {
  // put your setup code here, to run once:
  pinMode(IRON_LED, OUTPUT);
  pinMode(IRON_POWER, INPUT_PULLUP);
  pinMode(VIBRATIONS, INPUT_PULLUP);
  pinMode(IS_FLAT, INPUT_PULLUP);
  Serial.begin(9600);

  // Setting ESP8266 Baud Rate
  EspSerial.begin(ESP8266_BAUD);
  //delay(10);
  Blynk.begin(BLYNK_AUTH_TOKEN, wifi, ssid, pass); 

  // Calling every second 
  timer.setInterval(5000L, TimerEvent);
}

void loop() {

  // Run Blynk
  Blynk.run();
  timer.run();

} // void loop end


Your topic title says “Can’t get timer.setTimer() to work” which makes no sense as you aren’t using timer.setTimer() in the code you’ve posted.

Your use of Blynk.logEvent is going to cause you an issue. You are limited to logging 100 events per 24 hour period. Your code will log at least 1 event every 5 seconds, so you’ll run out of events after 500 seconds, or just over 8 minutes of code execution.

Pete.

Sorry for the confusion caused, I accidentally included a different version… I have edited the code above to the one that’s giving me the problem.

As for Blynk.logEvent(), should I be using Blynk.notify instead?

I’m still confused.
Your comments in the edited fiorts post now refer to an issue with timer.setTimeout(), which still isn’t the same as the timer.setTimer() command in your topic title…

If it’s actually timer.setTimeout() that you’re having a problem with, and it’s causing your device to reboot, then posting your serial output (as text, with triple backticks, not a screenshot) would be useful.

No, Blynk.notify() is a Legacy command and doesn’t work with Blynk IoT.
With Blynk IoT you are limited to 100 events per 24 hours and 100 notifications per 24 hours. Notifications are also limited to one per minute, so if you send 100 events in 8 minutes you will reach your notification limit, but will have received just 8 notifications. Even though you have 92 notifications left these cannot be utilised because the events that trigger the events have been used-up.

The bottom line is that you are utilising events and their associated notifications inappropriately. Notifications should be used to notify users of extraordinary situations, alerting them that they should open the Blynk app and take appropriate action.

Pete.

Hi Pete, here’s the Serial Output.

[636] Connecting to Don
[13714] AT version:2.2.0.0(b097cdf - ESP8266 - Jun 17 2021 12:57:45)
SDK version:v3.4-22-g967752e2
compile time(6800286):Aug  4 2021 17:34:06
Bin version:2.2.0(Cytron_ESP-12F_WROO-2

K

[14960] +CIFSR:STAIP,"192.168.196.151"
+CIFSR:STAMAC,"bc:ff:4d:d3:88:34"
[14971] Connected to WiFi
[26076] Ready (ping: 287ms).
[57420] Ready (ping: 289ms).
[88559] Ready (ping: 82ms).
[119698] Ready (ping: 83ms).
[150839] Ready (ping: 81ms).
[181976] Ready (ping: 83ms).
[213319] Ready (ping: 289ms).
[247328] Ready (ping: 84ms).
[282360] Ready (ping: 3159ms).
[313288] Ready (ping: 84ms).
[344594] Ready (ping: 45ms).

May I know what should I use instead of Blynk.logEvent() for this case? I only want to send an alert to the user whenever there’s a change in state of the “electric iron”, to notify the user about the state of the “electric iron”.

I don’t think that is an appropriate use for alerts, but I guess it depends on how often these changes in state will occur disputing the day.
If it’s more than just a small number (less than 10 maybe) then it could work, but beyond that the user will get “notification fatigue” and either ignore or silence the alerts, as they aren’t helpful.

A better approach would be to to show the current state in the app (which it seems you are doing) and alert the user to critical situations- such as the device being left on for extended periods, or outside of certain hours.

Pete.

Understood, I will try that out thank you.

By the way, as for the timer.setTimeout(), is there a way I can overcome this issue?

Your serial monitor output doesn’t show any of your Serial.print messages, and you’ve only updated your code snippet rather than providing the full code that you’re using, so it’s difficult to understand exactly what’s happening with your device.

How are you determining that it’s the timeout timer that’s causing your disconnections?

Pete.

I am currently testing it with rocker switches that are connected to the Arduino. The serial monitor will proceed to print out the messages associated with the state of the switches. However, when these lines of code (below) is implemented, none of the text will get printed out no matter how I flip the switches…

timer.setTimeout(3000L, []()
    {
      // When timer completes, turn off everything
      Blynk.logEvent("electric_iron", "Iron turned off after 3 seconds...");
      Blynk.virtualWrite(V0, 0);
      digitalWrite(IRON_LED, LOW);
      Serial.println("Iron turned off after 3 seconds...");
    });

And when I remove them, it does not have the issue of connecting and disconnecting, with the output getting printed on the serial monitor (as shown below) whenever I flip the switches…

[636] Connecting to Cheese Cake
[13716] AT version:2.2.0.0(b097cdf - ESP8266 - Jun 17 2021 12:57:45)
SDK version:v3.4-22-g967752e2
compile time(6800286):Aug  4 2021 17:34:06
Bin version:2.2.0(Cytron_ESP-12F_WROO0)

K

[15563] +CIFSR:STAIP,"192.168.68.113"
+CIFSR:STAMAC,"bc:ff:4d:d3:88:34"
[15574] Connected to WiFi
[26169] Ready (ping: 187ms).
Iron is OFF.
Iron is ON.
Iron is OFF.
Iron on, 3 seconds off
Iron on, 3 seconds off

When you share the full sketch, exactly as it’s uploaded (with the sensitive information redacted), then I’ll take a look at it.

Pete.

Here’s the full code

// ** ----------------   Constants   --------------- **
#define IRON_LED 13
#define IRON_POWER 5
#define VIBRATIONS 6
#define IS_FLAT 7

// ** ---------------- Blynk Constants and libraries -------------- **
#define BLYNK_TEMPLATE_ID "TMPL6o_AtNPvi"
#define BLYNK_TEMPLATE_NAME "Electric Iron Notifications"
#define BLYNK_AUTH_TOKEN "my_auth"
#define BLYNK_PRINT Serial
#define ESP8266_BAUD 9600

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(8, 9); // RX, TX
ESP8266 wifi(&EspSerial);
BlynkTimer timer;

// ** ----------------- Blynk token and wifi credentials ------------- **
char auth[] = "my_auth";
char ssid[] = "my_ssid";
char pass[] = "my_pass";

// Timer constants
const unsigned long TIMER_DURATION_FLAT = 3000; // 3000 milliseconds = 3 seconds
const unsigned long TIMER_DURATION_STAND = 6000; // 60000 milliseconds = 60 seconds

// ** ----------------   Variables   --------------- **
int IRON_POW = 0;
int VIBR = 0;
int FLAT = 0;
int tracker = 0;
unsigned long previousMillis = 0;
bool isFlat = false;
unsigned long flatStartTime = 0;

// Serial monitor output flag
bool stateChanged = false;

// Serial monitor constants for previous states
int prev_1 = 0;
int prev_2 = 0;
int prev_3 = 0;

// ** ----------------   END   --------------- **


int IronState()
{
    //pinMode(IRON_LED, OUTPUT);
  pinMode(IRON_POWER, INPUT_PULLUP);
  pinMode(VIBRATIONS, INPUT_PULLUP);
  pinMode(IS_FLAT, INPUT_PULLUP);

  // Read state of rocker switch
  IRON_POW = digitalRead(IRON_POWER);
  VIBR = digitalRead(VIBRATIONS);
  FLAT = digitalRead(IS_FLAT);

  if (IRON_POW == HIGH) {
    tracker = 0; 
  }
  // * ----------------- IRON is ON, CONDITIONS -------------- *
  else{
    // * --------------------- USER USING IT ------------------ *
    if (IRON_POW == LOW && VIBR == LOW && FLAT == LOW){
      tracker = 1;
    }
    // * -----------------------IRON is ON, NOT Using It, It's Flat ------------ *
    else if ((IRON_POW == LOW && VIBR == HIGH && FLAT == LOW) && (prev_1 == LOW && prev_2 == LOW && prev_3 == LOW)){
      tracker = 2;
    }
    // * ----------------- IRON is ON, NOT Using It, It's Standing ------------- *
    else if ((IRON_POW == LOW && FLAT == HIGH) && (prev_1 == LOW && prev_2 == LOW && prev_3 == LOW)){
      tracker = 3;
    }
  }
  return tracker;
}


// ** ---------- New Function for TimerEvent (Notifications) ------------ **
void TimerEvent()
{
  //Every second I will read the LED output state, if it's 
  tracker = IronState();

  if (tracker == 0){
    Blynk.logEvent("electric_iron", "Iron is OFF");
    Serial.println("Iron is OFF.");
    Blynk.virtualWrite(V0, 0);
    digitalWrite(IRON_LED, LOW);
  }
  else if (tracker == 1){
    Blynk.logEvent("electric_iron", "Someone's using the Iron...");
    Serial.println("Iron is ON.");
    Blynk.virtualWrite(V0, 1);
    digitalWrite(IRON_LED, HIGH);
  }
  else if (tracker == 2){
    Blynk.logEvent("electric_iron", "Iron flat and ON! Turning off in 3 seconds...");
    Serial.println("Iron on, 3 seconds off");
    Blynk.virtualWrite(V0, 1);
    digitalWrite(IRON_LED, HIGH);

    timer.setTimeout(3000L, []()
    {
      // When timer completes, turn off everything
      Blynk.logEvent("electric_iron", "Iron turned off after 3 seconds...");
      Blynk.virtualWrite(V0, 0);
      digitalWrite(IRON_LED, LOW);
      Serial.println("Iron turned off after 3 seconds...");
    });
  }
  else if (tracker == 3){
    Blynk.logEvent("electric_iron", "Iron idle and ON! Turning off in 6 seconds...");
    Serial.println("Iron on, 6 seconds off");
    Blynk.virtualWrite(V0, 1);
    digitalWrite(IRON_LED, HIGH);
    timer.setTimeout(6000L, []()
    {
      // When timer completes, turn off everything
      Blynk.logEvent("electric_iron", "Iron turned off after 6 seconds...");
      Blynk.virtualWrite(V0, 0);
      digitalWrite(IRON_LED, LOW);
      Serial.println("Iron turned off after 6 seconds...");
    });
  }

}

void setup() {
  // put your setup code here, to run once:
  pinMode(IRON_LED, OUTPUT);
  pinMode(IRON_POWER, INPUT_PULLUP);
  pinMode(VIBRATIONS, INPUT_PULLUP);
  pinMode(IS_FLAT, INPUT_PULLUP);
  Serial.begin(9600);

  // Setting ESP8266 Baud Rate
  EspSerial.begin(ESP8266_BAUD);
  //delay(10);
  Blynk.begin(BLYNK_AUTH_TOKEN, wifi, ssid, pass); 

  // Calling every second 
  timer.setInterval(1000L, TimerEvent);
}

void loop() {

  // Run Blynk
  Blynk.run();
  timer.run();

} // void loop end

I can’t get my head around the logic you are using ehre, but there’s certainly an issue with the way that you’re re-initialising the timeout timer each time that TimerEvent() is called and tracker == 2 or tracker == 3

You’re calling TimerEvent() every second, and it’s re-setting the Timeout Timer each time.

Also, you’re only changing the state of IRON_LED and this won’t change the result that is returned when you call IronState(). Shouldn’t you be doing something with IRON_POW instead (or as well)?

Also, you shouldn’t be doing this in IronState()

pinMode commands should be issued once, at startup, not each time you call a function.

Pete.

IRON_POW is the switch that I manually control on the Arduino, and I only want to control IRON_LED (with digitalWrite and virtualWrite)

I am currently trying to maintain a connection to Blynk while implementing a short delay for my LED to remain ON, then OFF after 3 seconds…

May I know if there’s a way I can do this without constantly re-setting the Timeout Timer each time?

In that case, you need to re-write your IronState() to take the IRON_LED status in to account, otherwise TimerEvent() will constantly keep trying to turn the iron off, even when it is already off.

Pete.

I have changed my code and I realized that I am not able to run two different timer.setTimeout() in a single function… (one with 3 seconds timeout and the other with 6 seconds timeout)

  if ((IRON_POW != prev_1) || (VIBR != prev_2) || (FLAT != prev_3)){
    if (!stateChanged){

      stateChanged = true;

      if (IRON_POW == HIGH) {
        // Update on the app
        Blynk.virtualWrite(V0, 0);
        digitalWrite(IRON_LED, LOW);
        Serial.println("Iron is OFF");
      }

      else{
        // Someone using it 
        if (IRON_POW == LOW && VIBR == LOW && FLAT == LOW){
          // Update on the app
          Blynk.virtualWrite(V0, 1);
          digitalWrite(IRON_LED, HIGH);
          Serial.println("Iron is ON");
        }

        // // Flat Iron ON - OFF 3 seconds
        else if ((IRON_POW == LOW && VIBR == HIGH)){
          if (FLAT == LOW){
            // Update on the app
            Blynk.virtualWrite(V0, 1);
            digitalWrite(IRON_LED, HIGH);
            Serial.println("Flat iron is ON");
            timer.setTimeout(3000L, []() {
              digitalWrite(IRON_LED, LOW);
              Serial.println("Flat iron turned OFF automatically after 3 seconds");
              Blynk.virtualWrite(V0, 0);
            });
          }
          else {
            // Update on the app
            Blynk.virtualWrite(V0, 1);
            digitalWrite(IRON_LED, HIGH);
            Serial.println("Standing iron is ON");
            timer.setTimeout(6000L, []() {
              digitalWrite(IRON_LED, LOW);
              Serial.println("Standing iron turned OFF automatically after 6 seconds");
              Blynk.virtualWrite(V0, 0);
            });
          }
        }
      }     
    }
      // Updating the previous state
      prev_1 = IRON_POW;
      prev_2 = VIBR;
      prev_3 = FLAT;
  }
  else{
    stateChanged = false;
  }
}

I tried running it with only the 3 seconds timer.setTimeout() and the code works perfectly…

May I know why does this happen?

Here’s the fully functioning code for your reference :

// ** ---------------- Blynk Constants and libraries -------------- **
#define BLYNK_TEMPLATE_ID "my_id"
#define BLYNK_TEMPLATE_NAME "Electric Iron Notifications"
#define BLYNK_AUTH_TOKEN "my_token"
#define BLYNK_PRINT Serial
#define ESP8266_BAUD 9600
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(8, 9); // RX, TX
ESP8266 wifi(&EspSerial);
BlynkTimer timer;
// ** ----------------- Blynk token and wifi credentials ------------- **
char auth[] = "my_token";
char ssid[] = "my_ssid";
char pass[] = "my_pass";

#define IRON_LED 13
#define IRON_POWER 5
#define VIBRATIONS 6
#define IS_FLAT 7

// ** -------- Define Global Variables here ----- **
bool LED_State = false;
int IRON_POW = 0;
int VIBR = 0;
int FLAT = 0;
int tracker = 0;

// Serial monitor output flag
bool stateChanged = false;

// Serial monitor constants for previous states
int prev_1 = 0;
int prev_2 = 0;
int prev_3 = 0;


BLYNK_WRITE(V0){
  int pinData = param.asInt();
  int ledData = digitalRead(IRON_LED);

  if (pinData == 1){
    digitalWrite(IRON_LED, pinData);
    Serial.println("Iron turned ON remotely.");
    digitalWrite(IRON_LED, HIGH);
  }
  else{
    digitalWrite(IRON_LED, pinData);
    Serial.println("Iron turned OFF remotely.");
    digitalWrite(IRON_LED, LOW);
  }
}


void Indicator(){
  // First read the state of the rocker switches
  IRON_POW = digitalRead(IRON_POWER);
  VIBR = digitalRead(VIBRATIONS);
  FLAT = digitalRead(IS_FLAT);

  // Check for state changes for ON or OFF only! 
  if ((IRON_POW != prev_1) || (VIBR != prev_2) || (FLAT != prev_3)){
    if (!stateChanged){

      stateChanged = true;

      if (IRON_POW == HIGH) {
        // Update on the app
        Blynk.virtualWrite(V0, 0);
        digitalWrite(IRON_LED, LOW);
        Serial.println("Iron is OFF");
      }

      else{
        // Someone using it 
        if (IRON_POW == LOW && VIBR == LOW && FLAT == LOW){
          // Update on the app
          Blynk.virtualWrite(V0, 1);
          digitalWrite(IRON_LED, HIGH);
          Serial.println("Iron is ON");
        }

        // // Flat Iron ON - OFF 3 seconds
        else if ((IRON_POW == LOW && VIBR == HIGH && FLAT == LOW)){
          // Update on the app
          Blynk.virtualWrite(V0, 1);
          digitalWrite(IRON_LED, HIGH);
          Serial.println("Flat iron is ON");
          timer.setTimeout(3000L, []() {
            digitalWrite(IRON_LED, LOW);
            Serial.println("Flat iron turned OFF automatically after 3 seconds");
            Blynk.virtualWrite(V0, 0);
          });
        }
      }     
    }
      // Updating the previous state
      prev_1 = IRON_POW;
      prev_2 = VIBR;
      prev_3 = FLAT;
  }
  else{
    stateChanged = false;
  }
}

void setup() {
  // put your setup code here, to run once:
  pinMode(IRON_LED, OUTPUT);
  pinMode(IRON_POWER, INPUT_PULLUP);
  pinMode(VIBRATIONS, INPUT_PULLUP);
  pinMode(IS_FLAT, INPUT_PULLUP);
  Serial.begin(9600);
  // Setting ESP8266 Baud Rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  Blynk.begin(BLYNK_AUTH_TOKEN, wifi, ssid, pass); 


}

void loop() {
  // put your main code here, to run repeatedly:
  Blynk.run();
  timer.run();

  // Have to keep running the Indicator to check
  Indicator();
}


And here’s the one that’s having issue (two different time.setTimeout())

// ** ---------------- Blynk Constants and libraries -------------- **
#define BLYNK_TEMPLATE_ID "my_id"
#define BLYNK_TEMPLATE_NAME "Electric Iron Notifications"
#define BLYNK_AUTH_TOKEN "my_ssid"
#define BLYNK_PRINT Serial
#define ESP8266_BAUD 9600
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(8, 9); // RX, TX
ESP8266 wifi(&EspSerial);
BlynkTimer timer;
// ** ----------------- Blynk token and wifi credentials ------------- **
char auth[] = "my_token";
char ssid[] = "my_ssid";
char pass[] = "my_pass";

#define IRON_LED 13
#define IRON_POWER 5
#define VIBRATIONS 6
#define IS_FLAT 7

// ** -------- Define Global Variables here ----- **
bool LED_State = false;
int IRON_POW = 0;
int VIBR = 0;
int FLAT = 0;
int tracker = 0;

// Serial monitor output flag
bool stateChanged = false;

// Serial monitor constants for previous states
int prev_1 = 0;
int prev_2 = 0;
int prev_3 = 0;


BLYNK_WRITE(V0){
  int pinData = param.asInt();
  int ledData = digitalRead(IRON_LED);

  if (pinData == 1){
    digitalWrite(IRON_LED, pinData);
    Serial.println("Iron turned ON remotely.");
    digitalWrite(IRON_LED, HIGH);

  }
  else{
    digitalWrite(IRON_LED, pinData);
    Serial.println("Iron turned OFF remotely.");
    digitalWrite(IRON_LED, LOW);
  }
}


void Indicator(){
  // First read the state of the rocker switches
  IRON_POW = digitalRead(IRON_POWER);
  VIBR = digitalRead(VIBRATIONS);
  FLAT = digitalRead(IS_FLAT);

  // Check for state changes for ON or OFF only! 
  if ((IRON_POW != prev_1) || (VIBR != prev_2) || (FLAT != prev_3)){
    if (!stateChanged){

      stateChanged = true;

      if (IRON_POW == HIGH) {
        // Update on the app
        Blynk.virtualWrite(V0, 0);
        digitalWrite(IRON_LED, LOW);
        Serial.println("Iron is OFF");
      }

      else{
        // Someone using it 
        if (IRON_POW == LOW && VIBR == LOW && FLAT == LOW){
          // Update on the app
          Blynk.virtualWrite(V0, 1);
          digitalWrite(IRON_LED, HIGH);
          Serial.println("Iron is ON");
        }

        // Flat Iron ON - OFF 3 seconds
        else if ((IRON_POW == LOW && VIBR == HIGH)){
          if (FLAT == LOW){
            // Update on the app
            Blynk.virtualWrite(V0, 1);
            digitalWrite(IRON_LED, HIGH);
            Serial.println("Flat iron is ON");
            timer.setTimeout(3000L, []() {
              digitalWrite(IRON_LED, LOW);
              Serial.println("Flat iron turned OFF automatically after 3 seconds");
              Blynk.virtualWrite(V0, 0);
            });
          }
          else {
            // Update on the app
            Blynk.virtualWrite(V0, 1);
            digitalWrite(IRON_LED, HIGH);
            Serial.println("Standing iron is ON");
            timer.setTimeout(6000L, []() {
              digitalWrite(IRON_LED, LOW);
              Serial.println("Standing iron turned OFF automatically after 6 seconds");
              Blynk.virtualWrite(V0, 0);
            });
          }
        }
      }     
    }
      // Updating the previous state
      prev_1 = IRON_POW;
      prev_2 = VIBR;
      prev_3 = FLAT;
  }
  else{
    stateChanged = false;
  }
}

void setup() {
  // put your setup code here, to run once:
  pinMode(IRON_LED, OUTPUT);
  pinMode(IRON_POWER, INPUT_PULLUP);
  pinMode(VIBRATIONS, INPUT_PULLUP);
  pinMode(IS_FLAT, INPUT_PULLUP);
  Serial.begin(9600);
  // Setting ESP8266 Baud Rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  Blynk.begin(BLYNK_AUTH_TOKEN, wifi, ssid, pass); 
}

void loop() {
  // put your main code here, to run repeatedly:
  Blynk.run();
  timer.run();

  // Have to keep running the Indicator to check
  Indicator();

}



You shouldn’t be doing this in your void loop. You need to use an interval timer.

I don’t think you fully understand how the timeout timers are being triggered. You would need to add some serial print statements to understand when they are starting and stopping.

If you read the Timeout Timers section of this tutorial, especially the part that starts…

then add messages in your code that tell you when each of the timeout timers are starting and ending, you’ll have a better idea of the code execution sequence.

Pete.