Light relay turn on with sunset and turn off with sunrise

Hello All
I found this sketch in the sketch builder i am trying to configure it to work with relay output but no luck.
I know how to get a virtual pin to activate a digital output but in this example i failed.
can anyone tell me how to do it here on V1 ?
thanks.

/ *************************************************************
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.

Downloads, docs, tutorials: http://www.blynk.cc
Blynk community:            http://community.blynk.cc
Social networks:            http://www.fb.com/blynkapp
                            http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************

  App project setup:
Time Input widget on V1.
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";

#define W5100_CS  10
#define SDCARD_CS 4

BLYNK_WRITE(V1) {
  TimeInputParam t(param);

  // Process start time

  if (t.hasStartTime())
  {
Serial.println(String("Start: ") +
               t.getStartHour() + ":" +
               t.getStartMinute() + ":" +
               t.getStartSecond());
  }
  else if (t.isStartSunrise())
  {
Serial.println("Start at sunrise");
  }
  else if (t.isStartSunset())
  {
Serial.println("Start at sunset");
  }
  else
  {
// Do nothing
  }

  // Process stop time

  if (t.hasStopTime())
  {
Serial.println(String("Stop: ") +
               t.getStopHour() + ":" +
               t.getStopMinute() + ":" +
               t.getStopSecond());
  }
  else if (t.isStopSunrise())
  {
Serial.println("Stop at sunrise");
  }
  else if (t.isStopSunset())
  {
Serial.println("Stop at sunset");
  }
  else
  {
// Do nothing: no stop time was set
  }

  // Process timezone
  // Timezone is already added to start/stop time

  Serial.println(String("Time zone: ") + t.getTZ());

  // Get timezone offset (in seconds)
  Serial.println(String("Time zone offset: ") + t.getTZ_Offset());

  // 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");
}
  }

  Serial.println();
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card

  Blynk.begin(auth);
  // You can also specify server:
  //Blynk.begin(auth, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, IPAddress(192,168,1,100), 8442);
}

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

why i can’t get V1 work with this code

   BLYNK_WRITE(Vx)  // Runs every-time switch widget is toggled.
    {
      switchState = param.asInt();  // Get switch value.
      if (switchState == HIGH) {
        digitalWrite(digitalPin, HIGH);  // set digital pin HIGH
      } else {
        digitalWrite(digitalPin, LOW);  // set digital pin LOW
      }
    }

Because there is no pin named Vx.
BLYNK_WRITE(V1) would be correct.

I’m assuming you just copy pasted that code from your sketch.

@Ze_Pico you will need to locate an Arduino sunrise / sunset library or API for Blynk Webhook to actually control anything at sunset / sunrise. TimeInput widget simply checks if you have selected the option in the app, no more, no less.

So the process is:

Was sunrise / sunset selected in the app?

If yes, is it sunrise / sunset time now (from library / API) then take some action.

No, of course not.
I need you to try the sketch and tell me if you get it working with an output.

you are correct, but i don’t know how to continue with the sketch

@Costas here is the serial print for V1 from the sketch

[5001] Connecting to 192.168.0.139
[5282] Ready (ping: 12ms).
Start at sunset
Stop at sunrise
Time zone: Europe/Paris
Time zone offset: 3600
Day 1 is selected
Day 2 is selected
Day 3 is selected
Day 4 is selected
Day 5 is selected
Day 6 is selected
Day 7 is selected

@Costas that’s the expected output from V1. Just add “control” now.

Try Timer Widget for this instead and manually set the time in the app.

Ie stop and stop time.

Start at around sunset at 8pm and finish around sunrise at 6am.

The Timer Widget simply sends a 1 or 0 depending if it is active or not.

Simple as!

if you can help me with the control it will be great.

Timer Widget is the easiest way but you need to change the start and stop time every now and then.

for the time being i am using IFTTT sending sunrise and sunset time from a WEMO switch to my hardware.

You mean sunrise / sunset control or control generally?

sunrise / sunset control using Time Input widget on V1.

I got it from the http://examples.blynk.cc/

thanks

@Ze_Pico look through this thread for sketches that actually control hardware with Time Input.

Watch for Blynk days being different to regular time library days and look up the library hack to set TimeInput as “off” when no days are selected.

Then just do the same for sunrise / sunset.

Just an FYI @Costas, links aren’t color coded for phones, could be a bit hard for some to understand :slight_smile:

@Ze_Pico see my image if you missed it

Recently I have noticed that both links and now @mentions are monochromatic as well, even on Chrome PC browser… really adds to the fun :wink:

1 Like

I think I will go back to posting links in full like this Timezone conversion for the Time Input widget rather than invisible links like this.

The links are still not hightlighted in Chrome or on Smartphones but at least when Blynkers see the http://… it gives a strong indication that there is something to click on.

Nice to see the SKETCH BUILDER link at the top of each forum page.

2 Likes

@Pavel please fix.

Fixed

1 Like

Highlighted link test.

Doesn’t look very fixed to me @Pavel