Timer input problem

I would like to turn on a pin of esp32 at a certain time of the day (e.g. 21:00 GTM+1) and turn it off at another (e.g. 24:00 GTM+1) with the old application it worked fine I was directly controlling the gpio pin ov the esp32 from the widjet, with the new app I am not able to make it work.

I have used the Time input widjet but it does not return me an activation status when the defined time is reached.
I write a code like that:

#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID 
#define BLYNK_DEVICE_NAME 
char auth[] = 
char ssid[] = 
char pass[] = 

#include <SPI.h>
#include <DHT.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

#define DHTPIN 12          // What digital pin we're connected to
#define DHTTYPE DHT11     // DHT 11
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
int tim = 4;
int sensorVal; 
void sendSensor()
{
 float h = dht.readHumidity();
 float t = dht.readTemperature();
 Blynk.virtualWrite(V5, h);
 Blynk.virtualWrite(V6, t);
}



void setup()
{
 Serial.begin(115200);
 Blynk.begin(auth,ssid,pass);
 
 pinMode(tim, OUTPUT);
 digitalWrite(tim,LOW);
 dht.begin();
 timer.setInterval(1000L, sendSensor);
}


BLYNK_WRITE(V40) // TIMER ZONE Executes when the value of virtual pin 40 changes
{
 if(param.asStr() == 1)
 {
   // execute this code if the switch widget is now ON
   digitalWrite(tim,HIGH);  // Set digital pin 2 HIGH
 {
 else
 {
   // execute this code if the switch widget is now OFF
   digitalWrite(tim,LOW);  // Set digital pin 2 LOW    
 }
}



void loop()
{

   Blynk.run();
 timer.run();
}

Someone can help me?

Please edit your post, and add triple backticks ``` before and after your whole sketch.

You can try automation
https://docs.blynk.io/en/concepts/automations

I wolud like to have the timer on the normal app

Timer input widget works well, I use

t.getStartHour();
t.getStartMinute());
t.getStopHour());
t.getStopMinute());
1 Like

I am a big fan.

1 Like

Here’s a full example

Thank you very much for the answers,
I don’t need to let the board know about time, with the old blynk app the timer was directly managing the PIN on/off…
in any case did you thnk that someting similar can work?

BLYNK_WRITE(V1) {
 TimeInputParam t(param);

 // Process start time

 if (t.hasStartTime())
 {
   Serial.println(String("Start: ") +
                  t.getStartHour() + ":" +
                  t.getStartMinute() + ":" +
                  t.getStartSecond());
digitalwrite(PIN 1, HIGH)
 }
}

Blynk Legacy had two widgets with “Time” in there name.

One was “Timer” which simply turned a pin high or low at the start/end times.

The other was “Time Input” which allowed you to input start/end times, days of the week, time zones etc.

Blynk IoT doesn’t have a “Timer” widget anymore, it was replaced by Automations.

If you wnat to use the Time Input widget in either Legacy or IoT and wish to use days of the week then you need to process the days information that comes from the widget and test it against the current day of the week to see if the timer should activate or not.
There are several examples of how to do this, one of which is the Advanced Time Input example, where this code handles the days…

  // Process weekdays (1. Mon, 2. Tue, 3. Wed, ...)

  for (int i = 1; i <= 7; i++) {
    if (t.isWeekdaySelected(i)) {
      Serial.println(String("Day ") + i + " is selected");
    }
  }

However, that example hasn’t been fully updated with the new RTC method, so you’ll need to read the RTC documentation for that.

Or, you could use Automations instead.

Pete.