Deep sleep with templated duration

Hi everyone, I’m trying to get my ESP32 based device to enter deep sleep until dawn. However I’m struggling with the sleep_duration. The documentation states that this field is templatable, however it doesn’t provide any examples.

The following configuration doesn’t compile, complaining that a float is expected, so clearly it doesn’t like the lambda under minutes.

on_...:
  then:
    - deep_sleep.enter:
        id: deep_sleep_1
        sleep_duration:
          minutes: !lambda return id(minutes_to_dawn).state;

I can put the lambda directly on the sleep_duration field, and that compiles, but then it’s unclear what the value should be. Is it still minutes? Seconds? Milliseconds?

on_...:
  then:
    - deep_sleep.enter:
        id: deep_sleep_1
        sleep_duration: !lambda return id(minutes_to_dawn).state;

Has anyone figured this out by any chance?

My guess would be that the lambda for sleep_duration would need to return a string like 1h, 1s or 1min?

I thought so too but it expects an integer or float to be returned.

1 Like