Photoperiod alarms

Good morning, in my project, I use an Arduino uno board, I have a photoresistor connected to analog input 2.
We have a room in which there are 12 hours of light and 12 hours of darkness and an external system turns those lights on and off.
I would like to generate an alarm in the Blynk automation section related to the Light reading according to the time.

Something like;
From 8:00 a.m. until 8:00 p.m. should read A2 >150 lux, otherwise it sends an alarm

From 8:00 p.m. until 8:00 there must be darkness A2<20 lux, otherwise it sends an alarm.

Thank you in advance for your help.

sorry for my english

my code

//device info

#include <Blynk.h>
#define BLYNK_PRINT Serial
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#define W5100_CS  10
#include <DHT.h>
#define ONE_WIRE_BUS 7 
OneWire oneWire(ONE_WIRE_BUS); 
DallasTemperature sensors(&oneWire);

// definir sensores
int SENSOR = 5;    

int LDR = analogRead (2);
int s = (sensors.getTempCByIndex(0));

DHT dht (SENSOR, DHT22);
BlynkTimer timer;

void sendSensor()
  int h = dht.readHumidity();
  int t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  int LDR = analogRead (2);
  int s = (sensors.getTempCByIndex(0));

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");

  Blynk.virtualWrite(V1, h);
  Blynk.virtualWrite(V0, t);
 Blynk.virtualWrite(V2, LDR);
  Blynk.virtualWrite(V7, s);


void setup()
  // Debug console


  // Setup a function to be called every second
  timer.setInterval(1000L, sendSensor);

void loop()

Hello, @Danilazaro please edit your post and read Recommendations for creating a new topic in Forum

Your code is not readable

Hello @Oleksii-QA , thanks for your response, I have just edit my post.

I´m a begginer and commit errors.

What sort of automation have you created using the V2 datastream?


Hi Pete,
I used a “Device State” Automation.
I program;
When V2, is less than 50 lux, send in App notifications
But I need that automation only works since 8:00 a.m. until 8:00 pm.
I don´t know how can I program for this.

Thanks a lot.


I think something is lost in translation in your previous post. I assume you mean that you need constant monitoring during the 24 hour period - let’s say once per minute - and if the lux parameters aren’t met then an alert should be sent.

First of all, you can’t do this with automations.

Secondly, this could potentially generate a high number of alerts, and there is a limit of 100 per 24 hour period.

To create the functionality in your sketch you would need to use the RTC data from the Blynk server, along with some timezone data, and define a set of rules which would limit the number of alerts that would be sent.

How good are your programming skills?


Normally, The room has 300 lux since 8:00 a.m until 8:00 pm. (day)
And 0 lux since 8:00 p.m until 8:00 am. (night)

These values normally doesn´t change in theses hours ranges.

I need an alert only if during (day) lux parametres is 0, or if during night lux parameters are 300.

I hope I have explained myself. My English is horrible.


Hello again,
I am now using an RTC clock. In V3 and V4 I have the actual time and date of my time zone.
Could you help me create the code for my alarm?

Thank you

Hello, finally I finished my project without your help.

Hello, @Danilazaro. Sorry if we couldn’t help you. We and the forum do not have examples for all cases. You have a PLUS 20 plan, and according to your plan technical support is only a forum. But we try to help everyone as much as we can for FREE and PLUS users.