ESPHome with dynamic sleep_time in Deepsleep

Hi,
I'm building a remote temperature sensor on ESP8266 to be put in a sauna, running on batteries. Since the sauna is only used for a couple of hours each time and sometimes weeks between usage, I'd like a variable sleep_time to reserve battery.

I.e. if the sauna temperature is below 30 degrees, it should sleep 15 minutes between readings.
If temperature is above 30 degrees I would like sleep_time to be 5 minutes.

Is is possible to have a template setting the sleep_time in ESPHome or do I need to build my own code to do this?

did you ever find out if anything like this is possible? I’m using an ESP32 and would like to do something similar

It’s not yet possible with just yaml there is a feature request though, go there and upvote https://github.com/esphome/feature-requests/issues/339#issuecomment-547940021

you can do it with a lambda and an undocumented call to the deep_sleep component but may be you just upvote meanwhile :slight_smile:

Upvoted, thanks

Hi there
I am responding to a bunch of old threads that are not resolved since I myself could not find this information here in the forums.

There are several ways (at least with version 1.19) to set the deep sleep duration from sensors or from Home Assistant by sending a retained MQTT message, se the code below.

In the sauna case I would maybe lean on having some sort of manual switch that turns the ESP on during the start up phase of the sauna but that might be overkill if you are not interested in logging the temps during the startup phase.

sensor:
  - platform: dallas
    address: 0x5500000970DEB928
    name: "Test temp1"
    id: some_sensor_id
    on_value:
      then:
      - if:
          condition:
            lambda: 'return id(some_sensor_id).state > 30.0 ;'
          then:
          - lambda: |-
              id(deep_sleep_1).set_sleep_duration(300000);
          else:
          - lambda: |-
              id(deep_sleep_1).set_sleep_duration(900000);

More code and text in this thread: DeepSleep with time window - #2 by runevad