How get the running duration of the led with blynk

i have a code for turning on led in through blynk i have to show how much time the led is turned on for a day and display it in blynk platform

#define BLYNK_TEMPLATE_NAME "led blink"
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>

// Your Wi-Fi credentials
char ssid[] = "YourWiFiSSID";
char password[ ] = "YourWiFiPassword";

// Blynk authentication token
char auth[] = "YourBlynkAuthToken";

// Pin for the LED
const int ledPin = 13;  // You can use any GPIO pin

void setup() {
  Serial.begin(9600);
  // Check if Wi-Fi is connected
  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("Connecting to Wi-Fi...");
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) {
      delay(1000);
      Serial.print(".");
    }
    Serial.println("\nConnected to Wi-Fi");
  }
  
  Blynk.begin(auth, ssid, password);
  pinMode(ledPin, OUTPUT);
}

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

// Blynk function to handle button widget events
BLYNK_WRITE(V0) {
  int value = param.asInt();  // Get the value from the Button widget
  digitalWrite(ledPin, value);  // Turn the LED on/off based on the widget value
}

please give me correct code where i can monitor the duration led in turned on

Hello @vishal3.

Your code is not readable. Please format and add

code

i have changed it is the basic blynk led code i want this code which also show the duration the led is on for a day

The way I would approach this would be to set a flag whenever the LED is on.
I’d then use a routine, called once every second by BlynkTimer, that checks if the flag is set to true or false.
If the flag is true then you update the “on count” by one. Your “on count” then shows the cumulative value of how many seconds the LED has been on for.

You’ll need a way to zero the results at midnight, and I guess an Automation may be the simplest way to do this.

Pete.

@PeteKnight can you give me the direct code for this with my led project this would help me i am complete beginner

If you want someone to write your code for you then you might be better looking at freelancing services like fyverr

Pete.

@PeteKnight give me like a pseudo code atleast

Try using chatGPT. It should work

Your requirement doesn’t sound too different from this…

Pete.