Deep sleep config in run time

Hi all,
On an ESP32 board I’m trying to define the deep sleep time during the run time so I wrote this code

# Deep Sleep Feature. 
  run_duration: 60min
  sleep_duration: 1380min #23 hours
  id: deep_sleep_23 

#Some actions
    - switch.turn_on: switch1
    - delay: 2000ms
    - switch.turn_off: switch1
#perform a set up for deep sleep  and go in deep sleep
    - logger.log: "********I'm going in DEEP SLEEP************"
    - lambda: |-  
       id(deep_sleep_23).set_sleep_duration(3000); #Define a new deep sleep time
    - deep_sleep.enter: deep_sleep_23                    #Go in deep sleep
    - logger.log: "*******WOKE-UP************"
    - lambda: |-  
       id(deep_sleep_23).set_sleep_duration(10000); #Define a new sleep time

When I run the code the log message " ******** I’m going in DEEP SLEEP ************" is correctly printed but I have never seen the log message " ******* WOKE-UP ************ "
My doubts are:

  1. When the esp32 come back from the deep sleep it does not start from where it was prior to go in sleep state?
  2. How could I define a new sleep duration when it wake up? I would to setup the default sleep duration (23 hours)
  1. No. Waking from deep sleep is equivalent to restarting the ESP CPU.

  2. I don’t know.

1 Like

I think on_boot ( ESPHome Core Configuration — ESPHome ) will get triggert after it woke up. So you should be able to set a new duration there. You could try that.

It works! thanks for your suggestions :slight_smile: