Ich habe jetzt einiges ausprobiert.
Ohne “deep_sleep” ist die PB nach 1-2 Tagen leer, mit meldet sich der ESP32 nach wenigen Minuten ab - ohne Wiederkehr.
Es handelt sich um ein ESP-32 Dev Kit C V4.
Ich bin dann auf diesen Artikel gestoßen:
ESPHome: Batteries, Deep Sleep, and Over-the-Air Updates – Tatham Oddie.
Aber auch damit hängt sich der ESP nach ~2Min endgültig stumpf ab.
Hier mal der Code:
esphome:
name: "esphome-dht22"
friendly_name: "esphome-dht22"
on_boot:
then:
- script.execute: consider_deep_sleep
esp32:
board: esp32dev
framework:
type: arduino
logger:
api:
encryption:
key: "***"
ota:
- platform: esphome
password: "***"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
power_save_mode: light
ap:
ssid: "Esphome-Dht22"
password: "***"
captive_portal:
sensor:
- platform: dht
pin: GPIO21
temperature:
name: "Temperatur"
humidity:
name: "Luftfeuchtigkeit"
update_interval: 60s
- platform: wifi_signal # Reports the WiFi signal strength/RSSI in dB
name: "WiFi Signal dB"
id: wifi_signal_db
update_interval: 60s
entity_category: "diagnostic"
- platform: copy # Reports the WiFi signal strength in %
source_id: wifi_signal_db
name: "WiFi Signal Percent"
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "%"
entity_category: "diagnostic"
device_class: ""
deep_sleep:
id: deep_sleep_control
sleep_duration: 2min
# 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
name: $friendly_name Prevent Deep Sleep
entity_id: input_boolean.prevent_deep_sleep
script:
- id: consider_deep_sleep
mode: queued
then:
- delay: 15s
- if:
condition:
binary_sensor.is_on: prevent_deep_sleep
then:
- logger.log: 'Skipping sleep, per prevent_deep_sleep'
else:
- deep_sleep.enter: deep_sleep_control
- script.execute: consider_deep_sleep
Und dieses ist ein Log:
INFO ESPHome 2025.2.1
INFO Reading configuration /config/esphome/esphome-dht22.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing esphome-dht22 (board: esp32dev; framework: arduino; platform: platformio/espressif32@5.4.0)
--------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
- toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
...
========================= [SUCCESS] Took 40.17 seconds =========================
INFO Successfully compiled program.
INFO Connecting to 192.168.***.*** port 3232...
INFO Connected to 192.168.***.***
INFO Uploading /data/build/esphome-dht22/.pioenvs/esphome-dht22/firmware.bin (945424 bytes)
Uploading: [============================================================] 100% Done...
INFO Upload took 9.15 seconds, waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from 192.168.***.*** using esphome API
INFO Successfully connected to esphome-dht22 @ 192.168.***.*** in 7.143s
INFO Successful handshake with esphome-dht22 @ 192.168.***.*** in 0.105s
[21:30:41][I][app:100]: ESPHome version 2025.2.1 compiled on Feb 27 2025, 21:29:51
[21:30:41][C][wifi:600]: WiFi:
...
[21:30:41][C][logger:177]: Logger:
[21:30:41][C][logger:178]: Max Level: DEBUG
[21:30:41][C][logger:179]: Initial Level: DEBUG
[21:30:41][C][logger:181]: Log Baud Rate: 115200
[21:30:41][C][logger:182]: Hardware UART: UART0
[21:30:41][C][dht:017]: DHT:
[21:30:41][C][dht:018]: Pin: GPIO21
[21:30:41][C][dht:020]: Auto-detected model: DHT22
[21:30:41][C][dht:026]: Internal Pull-up: ON
[21:30:41][C][dht:028]: Update Interval: 60.0s
[21:30:41][C][dht:030]: Temperature 'Temperatur'
[21:30:41][C][dht:030]: Device Class: 'temperature'
[21:30:41][C][dht:030]: State Class: 'measurement'
[21:30:41][C][dht:030]: Unit of Measurement: '°C'
[21:30:41][C][dht:030]: Accuracy Decimals: 1
[21:30:41][C][dht:031]: Humidity 'Luftfeuchtigkeit'
[21:30:41][C][dht:031]: Device Class: 'humidity'
[21:30:41][C][dht:031]: State Class: 'measurement'
[21:30:41][C][dht:031]: Unit of Measurement: '%'
[21:30:41][C][dht:031]: Accuracy Decimals: 0
[21:30:41][C][copy.sensor:015]: Copy Sensor 'WiFi Signal Percent'
[21:30:41][C][copy.sensor:015]: State Class: 'measurement'
[21:30:41][C][copy.sensor:015]: Unit of Measurement: '%'
[21:30:41][C][copy.sensor:015]: Accuracy Decimals: 0
[21:30:41][C][captive_portal:089]: Captive Portal:
[21:30:41][C][mdns:116]: mDNS:
[21:30:41][C][mdns:117]: Hostname: esphome-dht22
[21:30:41][C][esphome.ota:073]: Over-The-Air updates:
[21:30:41][C][esphome.ota:074]: Address: esphome-dht22.local:3232
[21:30:41][C][esphome.ota:075]: Version: 2
[21:30:41][C][esphome.ota:078]: Password configured
[21:30:41][C][safe_mode:018]: Safe Mode:
[21:30:41][C][safe_mode:020]: Boot considered successful after 60 seconds
[21:30:42][C][safe_mode:021]: Invoke after 10 boot attempts
[21:30:42][C][safe_mode:023]: Remain in safe mode for 300 seconds
[21:30:42][C][api:140]: API Server:
[21:30:42][C][api:141]: Address: esphome-dht22.local:6053
[21:30:42][C][api:143]: Using noise encryption: YES
[21:30:42][C][wifi_signal.sensor:010]: WiFi Signal 'WiFi Signal dB'
[21:30:42][C][wifi_signal.sensor:010]: Device Class: 'signal_strength'
[21:30:42][C][wifi_signal.sensor:010]: State Class: 'measurement'
[21:30:42][C][wifi_signal.sensor:010]: Unit of Measurement: 'dBm'
[21:30:42][C][wifi_signal.sensor:010]: Accuracy Decimals: 0
[21:30:42][C][homeassistant.binary_sensor:039]: Homeassistant Binary Sensor '$friendly_name Prevent Deep Sleep'
[21:30:42][C][homeassistant.binary_sensor:040]: Entity ID: 'input_boolean.prevent_deep_sleep'
[21:30:42][C][deep_sleep:026]: Setting up Deep Sleep...
[21:30:42][C][deep_sleep:029]: Sleep Duration: 120000 ms
[21:30:48][D][main:140]: Skipping sleep, per prevent_deep_sleep
[21:30:48][D][script:100]: Script 'consider_deep_sleep' queueing new instance (mode: queued)
[21:31:03][D][main:140]: Skipping sleep, per prevent_deep_sleep
[21:31:03][D][script:100]: Script 'consider_deep_sleep' queueing new instance (mode: queued)
[21:31:16][D][sensor:094]: 'WiFi Signal dB': Sending state -41.00000 dBm with 0 decimals of accuracy
[21:31:16][D][sensor:094]: 'WiFi Signal Percent': Sending state 100.00000 % with 0 decimals of accuracy
[21:31:18][D][main:140]: Skipping sleep, per prevent_deep_sleep
[21:31:18][D][script:100]: Script 'consider_deep_sleep' queueing new instance (mode: queued)
[21:31:20][D][dht:049]: Got Temperature=20.8°C Humidity=45.0%
[21:31:20][D][sensor:094]: 'Temperatur': Sending state 20.80000 °C with 1 decimals of accuracy
[21:31:20][D][sensor:094]: 'Luftfeuchtigkeit': Sending state 45.00000 % with 0 decimals of accuracy
[21:31:33][I][safe_mode:041]: Boot seems successful; resetting boot loop counter
[21:31:33][D][esp32.preferences:114]: Saving 1 preferences to flash...
[21:31:33][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[21:31:33][D][main:140]: Skipping sleep, per prevent_deep_sleep
[21:31:33][D][script:100]: Script 'consider_deep_sleep' queueing new instance (mode: queued)
...
[21:32:20][D][dht:049]: Got Temperature=20.8°C Humidity=45.0%
[21:32:20][D][sensor:094]: 'Temperatur': Sending state 20.80000 °C with 1 decimals of accuracy
[21:32:20][D][sensor:094]: 'Luftfeuchtigkeit': Sending state 45.00000 % with 0 decimals of accuracy
[21:32:33][D][main:140]: Skipping sleep, per prevent_deep_sleep
[21:32:33][D][script:100]: Script 'consider_deep_sleep' queueing new instance (mode: queued)
[21:32:48][D][main:140]: Skipping sleep, per prevent_deep_sleep
[21:32:48][D][script:100]: Script 'consider_deep_sleep' queueing new instance (mode: queued)
[21:33:03][D][main:140]: Skipping sleep, per prevent_deep_sleep
[21:33:03][D][script:100]: Script 'consider_deep_sleep' queueing new instance (mode: queued)
WARNING esphome-dht22 @ 192.168.***.***: Connection error occurred: Ping response not received after 90.0 seconds
INFO Processing unexpected disconnect from ESPHome API for esphome-dht22 @ 192.168.***.***
WARNING Disconnected from API
WARNING Can't connect to ESPHome API for esphome-dht22 @ 192.168.***.***: Error connecting to [AddrInfo(family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, proto=6, sockaddr=IPv4Sockaddr(address='192.168.***.***', port=6053))]: [Errno 113] Connect call failed ('192.168.***.***', 6053) (SocketAPIError)
INFO Trying to connect to esphome-dht22 @ 192.168.***.*** in the background
Dass der Helper in ESPHome aktiv ist, sieht man ja an den Meldungen “Skipping sleep, per prevent_deep_sleep”.
Wie betreibt ihr eure ESP32-Geräte mit Akku oder Batterie?