Value not showing with Deep Sleep mode in latest update?

I have an ESP device that I use to monitor my car battery, and noticed that after the recent HA updates, the value comes up as ‘Unknown’ if the deep sleep mode is on. Is there any known issue with the latest release? I haven’t had any issues with this module since installing it months ago.

It does show the value when the device wakes up; but once it goes back to sleep, the value is missing again.

  name: car-battery-monitor
  on_boot:
    then:
#      - logger.log: 'Car Battery Monitor booted...'
      - script.execute: consider_deep_sleep
  on_shutdown:
    then:
#      - logger.log: 'Shutting down...'
      
esp8266:
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "4c99fac4c96426d1f7a199737d02601a"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Car-Battery-Monitor"
    password: "qf6fl73Aaq9C"

captive_portal:

# This is the sensor which monitors the battery voltage
sensor:
  - platform: adc
    pin: A0
    name: "Car Battery Level"
    device_class: voltage
    update_interval: 10s
    filters:
      - multiply: 14.4217

# This is a binary Helper in Home Assistant
binary_sensor:
  - platform: homeassistant
    id: deep_sleep_mode
    name: Deep Sleep Mode
    entity_id: input_boolean.car_battery_monitor_sleep_mode

# Deep Sleep
deep_sleep:
  id: deep_sleep_control
  run_duration: 20s 
  sleep_duration: 290s  working.

# Script to check Binary Helper to enable/disable deep sleep mode
script:
  - id: consider_deep_sleep
    mode: queued
    then:
      - delay: 20s
      - if:
          condition:
            binary_sensor.is_on: deep_sleep_mode
          then:
            - deep_sleep.enter: deep_sleep_control
            - logger.log: 'Deep Sleep Enabled!'
          else:
            - deep_sleep.prevent: deep_sleep_control
            - logger.log: 'Deep Sleep NOT Enabled'
      - script.execute: consider_deep_sleep
1 Like

Thanks. I didn’t see anything in the release documentation when I looked. Hope this gets fixed quickly

1 Like

Just coming here to post that it looks like it’s fixed.

Awesome job, guys.

I’m still seeing the problem behavior on core-2023.8.4


substitutions:
  device_name: househumidity-esp32s
  friendly_name: househumidity-esp32s
  deepsleep_time: 30s
  update_interval: 5min
  sleep_check_interval: 5s       # As soon as the switch is toggled, we want to go to sleep.
  initial_sleep_check_delay: 30s  # Allows API to connect and give sleep boolean to us

esphome:
  name: ${device_name}
  friendly_name: ${friendly_name}

  on_boot:
    then:
      #- logger.log: 'on_boot - Before initial delay'
      - delay: ${initial_sleep_check_delay}
      #- logger.log: 'on_boot - executing script'
      - script.execute: consider_deep_sleep

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "xxxxx"

#ota:
#  password: xxxxx"

#captive_portal:
   

wifi:
  power_save_mode: none

  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
#  ap:
#    ssid: ${device_name}
#    password: "xxxxx"

sensor:
  - platform: dht
    pin: 16
    temperature:
      name: "Temperature"
    humidity:
      name: "Humidity"
    update_interval: ${update_interval}
    model: DHT11


## Deep Sleep

deep_sleep:
  id: deep_sleep_control
  sleep_duration: ${deepsleep_time}

# Will only pick up a value if this device is configured in Home Assistant > Integrations
# If the device isn't configured, or Home Assistant is offline, it'll default to false
binary_sensor:
  - platform: homeassistant
    id: prevent_deep_sleep
    entity_id: input_boolean.prevent_deep_sleep

script:
  - id: consider_deep_sleep
    mode: queued
    then:
#      - logger.log: 'Starting Script iteration'
      - delay: ${sleep_check_interval}
#      - logger.log: 'After Script delay'
      - if:
          condition:
            - api.connected:
          then:
            - delay: 5s
            - if:
                condition:
                  - binary_sensor.is_off: prevent_deep_sleep
                then:
                  - logger.log: 'No prevent_deep_sleep, so nappy nap time'
                  - deep_sleep.enter: deep_sleep_control
                else:
                  - logger.log: 'Staying awake; prevent_deep_sleep set.'
          else:
            - logger.log: 'Skipping sleep - no API connection.'
      - script.execute: consider_deep_sleep

Same problem.

Sometimes is works fine, sometimes not.

I’m experiencing the same anomaly.

  • Core 2023.11.0
  • Supervisor 2023.10.1
  • Operating System 11.1
  • ESPhome 2023.10.6
substitutions:
  dev_name: rodu-temperatuuri-andur
  dev_fname: Rõdu temperatuuri andur


esphome:
  name: ${dev_name}
  friendly_name: ${dev_fname}

esp32:
  board: lolin32_lite

# Enable logging
logger:
  level: DEBUG

# Enable Home Assistant API
api:
  encryption:
    key: "xxxx"
ota:
  password: "xxxx"
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password


i2c:
  sda: GPIO0
  scl: GPIO4
  scan: true

deep_sleep:
  run_duration: 60s
  sleep_duration: 10min



sensor:
  - platform: bme280
    temperature:
      id: bme280_temperature
      name: "Temperature"
      icon: 'mdi:thermometer'
      unit_of_measurement: "°C"
      oversampling: 16x
    pressure:
      name: "Pressure"
      icon: 'mdi:gauge'
    humidity:
      id: bme280_humidity
      name: "Relative Humidity"
      icon: 'mdi:water-percent'
      unit_of_measurement: "%"
    address: 0x76 #if doesn't work then try 0x77
    update_interval: 10s
  
  - platform: absolute_humidity
    name: "Absolute Humidity"
    temperature: bme280_temperature
    humidity: bme280_humidity
    icon: 'mdi:water-percent'
    unit_of_measurement: "%"
      
  - platform: template
    name: "Dew Point"
    lambda: |-
      return (243.5*(log(id(bme280_humidity).state/100)+((17.67*id(bme280_temperature).state)/
      (243.5+id(bme280_temperature).state)))/(17.67-log(id(bme280_humidity).state/100)-
      ((17.67*id(bme280_temperature).state)/(243.5+id(bme280_temperature).state))));
    unit_of_measurement: °C
    icon: 'mdi:thermometer-alert'

log:

[23:48:54][D][sensor:094]: 'Absolute Humidity': Sending state 7.91753 % with 2 decimals of accuracy
[23:48:54][I][deep_sleep:116]: Beginning Deep Sleep
[23:48:54][I][deep_sleep:118]: Sleeping for 600000000us
[23:48:54][D][esp32.preferences:114]: Saving 1 preferences to flash...
[23:48:54][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
INFO Processing expected disconnect from ESPHome API for rodu-temperatuuri-andur.local
WARNING Disconnected from API

Okay, it started to work.
I did two things.

  1. I added a battery sensor to yaml.
  - platform: adc
    pin: GPIO33
    id: VCC
    name: "VCC Voltage"
    attenuation: 11db
    entity_category: diagnostic
    update_interval: 60s
    filters:
      - multiply: 1.991
  - platform: template
    name: "Battery level"
    update_interval: 60s
    accuracy_decimals: 0
    lambda: |-
      return (((id(VCC).state-3) /1.2) * 100.00);
    entity_category: diagnostic
    unit_of_measurement: "%"  
    device_class: battery
  1. integrations → esphome → configure devce → Allow the device to make Home Assistant service calls.

firefox_0SYwlKXziZ

It’s a known issue since weeks now. I’ll try your suggestion as the previous workaround does not work anymore: some of us increased the DisconnectRequest in apiserver.cpp from 10 to 500ms. That worked. But I get errors in compiling if I try that now.

Allowing service calls makes no difference. On the contrary.

1 Like

Did anyone find a solution to this. I am doing a new setup now. And I am getting unavailable when in deep sleep.