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

ESP8266 Wemos D1 Mini - Time Input Widget

Hey guys,

I’ve got 2 actual problems with the TimerInput Widget :confused:
I’m running a Wemos D1 Mini with ESP8266 and everything is hosted on my own server.

I’m looking for an example on how-to resett a Virtual Pin to default settings.
The Examples on the github page didn’t help or maybe I did something wrong?

On V11 only the Weekdays and the Starttime could be selected!
On V12 everything except the timezone could be selected!
V0 is working great, but that isn’t a TimeInputWidget :slight_smile:

Here is my sketch for my reset on startup of blynk:

BLYNK_CONNECTED() {
  Blynk.virtualWrite(V0, R, G, B);
  for (int i = 1; i <= 7; i++) {
    Blynk.virtualWrite(V11, wecker, WECKERdays[i]);
    Blynk.virtualWrite(V12, PIRstart, PIRende, PIRdays[i]);
  }

  //or days
  //char days[] = "1,2,3"; //Monday, Tuesday, Wednesday
  //Blynk.virtualWrite(V1, startAt, stopAt, tz, days);
}

Then my 2nd problem is with V11 and V12. If disable every day it is like every day is checked.
I can’t find anything like t.hasStartTime() for this problem (maybe something like t.hasWeekdaysSelected().

Is there a work around?
Here is the sketch, how I set every day to 0 or 1 if it is selected or not.

  for (int i = 1; i <= 7; i++) {
    if (t.isWeekdaySelected(i)) {
      PIRdays[i] = 1;
    }
    else {
      PIRdays[i] = 0;
    }
    Serial.println(PIRdays[i]);
  }

Thank you in advance for every help :slight_smile:

I’ve fixed your formatting. You need to use triple backticks, not apostrophes.
Triple backticks look like this:
```

Pete.

thank you :slight_smile:

that’s true !

Could you just do:

for (int i = 1; i <= 7; i++) {
    PIRdays[i] = t.isWeekdaySelected(i);
    Serial.println(PIRdays[i]);
}
2 Likes

Oh… it was that simple? :smiley:
Thank you!

But that didn’t fix the problem?

Maybe you could share the rest of your code so we can see what is happening elsewhere?

Remove your Auth token before posting though :wink:

1 Like

If it helps, sure :slight_smile:

The code should do something like this:
If first timerInput time is reached, turn on LED (wake up light, red is just for testing).
If thats not the case: If time is between 2nd timerInput check if PIR-sensor is high, if so: turn on LED with presetted color of zeRGBa (nightlight).

#define BLYNK_PRINT Serial

#include <Adafruit_NeoPixel.h>
#include <SPI.h>
#include <BlynkSimpleEsp8266.h>
#include <NTPClient.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <SimpleTimer.h>

#define PIN D5
#define NUMPIXELS 37

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ400);

int interval = 1000;
unsigned long previousMillis = 0;

int R;
int G;
int B;

int lastConnectionAttempt = millis();
int connectionDelay = 5 * 1000;
int connectionSuccess = 0;

int PIRpin = D3;
int PIRval;
int PIRstart;
int PIRende;
int PIRtimer = 10 * 1000;
int PIRdays[] = {0, 0, 0, 0, 0, 0, 0};
bool PIRon;

int jetzt;
int endeVar;
int wochentag;

int WECKERval;
int WECKERtimer = 5 * 1000;
int WECKERdays[] = {0, 0, 0, 0, 0, 0, 0};
bool WECKERon;

const long utcOffsetInSeconds = 2 * 60 * 60;

unsigned long delayStart = 0;
bool delayRunning = false;

char auth[] = "****";
char ssid[] = "****";
char pass[] = "****";
char serv[] = "****";

WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "10.0.4.1", utcOffsetInSeconds, 24 * 60 * 60 * 1000);

SimpleTimer PIRreadTimer;

void setup() {
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass, serv, 8080);
  timeClient.begin();

  PIRreadTimer.setInterval(0.5 * 1000, PIRreadOUT);

  pinMode(PIRpin, INPUT);
  //pinMode(LED_BUILTIN, OUTPUT);
  timeClient.begin();
  pixels.begin();
  pixels.clear();

  delayStart = millis();
  delayRunning = false;
}

void loop() {
  PIRreadTimer.run();
  timeClient.update();

  unsigned long currentMillis = millis();
  if ((unsigned long)(currentMillis - previousMillis) >= interval) {
    previousMillis = currentMillis;
  }

  jetzt = timeClient.getHours() * 60 * 60 + timeClient.getMinutes() * 60 + timeClient.getSeconds();

  /*
      timeClient ist Sonntag die 0
      BlynkApp ist Sonntag die 7
      hiermit beides angleichen
  */
  wochentag = timeClient.getDay();
  if (timeClient.getDay() == 0) {
    wochentag = 7;
  }

  //    Wecker Zeit ist erreicht
  if (jetzt >= WECKERval && jetzt <= WECKERval + 6 && WECKERval != -1 && WECKERdays[wochentag] == 1) {
    WECKERon = 1;
    PIRon = 0;
  }

  else {

    // Abfrage ob Tag ausgewählt ist für PIR
    if (PIRdays[wochentag] == 1) {

      // Abfrage für Zeitraum 20:00 bis 20:50 Uhr
      if (PIRende > PIRstart && PIRstart != -1 && PIRende != -1) {
        endeVar = PIRende;
      }

      // Abfrage für Zeitraum 20:00 bis 03:50 Uhr (Tageswechsel)
      else if (PIRende < PIRstart && PIRstart != -1 && PIRende != -1) {
        endeVar = PIRende + 24 * 60 * 60;
        Serial.println("endeVar 86400s addiert");
        // Aktuell ist am folgendem Tag nach Start
        if (jetzt < PIRstart) {
          jetzt = jetzt + 24 * 60 * 60;
          Serial.println("jetzt 86400s addiert");
        }
      }

      // Im Start/Stop Zeitraum?
      if (jetzt >= PIRstart && jetzt < endeVar && PIRstart != -1 && PIRende != -1) {
        PIRon = 1;
        Serial.println("PIR A");
      }
      else {
        PIRon = 0;
        Serial.println("PIR B");
      }
    }
    else {
      PIRon = 0;
      Serial.println("PIR C");
    }
  }

  if (WiFi.status() != WL_CONNECTED) {
    if (millis() - lastConnectionAttempt >= connectionDelay) {
      lastConnectionAttempt = millis();
      Serial.println("Lost connections. Trying to reconnect...");
      WiFi.begin((char*)ssid, (char*)pass);
      connectionSuccess = 1;
    }
  }
  else if (WiFi.status() == WL_CONNECTED && connectionSuccess == 1) {
    Serial.print("Connected to WiFi: ");
    Serial.println(ssid);
    Serial.print("Local IP address: ");
    Serial.println(WiFi.localIP());
    connectionSuccess = 0;
  }
  else {
    Blynk.run();
  }
}

void PIRreadOUT() {
  if (PIRon == 1) {
    PIRval = digitalRead(PIRpin);
    Blynk.virtualWrite(V99, "PIRval: ", PIRval, "\n");
    Blynk.virtualWrite(V99, "delayRunning: ", delayRunning, "\n");
    Blynk.virtualWrite(V99, "millis: ", millis(), "\n");
    Blynk.virtualWrite(V99, "delayStart: ", delayStart, "\n");
    if (delayRunning && ((millis() - delayStart) <= PIRtimer)) {
      for (int i = 0; i < NUMPIXELS; i++) {
        pixels.setPixelColor(i, pixels.Color(R, B, G));
        pixels.show();
      }
      Blynk.virtualWrite(V99, "habe licht angemacht \n");
    }
    if (delayRunning && ((millis() - delayStart) > PIRtimer) && PIRval == LOW) {
      delayRunning = false;
      pixels.fill(0, 0, NUMPIXELS);
      pixels.show();
      Blynk.virtualWrite(V5, "No Motion");
      Blynk.virtualWrite(V99, "No Motion");
    }
    if (PIRval == HIGH) {
      Blynk.virtualWrite(V5, "Motion detected");
      Blynk.virtualWrite(V99, "Motion detected \n");
      Serial.println("Motion detected!");
      delayStart = millis();
      delayRunning = true;
    }
  }
  else if (WECKERon == 1) {
    Blynk.virtualWrite(V99, "HIER BIN ICH FALSCH \n");
    if (delayRunning && ((millis() - delayStart) <= WECKERtimer)) {
      for (int i = 0; i < NUMPIXELS; i++) {
        pixels.setPixelColor(i, pixels.Color(255, 0, 0));
        pixels.show();
      }
    }
    else {
      delayRunning = false;
      pixels.fill(0, 0, NUMPIXELS);
      pixels.show();
    }
  }
}

BLYNK_CONNECTED() {
  Blynk.virtualWrite(V0, R, G, B);
  Blynk.virtualWrite(V5, "First Start");
  Blynk.virtualWrite(V8, WECKERtimer / 1000);
  Blynk.virtualWrite(V9, PIRtimer / 1000);

  for (int i = 1; i <= 7; i++) {
    Blynk.virtualWrite(V11, WECKERval, WECKERdays[i]);
    Blynk.virtualWrite(V12, PIRstart, PIRende, PIRdays[i]);
  }
}


BLYNK_WRITE(V0) {
  int r = param[0].asInt();
  int g = param[1].asInt();
  int b = param[2].asInt();
  R = r;
  G = g;
  B = b;
}

BLYNK_WRITE(V8) {
  int pinValue = param.asInt();
  WECKERtimer = pinValue * 1000;
  //Blynk.virtualWrite(V9, WECKERtimer / 1000);
}

BLYNK_WRITE(V9) {
  int pinValue = param.asInt();
  PIRtimer = pinValue * 1000;
  //Blynk.virtualWrite(V9, PIRtimer / 1000);
}

BLYNK_WRITE(V11) {
  TimeInputParam t(param);
  if (t.hasStartTime()) {
    WECKERval = t.getStartHour() * 60 * 60 + t.getStartMinute() * 60 + t.getStartSecond();
  }
  else {
    WECKERval = -1;
  }
  Serial.println(String("Wecker: ") + WECKERval);
  for (int i = 1; i <= 7; i++) {
    WECKERdays[i] = t.isWeekdaySelected(i);
    Serial.println(WECKERdays[i]);
  }
}


BLYNK_WRITE(V12) {
  TimeInputParam t(param);
  if (t.hasStartTime()) {
    PIRstart = t.getStartHour() * 60 * 60 + t.getStartMinute() * 60 + t.getStartSecond();
  }
  else {
    PIRstart = -1;
  }
  if (t.hasStopTime()) {
    PIRende = t.getStopHour() * 60 * 60 + t.getStopMinute() * 60 + t.getStopSecond();
  }
  else {
    PIRende = -1;
  }
  for (int i = 1; i <= 7; i++) {
    PIRdays[i] = t.isWeekdaySelected(i);
    Serial.println(PIRdays[i]);
  }
}
1 Like

I’m afraid that your loop is blocking your virtual pins …

2 Likes

Try Blynk.run(); here:

else if (WiFi.status() == WL_CONNECTED && connectionSuccess == 1) {
    Serial.print("Connected to WiFi: ");
    Serial.println(ssid);
    Serial.print("Local IP address: ");
    Serial.println(WiFi.localIP());
    connectionSuccess = 0;
    Blynk.run(); // < insert Blynk.run() here
  }
  else {
    //Blynk.run(); // < remove/ comment out this one 
  }
2 Likes

Mhh what do you mean exactly? Is there a way to make it better… I’m sure there is, I’m realy new in blynking and ESP stuff :slight_smile:

I tested my sketch this morning again and I’m not sure what is wrong.
It only enables my PIR when the time start is at 6 am and the end is greater then this time.
If the end time is at 4 am f.e. it doesn’t work :frowning:

Also my “WECKER” (german: alarm clock) won’t work as intended :frowning:

I think I start my sketch again this evening :slight_smile:

Is there a possibility to enable and disable a simpletimer at all? Is this a better way then just let it run all day long and just check for a variable if it is 1 or 0? Thanks again mates, good Input so far <3

2 Likes

Mhh that code was from anywhere else (can’t remember) did a copy paste, makes sense :smiley:
My tests did work with the “wrong” code as well…

I could completly delete the

  else {
    //Blynk.run(); // < remove/ comment out this one 
  }

nothing else could happen

1 Like

you need to use interval timer
timer.setInterval(1000L, check_timer_widget);
and use the timer widget

1 Like

As @Blynk_Coeur has said, your void loop() needs to only have very minimal code. You should use a timer function to do other checks etc.

But for now, try to change your void loop() code to this:

void loop() {
  PIRreadTimer.run();
  timeClient.update();
  Blynk.run();

  unsigned long currentMillis = millis();
  if ((unsigned long)(currentMillis - previousMillis) >= interval) {
    previousMillis = currentMillis;
  }

  jetzt = timeClient.getHours() * 60 * 60 + timeClient.getMinutes() * 60 + timeClient.getSeconds();

  /*
      timeClient ist Sonntag die 0
      BlynkApp ist Sonntag die 7
      hiermit beides angleichen
  */
  wochentag = timeClient.getDay();
  if (timeClient.getDay() == 0) {
    wochentag = 7;
  }

  //    Wecker Zeit ist erreicht
  if (jetzt >= WECKERval && jetzt <= WECKERval + 6 && WECKERval != -1 && WECKERdays[wochentag] == 1) {
    WECKERon = 1;
    PIRon = 0;
  }

  else {

    // Abfrage ob Tag ausgewählt ist für PIR
    if (PIRdays[wochentag] == 1) {

      // Abfrage für Zeitraum 20:00 bis 20:50 Uhr
      if (PIRende > PIRstart && PIRstart != -1 && PIRende != -1) {
        endeVar = PIRende;
      }

      // Abfrage für Zeitraum 20:00 bis 03:50 Uhr (Tageswechsel)
      else if (PIRende < PIRstart && PIRstart != -1 && PIRende != -1) {
        endeVar = PIRende + 24 * 60 * 60;
        Serial.println("endeVar 86400s addiert");
        // Aktuell ist am folgendem Tag nach Start
        if (jetzt < PIRstart) {
          jetzt = jetzt + 24 * 60 * 60;
          Serial.println("jetzt 86400s addiert");
        }
      }

      // Im Start/Stop Zeitraum?
      if (jetzt >= PIRstart && jetzt < endeVar && PIRstart != -1 && PIRende != -1) {
        PIRon = 1;
        Serial.println("PIR A");
      }
      else {
        PIRon = 0;
        Serial.println("PIR B");
      }
    }
    else {
      PIRon = 0;
      Serial.println("PIR C");
    }
  }

  if (WiFi.status() != WL_CONNECTED) {
    if (millis() - lastConnectionAttempt >= connectionDelay) {
      lastConnectionAttempt = millis();
      Serial.println("Lost connections. Trying to reconnect...");
      WiFi.begin((char*)ssid, (char*)pass);
      connectionSuccess = 1;
    }
  }
  else if (WiFi.status() == WL_CONNECTED && connectionSuccess == 1) {
    Serial.print("Connected to WiFi: ");
    Serial.println(ssid);
    Serial.print("Local IP address: ");
    Serial.println(WiFi.localIP());
    connectionSuccess = 0;
  }
  else {
    
  }
}

And then post us the serial monitor output too :slight_smile:

1 Like

mhhh you changed the blynk.run() to the start of the loop now. not inside of the wifi check?

1 Like

you’re loop need to be like that

void loop() {
Blynk.run();
timer.run();
}

keep it clean

2 Likes

Yes I did. Just to try. Over the next few days I will check your code and maybe write something up for you if that change does not work?

1 Like

ok mates, I’m on it right now. Change everything to match best practices I learned so far :slight_smile:
I’m trying to code with PlatformIO now. Looks a bit cleaner and makes it a bit easier to see everything important. I will also try to add more timerintervalls instead of putting everything inside the loop.

Will report back. And JustBertC => thank you very much for taking the time you took so far for reading through the whole code <3

2 Likes

Hey guys,

I’m getting more and more familiar with the voids/functions and timers/intervalls.

My new written code (if I’m right I just copied some variables and the whole Blynk part, the other parts are new and running pretty well!

What I have to do for now is the part with the check of time for the PIR thing.
The sketch below will actually work like this:

Motion detected => turn on LED with RGB settings of ZeRGBa for given seconds in blynk
Alarm Time reached => turn off LED from Motion detection if they are on at this moment and then make a LED stripe effect with the color settings from ZeRGBa for given seconds in blynk

Stripe effect is taken from this example page: ColorWipe

Could someone take a look at this and tell me where the best position would be for the time calculation when the PIR will be active (timeInput Widget with Start and Endtime).

Here is my new sketch

#define BLYNK_PRINT Serial

#include <Adafruit_NeoPixel.h>
#include <BlynkSimpleEsp8266.h>
#include <ESP8266WiFi.h>
#include <NTPClient.h>
#include <SPI.h>
#include <SimpleTimer.h>
#include <WiFiUdp.h>

// LED Stuff
#define PIN D5
#define NUM_LEDS 37
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ400);
void colorWipe(int, int, int, int);
void showStrip();
void clearStrip();
void setPixel(int, int, int, int);
void ZeRGBa();

// WiFi Stuff
char auth[] = "************";
char ssid[] = "************";
char pass[] = "************";
char serv[] = "************";
#define BLYNK_PRINT Serial

#include <Adafruit_NeoPixel.h>
#include <BlynkSimpleEsp8266.h>
#include <ESP8266WiFi.h>
#include <NTPClient.h>
#include <SPI.h>
#include <SimpleTimer.h>
#include <WiFiUdp.h>

// LED Stuff
#define PIN D5
#define NUM_LEDS 37
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ400);
void colorWipe(int, int, int, int);
void showStrip();
void clearStrip();
void setPixel(int, int, int, int);
void ZeRGBa();

// WiFi Stuff
char auth[] = "59e6fabd771c46158bd201cd85733cb1";
char ssid[] = "SkyNet";
char pass[] = "Hb8#!D00fX!";
char serv[] = "blynk.maal.myds.me";

// Variables
int interval = 1000;
unsigned long previousMillis = 0;
unsigned long currentMillis = 0;

int red = 2;
int green = 2;
int blue = 0;

int connectionDelay = 5 * 1000;
int connectionSuccess = 0;

// Motion Sensor Variables
int PIR_pin = D3;
int PIR_val;
int PIR_start;
int PIR_stop;
int PIR_timer = 10 * 1000;
bool PIR_days[] = {0, 0, 0, 0, 0, 0, 0};
bool PIR_status = false;
unsigned long PIR_start_millis = 0;

int now;
int finish;
int weekday;

// Alarm Variables
int ALARM_start = -1;
int ALARM_timer = 5 * 1000;
bool ALARM_days[] = {0, 0, 0, 0, 0, 0, 0};
bool ALARM_status = false;
unsigned long ALARM_start_millis = 0;

const long utcOffsetInSeconds = 2 * 60 * 60;

unsigned long delayStart = 0;
bool delayRunning = false;

WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "10.0.4.1", utcOffsetInSeconds, 24 * 60 * 60 * 1000);

SimpleTimer timer;

void WIFI_check();
void TIME_check();
void PIR_check();
void ALARM_check();

void setup()
{
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass, serv, 8080);
  timeClient.begin();

  timer.setInterval(5.0 * 1000L, WIFI_check);
  timer.setInterval(0.2 * 1000L, TIME_check);
  timer.setInterval(0.5 * 1000L, PIR_check);
  timer.setInterval(1.0 * 1000L, ALARM_check);

  pinMode(PIR_pin, INPUT);

  timeClient.begin();
  pixels.begin();
  pixels.clear();

  delayStart = millis();
  delayRunning = false;

  Blynk.virtualWrite(V0, red, green, blue);
  Blynk.virtualWrite(V5, "First Start");
  Blynk.virtualWrite(V8, ALARM_timer / 1000);
  Blynk.virtualWrite(V9, PIR_timer / 1000);

  for (int i = 1; i <= 7; i++) {
    Blynk.virtualWrite(V11, ALARM_start, ALARM_days[i]);
    Blynk.virtualWrite(V12, PIR_start, PIR_stop, PIR_days[i]);
  }
}

void loop()
{
  timer.run();
  Blynk.run();
  timeClient.update();

  currentMillis = millis();
  if ((unsigned long)(currentMillis - previousMillis) >= interval) {
    previousMillis = currentMillis;
  }

  if (ALARM_status) {
    colorWipe(red, green, blue, 50);
    colorWipe(0, 0, 0, 50);
  }
  if (PIR_status) {
    ZeRGBa();
  }
}

void WIFI_check()
{
  if (WiFi.status() != WL_CONNECTED) {
    WiFi.begin((char*)ssid, (char*)pass);
    Serial.println("Lost WiFi Connection, trying to reconnect... ");
    connectionSuccess = 1;
  }
  else if (WiFi.status() == WL_CONNECTED && connectionSuccess == 1) {
    Serial.print("Connected to WiFi: ");
    Serial.println(ssid);
    Serial.print("Local IP address: ");
    Serial.println(WiFi.localIP());
    connectionSuccess = 0;
  }
}

void TIME_check()
{
  now = timeClient.getHours() * 60 * 60 + timeClient.getMinutes() * 60 + timeClient.getSeconds();
  weekday = timeClient.getDay();
    if (timeClient.getDay() == 0) {
      weekday = 7;
    }

}

void PIR_check()
{
  // PIR_start/stop >= 0 tracks, if both Start and Stop have time set in Blynk
  if (!ALARM_status && PIR_days[weekday] && PIR_start >= 0 && PIR_stop >= 0) {

    // Time between 5:00 and 6:00 f.e.
    if (PIR_stop > PIR_start) {
      finish = PIR_stop;
    }

    // Time between 6:00 and 5:00 f.e.
    else if (PIR_stop < PIR_start) {
      finish = PIR_stop + 24 * 60 * 60;

      // Now is at time on the next day after Start
      // Start = 20:00 | Stop = 4:00 | Now = 2:00
      if (now < PIR_start) {
        now = now + 24 * 60 * 60;
      }
    }

    // Check if Now is between Start and Stop
    if (now >= PIR_start && now < finish) {
      PIR_val = digitalRead(PIR_pin);
      if (PIR_val == HIGH) {
        Blynk.virtualWrite(V5, "Motion deteced");
        PIR_status = true;
        PIR_start_millis = currentMillis;
      }
      else {
        Blynk.virtualWrite(V5, "No Motion");
      }

      if (PIR_status) {
        if ((unsigned long)(currentMillis - PIR_start_millis) >= PIR_timer) {
          PIR_status = false;
        }
      }
      else {
        clearStrip();
      }
    }
  }
}

void ALARM_check()
{
  if (now == ALARM_start && ALARM_days[weekday] && ALARM_start >= 0) {
    clearStrip(); // Strip turned off if other Effects are running while Alarm is triggered
    ALARM_status = true;
    ALARM_start_millis = currentMillis;
  }

  if (ALARM_status) {
    if ((unsigned long)(currentMillis - ALARM_start_millis) >= ALARM_timer) {
      ALARM_status = false;
    }
  }
  else if (!PIR_status)
  {
    clearStrip();
  }
}

void showStrip() {
    pixels.show();
}

void clearStrip() {
    pixels.fill(0, 0, NUM_LEDS);
    showStrip();
}

void ZeRGBa() {
  for (int i = 0; i < NUM_LEDS; i++) {
    setPixel(i, red, green, blue);
    showStrip();
  }
}

void setPixel(int Pixel, int red, int green, int blue) {
    pixels.setPixelColor(Pixel, pixels.Color(red, blue, green));
}

void colorWipe(int red, int green, int blue, int SpeedDelay) {
  for (uint16_t i = 0; i < NUM_LEDS; i++) {
      setPixel(i, red, green, blue);
      showStrip();
      delay(SpeedDelay);
  }
}

BLYNK_CONNECTED()
{
  Blynk.virtualWrite(V0, red, green, blue);
  Blynk.virtualWrite(V8, ALARM_timer / 1000);
  Blynk.virtualWrite(V9, PIR_timer / 1000);

  for (int i = 1; i <= 7; i++) {
    Blynk.virtualWrite(V11, ALARM_start, ALARM_days[i]);
    Blynk.virtualWrite(V12, PIR_start, PIR_stop, PIR_days[i]);
  }
}


BLYNK_WRITE(V0)
{
  int r = param[0].asInt();
  int g = param[1].asInt();
  int b = param[2].asInt();
  red = r;
  green = g;
  blue = b;
}

BLYNK_WRITE(V8)
{
  int pinValue = param.asInt();
  ALARM_timer = pinValue * 1000;
}

BLYNK_WRITE(V9)
{
  int pinValue = param.asInt();
  PIR_timer = pinValue * 1000;
}

BLYNK_WRITE(V11)
{
  TimeInputParam t(param);
  if (t.hasStartTime()) {
    ALARM_start = t.getStartHour() * 60 * 60 + t.getStartMinute() * 60 + t.getStartSecond();
  }
  else {
    ALARM_start = -1;
  }
  for (int i = 1; i <= 7; i++) {
    ALARM_days[i] = t.isWeekdaySelected(i);
  }
}

BLYNK_WRITE(V12)
{
  TimeInputParam t(param);
  if (t.hasStartTime()) {
    PIR_start = t.getStartHour() * 60 * 60 + t.getStartMinute() * 60 + t.getStartSecond();
  }
  else {
    PIR_start = -1;
  }
  if (t.hasStopTime()) {
    PIR_stop = t.getStopHour() * 60 * 60 + t.getStopMinute() * 60 + t.getStopSecond();
  }
  else {
    PIR_stop = -1;
  }
  for (int i = 1; i <= 7; i++) {
    PIR_days[i] = t.isWeekdaySelected(i);
  }
}

Can you please just let us know which widgets are linked to each V pin? (Will make checking over easier :wink:)