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
[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
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.
Struggling with Deep Sleep Sensor Values in ESPHome (Again!)
Hey everyone,
I’ve been following this thread because I’ve been having the exact same issue with my ESPHome setup. My ESP32C3 device sends sensor data every few minutes and then goes into deep sleep. But as soon as it goes to sleep, Home Assistant marks all my sensors as “unavailable.” It’s been a frustrating experience, especially since it used to work fine before some recent updates.
Here’s What I’ve Tried So Far:
MQTT Retain Flag:
I configured the ESP to send all its data with the retain flag before going into deep sleep. The idea was to keep the last known values visible in Home Assistant while the device sleeps. It improved things a bit, but I still had sensors going “unavailable” occasionally.
Expire After Parameter:
I also tried setting expire_after for my sensors, thinking it would keep the last value for a set amount of time (like 3600s). This was supposed to ensure that Home Assistant holds onto the last data longer, but unfortunately, some sensors still didn’t behave as expected.
Tweaking the Deep Sleep Cycle:
I tweaked the ESPHome config so the device sends data as soon as it wakes up and right before it goes back to sleep. This helped make the data more reliable, but I still see that dreaded “unavailable” status now and then.
The Next Idea (Borrowed from an Old Forum Post):
I found an old forum suggestion about using Template Sensors in Home Assistant to keep the last known values when the sensor isn’t sending new data. Here’s a quick example:
I haven’t tried this yet, but it’s my next step. The idea is to avoid the “unavailable” status by making Home Assistant hold onto the last good value until the sensor sends fresh data. I’m hoping this will finally stabilize things.
I’ll be testing this out over the next few days. If anyone else has tried something similar, I’d love to hear how it worked out for you!