Sunset/sunrise relay on/off

I need a simple code to turn relay on/off on sunset/sunrise.I don’t have enough energy to add eventor or nor IFTTT(now paid).

Did not find any code that to do this on blynk forum

IFTTT is free for a limited number of recipes (three I think) and you only need one or two.
Otherwise, search the forum for an API to download data from a weather site, which will give you sunrise and sunset times for your city or latitude/longitude.

Or, you could switch to Blynk 2.0 and use automations.


I posted a project a couple years ago called “Way Smarter Lights” that included onboard calculation of Sunrise / Sunset times. I ran into the same problem as you did with IFTTT, and because I’m an iPhone user, Eventor wasn’t even available to me. The code is not simple, and goes well beyond your requirements, but it will switch a relay at sunrise and sunset.

You can just use Automations on the new platform. We support astronomical timers there. No need to use another service :wink:

Close this topic, the code for sunset/sunrise quiet complex for me.
Can’t switch to 2.0 version for some reason,thanks for all of your reply.

New version doesn’t require any code for that.

Just wondering what’s with the new platform that stops you from using it? Appreciate your feedback

limitation to single mcu in free plan

yes three are free

use zapier or other tool similar to ifttt.

Screenshot 2021-06-04 171205

I guess you’re are responding to @VIGHNESHNS2008 comment that “yes, 3 are free”. This was in response to m comment that three IFTTT recipes are free.

I guess you have a number of options…

  • Use IFTTT for free
  • Pay $4.99 each for however many devices you need
  • Use one of the code examples or a weather API
  • Forget the idea.

Bear in mind that you will need to migrate toBlynk 2.0 at some point in the future, so why not do it now?



I personally always have issues with IFTTT and excluded it from all of my home systems. I mean, they are great, but absolutely not reliable and sometimes webhooks are processed in 10 minutes.

So for me personally it’s a no go.

Re: 1 device. Yes, you have 1 free device and you will be able to purchase more for just $4.99 one-time payment.

You bought your hardware right? Hardware is inly 30-50% of the IoT solution. The rest is done by software. So why not invest in the lifetime support of your device?

Check this out:

You will need to install the library, play a little with the example, that’s it. Blynk is being used to monitor live my PWS.

this is what i’m looking for thanks @italex33 :wink:

You are welcome. If you get stuck, let me know. Keep in mind that the trick here is converting hours/minutes to straight minutes, way much easier to calculate sunset/sunrise than using hours and minutes combined.