On/Off Scheduling for Blynk Project

I have done a ton of searching and I have come across plenty of information on timers and such, but I am not able to figure out how to apply it to my scenario. I believe that it’s too simple of a scenario, which is why I can’t figure this out.

I built a wall shelf with LEDs built in that are controlled (color, brightness) via bkynk. I didn’t want to plug anything in, so I’m using batteries. The LEDs have a separate power supply, so that’s not the issue. It’s the li-po that I have connected to the esp2866 nodemcu that has the issue. The charge lasts less than 12 hours usually.

So, ALL I want to do is put the nodemcu in deep sleep all day except from the hours of 5p -10p (when I’m home and before I go to bed). This way, the battery should last much longer per charge. From what I’ve gathered, it can’t deep sleep for 19 hours straight. Which is fine, I would need to have it wake every hour or so for a second, then wake up for 5 hours around 5p.

Again, I know that there is plenty of info out there. I just need some advice on how to implement.

Thank you for any help that can be offered.

Your NodeMCU is going to need some way of finding-out what time it is when it wakes up, so I’d suggest you break the task down into bite-size chunks…

  1. get your NodeMCU to deep-sleep for a short time (maybe 5 minutes for simple testing) then re-connect to Blynk and write a message to a widget - terminal widget for example, then sleep again. When this is working consistently then extend your sleep time and make sure you can sleep successfully for 1 hour.

  2. go back to short sleeps and use your preferred method of getting the correct time (Blynk server using the RTC widget, or from an NTP time server. Add the time to the message that you’re sending to Blynk so that you’re happy its working properly. Once this is fine then move on to step 3.

  3. Analyse the time you’re getting from your time source and compare it to your On time (5pm). If it’s already reached the On time, but it’s before the Off time then turn on the LEDs. If it’s within an hour of the On time then sleep for a shorter time - e.g if it’s 4:30pm then sleep for 30 minutes.

The problem you’ll encounter is that the countdown timer that the NodeMCU uses in deep sleep isn’t very accurate, so the 30 minute sleep in the last example may give you 28 minutes, or 35 minutes. If it gives 35 minutes then no problem - your lights will come on 5 minutes late. If it’s 28 minutes then the next deep sleep will be only 2 minutes - again not a problem, except it’s a bit wasteful on battery life. You’ll need to do a bit of experimentation to see what the best way of handling this time drift is to suit your needs.
When it’s awake then you can use a timer to periodically compare the time to your Off time and switch the LEDs off if it’s equal to or greater than the Off time.

Hope this helps getting you started.


Excellent! Thank you for the guidance. I’m going to work with this outline today. I may have to reach back out if I hit some obstacles. I will be sure to report back either way.

honestly, even if you use timers and deep sleep stuff, you would have to charge the lipo every 2-3 days. and after some time, this gets irritating, so consider powering the nodemcu from a power supply.