ESPHome - start sequence - deepsleep

Hello,
I am using an ESP8266 for a waveshare display.

unnamed

I want to save energy and want to use the deep sleep mode of the esp8266.
Everything works but I am not happy with the sequence the cod runs and need an idea how to implement the folowing sequence:

boot - update sensors - refresh display once - go to deepsleep

At the moment the code runs this way:
boot - update display with no sensor data - after about 30sec all sensor data are refreshed - update display - go to deep sleep

this is my code:

esphome:
  name: ${name}
  platform: ESP8266
  board: esp12e
#  on_boot:
#     priority: -10
#     then:
#        - delay: 30s
#        - component.update: temp
#        - delay: 2s
#        - component.update: epaper
        
#  on_shutdown:
#    then:
#      - component.update: epaper
#      - delay: 5s

wifi:
  ssid: "FRITZ!Box 7490"
  password: "XXX"
  fast_connect: True

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "${name} Fallback Hotspot"
    password: "xxx"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "xxx"

ota:
  password: "xxx"

# Deep Sleep ###################################################################
deep_sleep:
  run_duration: 35s
  sleep_duration: 30min
 #  note that on the ESP8266 GPIO16 (D0) must be connected to the RST pin so that it will wake up again


# Name ##########################################################################
substitutions:
  name: esp8266_display

# SPI ##########################################################################
spi:
  clk_pin: GPIO14
  mosi_pin: GPIO13

# Time #########################################################################
time:
  - platform: homeassistant
    id: homeassistant_time
    timezone: Europe/Berlin
#    on_time:
#      # alle 5 Minuten :00; :05; :10; :15
#      - seconds: 0
#        minutes: /5
#        then:
#          - component.update: epaper


# Display 400x300 ##############################################################
display:
  - platform: waveshare_epaper
    cs_pin: GPIO15
    reset_pin: GPIO2
    dc_pin: GPIO4
    busy_pin: GPIO5
    model: 4.20in
    #rotation: 90°
    update_interval: 30s
    #update_interval: 24h
    id: epaper
    lambda: |-
      int x = 0, y = 0;
      ESP_LOGI("display", "Updating..");
      //it.print(0, 0, id(status_font), "Hello World!");
      /* Datum */
      it.strftime(200, 0, id(status_font), TextAlign::CENTER_HORIZONTAL, "%d.%m.%Y", id(homeassistant_time).now());
      /* Zeitupdate */
      it.strftime(0, 300, id(clock_font), TextAlign::BOTTOM_LEFT , "%H:%M", id(homeassistant_time).now());
      
      /*Wetter ---------------------------------------------------------------*/
      /* Innen */
      x = 0,  y = 50;
      if (id(temp_innen).has_state()) {
        it.print(x, y+5, id(icon_font), TextAlign::TOP_LEFT, "ア");
        it.printf(x+50, y, id(status_font), TextAlign::TOP_LEFT , "%.1f°C", id(temp_innen).state);
      }
      /* Luftfeuchte innen */
      if (id(feuchte).has_state()) {
        it.printf(x+200, y+5, id(icon_font), TextAlign::TOP_LEFT, ""); // Umbrella
        it.printf(x+250, y, id(status_font), TextAlign::TOP_LEFT , "%.0f%%", id(feuchte).state);
      }
      
      /* Print outside temperature (from homeassistant sensor) */
      if (id(aussentemperatur_eigene).has_state()) {
        it.print(x, y+50+5, id(icon_font), TextAlign::TOP_LEFT, "イ"); 
        it.printf(x+50, y+50, id(status_font), TextAlign::TOP_LEFT, "%.1f°C", id(aussentemperatur_eigene).state);
      } 
      else {
        if (id(aussentemperatur).has_state()) {
          it.print(x, y+50+5, id(icon_font), TextAlign::TOP_LEFT, "イ"); 
          it.printf(x+50, y+50, id(status_font), TextAlign::TOP_LEFT, "%.1f°C", id(aussentemperatur).state);
        } 
      }
      
      /* Luftfeuchte außen */
      if (id(luftfeuchte).has_state()) {
        it.printf(x+200, y+5+50, id(icon_font), TextAlign::TOP_LEFT, ""); // Umbrella
        it.printf(x+250, y+50, id(status_font), TextAlign::TOP_LEFT , "%.0f%%", id(luftfeuchte).state);
      }
      x= 400, y = 55;
      /* Himmel  */
      if (id(himmel_aktuell).has_state()) {
        if (id(himmel_aktuell).state == "Klarer Himmel") {
          it.printf(x, y, id(icon_font), TextAlign::TOP_RIGHT, ""); //  # mdi-weather-sunny
        } else if (id(himmel_aktuell).state == "Überwiegend bewölkt") {
          it.printf(x, y, id(icon_font), TextAlign::TOP_RIGHT, ""); // # mdi-weather-partly-cloudy
        } else if (id(himmel_aktuell).state == "Ein paar Wolken") {
          it.printf(x, y, id(icon_font), TextAlign::TOP_RIGHT, ""); // # mdi-weather-partly-cloudy
        } else if (id(himmel_aktuell).state == "Mäßig bewölkt") {
          it.printf(x, y, id(icon_font), TextAlign::TOP_RIGHT, ""); // # mdi-weather-partly-cloudy
        } else if (id(himmel_aktuell).state == "Bedeckt") {
          it.printf(x, y, id(icon_font), TextAlign::TOP_RIGHT, ""); //  # mdi-weather-cloudy
        } else if (id(himmel_aktuell).state == "Nebel") {
          it.printf(x, y, id(icon_font), TextAlign::TOP_RIGHT, ""); // # mdi-weather-fog
        } else if (id(himmel_aktuell).state == "Regen") {
          it.printf(x, y, id(icon_font), TextAlign::TOP_RIGHT, "");  // mdi-rain
        } else if (id(himmel_aktuell).state == "Mäßiger Regen") {
          it.printf(x, y+30, id(icon_font), TextAlign::TOP_RIGHT, "");  // mdi-rain
        } else if (id(himmel_aktuell).state == "Leichter Regen") {
          it.printf(x, y, id(icon_font), TextAlign::TOP_RIGHT, "");  // mdi-rain
        } else if (id(himmel_aktuell).state == "Gewitter mit leichtem Regen") {
          it.printf(x, y, id(icon_font), TextAlign::TOP_RIGHT, "");  // mdi-rain
        }
        else {
          //it.printf(x, y+30, id(icon_font), TextAlign::TOP_RIGHT, ""); //  # mdi-weather-sunny
        }
        //y = 150;
        //it.printf(x+40, y+30, id(status_font), TextAlign::TOP_RIGHT, "%s", id(himmel_aktuell).state.c_str());
      }
      
      /* Sonnenaufgang / untergang */
      x = 0, y = 150;
      if (id(sonnen_untergang).has_state()) {
        if (id(sonne).state == "above_horizon") {
          it.printf(x, y+5, id(icon_font), TextAlign::TOP_LEFT, ""); //  # mdi-weather-sunset-down
          it.printf(x+50, y, id(status_font), TextAlign::TOP_LEFT, "%sUhr", id(sonnen_untergang).state.c_str());
        } else {
          it.printf(x, y+5, id(icon_font), TextAlign::TOP_LEFT, ""); //  # mdi-weather-sunset-up
          it.printf(x+50, y, id(status_font), TextAlign::TOP_LEFT, "%sUhr", id(sonnen_aufgang).state.c_str());
        }
      }
      
      /* Wind */
      y = 200;
      if (id(windgeschwindigkeit).has_state()) {
        it.printf(x, y+5, id(icon_font), TextAlign::TOP_LEFT, ""); // # mdi-weather-windy-variant
        it.printf(x+50, y, id(status_font), TextAlign::TOP_LEFT , "%.1f km/h", id(windgeschwindigkeit).state);
        /* Richtung */
        x = 300, y = 200;
        if (id(windrichtung).state > 0.0 ) {
          if (id(windrichtung).state <= 22.5 )  {
            it.print(x, y, id(status_font), TextAlign::TOP_LEFT, "N");
          }
        }
        if (id(windrichtung).state > 22.5 ) {
          if (id(windrichtung).state <= 67.5 )  {
            it.print(x, y, id(status_font), TextAlign::TOP_LEFT, "NO");
          }
        }
        if (id(windrichtung).state > 67.5 ) {
          if (id(windrichtung).state <= 112.5 )  {
            it.print(x, y, id(status_font), TextAlign::TOP_LEFT, "O");
          }
        }
        if (id(windrichtung).state > 112.5 ) {
          if (id(windrichtung).state <= 157.5 )  {
            it.print(x, y, id(status_font), TextAlign::TOP_LEFT, "SO");
          }
        }
        if (id(windrichtung).state > 157.5 ) {
          if (id(windrichtung).state <= 202.5 )  {
            it.print(x, y, id(status_font), TextAlign::TOP_LEFT, "S");
          }
        }
        if (id(windrichtung).state > 202.5 ) {
          if (id(windrichtung).state <= 247.5 )  {
            it.print(x, y, id(status_font), TextAlign::TOP_LEFT, "SW");
          }
        }
        if (id(windrichtung).state > 247.5 ) {
          if (id(windrichtung).state <= 292.5 )  {
            it.print(x, y, id(status_font), TextAlign::TOP_LEFT, "W");
          }
        }
        if (id(windrichtung).state > 292.5 ) {
          if (id(windrichtung).state <= 337.5 )  {
            it.print(x, y, id(status_font), TextAlign::TOP_LEFT, "NW");
          }
        }
        if (id(windrichtung).state > 337.5 ) {
            it.print(x, y, id(status_font), TextAlign::TOP_LEFT, "N");
        }
        
        //it.printf(x, y, id(status_font), TextAlign::TOP_LEFT , "%.0f°", id(windrichtung).state);
        
      }
      
      /* WiFi Signal Strenght------------------------------------------------ */
      x = 400, y = 300;
      if(id(wifisignal).has_state()) {
        if (id(wifisignal).state >= -50) {
            /* Excellent */
            it.print(x, y, id(icon_font), TextAlign::BOTTOM_RIGHT, "蠟");
            ESP_LOGI("WiFi", "Exellent");
        } else if (id(wifisignal).state  >= -60) {
            /* Good */
            it.print(x, y, id(icon_font), TextAlign::BOTTOM_RIGHT, "襤");
            ESP_LOGI("WiFi", "Good");
        } else if (id(wifisignal).state  >= -67) {
            /* Fair */
            it.print(x, y, id(icon_font), TextAlign::BOTTOM_RIGHT, "嵐");
            ESP_LOGI("WiFi", "Fair");
        } else if (id(wifisignal).state  >= -70) {
            /* Weak */
            it.print(x, y, id(icon_font), TextAlign::BOTTOM_RIGHT, "爛");
            ESP_LOGI("WiFi", "Weak");
        } else {
            /* Unlikely working signal */
            it.print(x, y, id(icon_font), TextAlign::BOTTOM_RIGHT, "冷");
            ESP_LOGI("WiFi", "Unlikely");
        }
      }
# Sensor #######################################################################
sensor:     
# Wlan Stärke
  - platform: wifi_signal
    name: "WiFi Signal ${name}"
    update_interval: 30s
    id: wifisignal
# Solaranlage
  - platform: homeassistant
    id: watt_solaranlage
    entity_id: sensor.w_solaranlage
    internal: true
  - platform: homeassistant
    id: energy
    entity_id: sensor.energy_solaranlage
    internal: true
  - platform: homeassistant
    id: energy_gesamt
    entity_id: sensor.gesamterzeugung_solaranlage
    internal: true
# DHT 22
  # - platform: dht
  #   model: DHT22
  #   pin: GPIO5
  #   update_interval: 18s
  #   temperature:
  #     name: "Temperatur ${name}"
  #     id: temp
  #   humidity:
  #     name: "Luftfeuchte ${name}"
  #     id: feuchte
    
# Home Assistant
# Wetter
  - platform: homeassistant
    id: temp_innen
    entity_id: sensor.temperatur_flur
    internal: true
  - platform: homeassistant
    id: feuchte
    entity_id: sensor.esszimmer_luftfeuchte
    internal: true
  - platform: homeassistant
    id: aussentemperatur
    #entity_id: sensor.f007_t_pf_468a0_temp
    entity_id: sensor.openweathermap_temperature
    internal: true
    force_update: true
  - platform: homeassistant
    id: aussentemperatur_eigene
    entity_id: sensor.f007_t_pf_468a0_temp
    internal: true
    force_update: true
  - platform: homeassistant
    id: windgeschwindigkeit
    entity_id: sensor.openweathermap_wind_speed
    internal: true    
  - platform: homeassistant
    id: windrichtung
    entity_id: sensor.openweathermap_wind_bearing
    internal: true    
  - platform: homeassistant
    id: luftfeuchte
    entity_id: sensor.openweathermap_humidity
    internal: true


# Text Sensor aus Home Assistant ###############################################
text_sensor:
  - platform: homeassistant
    id: himmel_aktuell
    entity_id: sensor.openweathermap_condition
    internal: true
  - platform: homeassistant
    id: sonne
    entity_id: sun.sun
    internal: true
  - platform: homeassistant
    id: sonnen_untergang
    entity_id: sensor.sonnen_untergang
    internal: true
  - platform: homeassistant
    id: sonnen_aufgang
    entity_id: sensor.sonnen_aufgang
    internal: true

# Switch #######################################################################    
switch:
  - platform: gpio
    pin:
      number: GPIO2
      inverted: True
    name: "internalLED_esp8266"
    id: "led"

    
# Schriften ####################################################################
font:
  - file: 'fonts/Google_Sans_Bold.ttf'
    id: clock_font
    size: 10
    glyphs: [0, 1, 2, 3, 4, 5, 6, 7 ,8, 9, ':']
  - file: 'fonts/Google_Sans_Medium.ttf'
    id: temp_font
    size: 30
    glyphs:
      ['&', '@', '!', ',', '.', '"', '%', '(', ')', '+', '-', '_', ':', '°', '0',
       '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
       'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
       'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', 'a', 'b', 'c', 'd', 'e', 'f',
       'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
       'u', 'v', 'w', 'x', 'y', 'z','å', 'ä', 'ö', '/', '€']
  - file: 'fonts/Google_Sans_Bold.ttf'
    id: status_font
    size: 50
    glyphs:
      ['&', '@', '!', ',', '.', '"', '%', '(', ')', '+', '-', '_', ':', '°', '0',
       '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
       'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
       'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', 'a', 'b', 'c', 'd', 'e', 'f',
       'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
       'u', 'v', 'w', 'x', 'y', 'z', 'å', 'ä', 'ö', '/', 'ß', 'ü', 'Ü', 'Ö',
       'Ä', 'µ', '³' ]
  - file: 'fonts/materialdesignicons-webfont.ttf'
    id: icon_font
    size: 45
    glyphs: [
      '', # mdi-account-heart
      '', # mdi-thermometer
      '󰅢', # mdi-fire-hydrant
      "", # mdi-umbrella
      "イ", # mdi-home-thermometer-outline
      "ア", # mdi-home-thermometer
      # Wifi
      '冷', # mdi-wifi-strength-outline
      '爛', # mdi-wifi-strength-1
      '嵐', # mdi-wifi-strength-2
      '襤', # mdi-wifi-strength-3
      '蠟', # mdi-wifi-strength-4
      # Weather
      "", # mdi-weather-sunny
      "", # mdi-weather-night
      "", # mdi-weather-cloudy
      "", # mdi-weather-pouring
      "", # mdi-weather-snowy-rainy
      "s", # mdi-weather-snowy-heavy
      "", # mdi-weather-windy-variant
      "", # mdi-weather-fog
      "n", # mdi-weather-night-partly-cloudy
      "", # mdi-weather-partly-cloudy
      # Moon
      "チ", # new_moon
      "ト", # waxing_crecent
      "セ", # first_quarter
      "ナ", # waxing_gibbous
      "ソ", # full_moon
      "テ", # waning_gibbous
      "タ", # last_quarter
      "ツ", # waning_crescent
      # Sun
      "", # mdi-weather-sunset-down
      "", # mdi-weather-sunset-up
      "", # zapfsäule
      "",# männlich
      "", # weiblich
      ]

Did this not work?

#  on_boot:
#     priority: -10
#     then:
#        - delay: 30s
#        - component.update: temp
#        - delay: 2s
#        - component.update: epaper

It’s how I would have done it.

no this does not work.
polling from home assistant sensors does not work

struggling with the same problem, have an esp32 an a waveshare 7,5" display… still searching for a way to delay the display initialization…

i have a solution for you:

    update_interval: never

…this prevents the initial display update… and whenever you want to update the display, just call a refresh with:

      - component.update: my_display   
2 Likes