How can I implement deep sleep on an ESP8266 and wake when 1 of 2 buttons are pressed or when the temperature sensor is being read every minutee?

Hello, I’m looking to implement deep sleep for an ESP8266 with ESPhome to control a fan. I don’t need it to be using power all the time unless it’s reporting back temperature sensor values or when a button is pressed.

substitutions:
  name: esphome-web-3070ac
  friendly_name: Vent

esphome:
  name: ${name}
  friendly_name: ${friendly_name}
  min_version: 2024.6.0
  name_add_mac_suffix: false
  project:
    name: esphome.web
    version: dev

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption: 
    key: WZIIl3yawMBlaiu8LdtVUqOL7gDq74lQxivRIh8vhhw=

# OTA updates with password
ota:
  - platform: esphome
    password: !secret ota_password

# Allow provisioning Wi-Fi via serial
improv_serial:

# In combination with the `ap` this allows the user
# to provision wifi credentials to the device via WiFi AP.
captive_portal:

# To have a "next url" for improv serial
web_server:
  version: 3
  port: 80
  auth:
    username: !secret web_server_username
    password: !secret web_server_password

dashboard_import:
  package_import_url: github://esphome/example-configs/esphome-web/esp32.yaml@main
  import_full_config: true

wifi:
  # Set up a wifi access point
  ap: 
    ssid: !secret ap_ssid
    password: !secret ap_password

# Define the Neopixel light
light:
  - platform: neopixelbus
    name: "d9cd470a-163a-4f5f-b9fa-8abe6e945412"
    icon: "mdi:wall-sconce-round-variant"
    type: GRB
    variant: WS2812
    pin: 3
    num_leds: 1
    id: ws2812_indc_light
    restore_mode: ALWAYS_OFF
    default_transition_length: 1500ms
    web_server:
      sorting_weight: -1

# Define the SPI bus
spi:
  miso_pin: 12
  clk_pin: 15

# Define the SPI sensor
sensor:
  - platform: max6675
    name: "Temperature"
    icon: "mdi:thermometer"
    id: stove_temp
    cs_pin: 13
    update_interval: 60s
    web_server:
      sorting_weight: 5

# Define the binary sensors
binary_sensor:
  - platform: gpio
    pin:
      number: 0
      mode: INPUT_PULLUP
      inverted: true
    id: light_switch
    name: "Light"
    icon: "mdi:lightbulb"
    web_server:
      sorting_weight: 3
    on_press:
      then:
        - switch.toggle: light_relay

  - platform: gpio
    pin:
      number: 2
      mode: INPUT_PULLUP
      inverted: true
    id: fan_switch
    name: "Vent Fan"
    icon: "mdi:fan"
    web_server:
      sorting_weight: 1
    on_press:
      then:
        - script.execute: switch_indc_aesthetics

# Define the GPIO switches
switch:
  - platform: gpio
    pin: 4
    id: fan_relay
    name: "Vent Relay"
    icon: "mdi:fan"
    web_server:
      sorting_weight: 2

  - platform: gpio
    pin: 5
    id: light_relay
    name: "Light Relay"
    icon: "mdi:light"
    web_server:
      sorting_weight: 4

# Define the script for toggling the light
script:
  - id: switch_indc_aesthetics
    then:
      - if:
          condition:
            switch.is_on: fan_relay
          then:
            - light.turn_off:
                id: ws2812_indc_light
                transition_length: 600ms
            - delay: 700ms
            - switch.toggle: fan_relay
          else:
            - light.turn_on:
                id: ws2812_indc_light
                transition_length: 400ms
                brightness: 100%
                red: 100%
                green: 45%
                blue: 100%
            - delay: 700ms
            - switch.toggle: fan_relay

I’m sorry, I don’t understand. You’re controlling a fan, right? Doesn’t the fan always have power?
Also, are you not planning on bein able to contol anyting on your ESP board from within HA? If so, it has to be awake in order for you to do that. Otherwise it will not recieve the command from HA.

Have you read the documentation on deep sleep?

I have never enabled deep sleep, based on the few threads I have read about it, it is an adventure/advanced topic. So, I would ask why?

What do you hope to achieve?
How much energy do you hope to save?
How much time and personal energy are you willing to use to reach this goal?

I have a plan to use deep sleep with my Firebettle 2 devices which will have a li-ion battery and my goal is to get months before needing to recharge. I know this will be challenging to achieve and success is not guaranteed.

I also remember when partial sleep was added to Tasmota to reduce power consumption. I was skeptical, but the savings were real and ended up being easy to use. This was because there were people passionate enough about it to do the work to make happen and share it with everyone.

Esphome allows creating exactly what you want, but it also requires understanding enough of the system to do that. Some things are trivially easy. Some things that seem like they should be easy are incredibly difficult if not impossible unless you do a whole lot of work. I believe deep sleep is in the latter category.

The only way to wake an ESP8266 from deep sleep is to pull RST low. The ESP wakes and starts running.

1 Like

You can also set a timer, maximum of 60mins on an esp8266


deep_sleep:
  run_duration: 60s
  sleep_duration: 60min
  id: battery_deep_sleep

The timer output is on GPIO16, and is connected to RST to force a reset when the timer runs out.