Chicken coop esp32 sleep to save battery

This is my first project with Blynk and I want to create a chicken coop door with a ESP32 and a stepper motor. I have achieved a simple code with Blynk that closes the door at sunset and opens again at sunrise. My problem I need help with is that I want to run this on battery and need to put the ESP32 in a sleep mode between the open and closing. Is it possible to put the device in deep or light sleep mode and still use Blynk scheduler? If so, how can it be done?


What exactly do you mean by “Blynk scheduler”?
If you’re using the sunrise/sunset settings then I assume that this is a sunrise/sunset automation?

There’s no point in using Light Sleep, it achieves nothing in this situation.
With Deep Sleep your device won’t know that Bl6nk has commanded your door to open or close, so you’d need to wake up on a regular basis to check. The more often you wake up the more power is used, the less often you wake up the longer between the open/close command being issued by Blynk and your device knowing about it.

I don’t know much about chickens (apart from them tasting good :blush:) but I assume that waking every 10 minutes to check if Blynk has commanded the door to open or close, then actually actuating the door, would be acceptable?

Blynk deep sleep sketches need to be structured differently to normal Blynk sketches, and you need to use Blynk.config and Blynk.connect instead of Blynk.begin.
If you search for “deep sleep” on the forum you’ll find some examples.


Honestly - Wifi is generally power draining intensive. Why not build a simpler daylight sensor setup powered by a small solar cell & Li-Ion battery to open & close the door? Use something like a YoLink LoRa gate sensor (good for up to 1/4 mile) to notify regarding the door status (didn’t close right, etc). The YoLink API could be a way to get the door status to Blynk for viewing that way - others would need to weigh in?

Thanks @PeteKnight!
Might be to complex but my hope was to be able to to create a routine that identifies next automation and puts the esp to sleep until next open or close. Not sure if it’s possible to identify next automation?

Thanks @Sparky22!
This would be interesting to try out. I will do some research :slight_smile:

No, the way that automations work is that they simply turn a virtual pin on or off at the preset time.
That’s why I said that you’d need to wake the device up and check the virtual pin, then sleep again.

If I was doing this I’d use a hardware RTC module to store the time, and synchronise it with the Blynk server time once per day, then use the Blynk app to input the sunrise/sunset offset time as an easy way to tweak these parameters if you wanted to.


1 Like