In testing ESP32 deep_sleep I have come across something I can’t explain, and hoping someone can help me. I have a couple of issues:
- I have a programming background, but not familiar with C++
- For some variables
id(variable)
contains the value, but other timesid(other_variable).state
contains the value. - Sometimes ESP_LOGD() and logger.log return different values for the same variable.
Here is my test code:
#####################################################################
# #
# The ESP32-S3-DevKitC-1 (v1) board with ESP32-S3-WROOM-1-N16R8 #
# CURRENT usage for debugging parts of the greenhouse code #
# #
#####################################################################
substitutions:
devicename: "esp32s3-test"
update_interval_sensor: "2 min" # How often to measure and report sensor values
deep_sleep:
id: deep_sleep_1
run_duration: 300000ms # = 5 min - how long to run (be awake)
sleep_duration: 180000ms # = 3 min - how long to sleep for
esphome:
name: $devicename
platformio_options:
board_build.flash_mode: dio
on_boot:
- priority: -100.0
then:
- lambda: |-
ESP_LOGD("on_boot", "");
ESP_LOGD("on-boot", "#################### ON_BOOT ####################");
ESP_LOGD("on_boot", ">>>>>> on_boot: initial values wakeup_cause=%d, wakeup_cause.state=%d, num_wake_cycles=%d",
id(wakeup_cause), id(wakeup_cause).state, id(num_wake_cycles) );
// id(wakeup_cause) = esp_sleep_get_wakeup_cause();
id(num_wake_cycles) += 1;
#- number.increment: num_wake_cycles
- logger.log: "##### on_boot finished"
on_shutdown:
- priority: -100
then:
- lambda: |-
ESP_LOGD("on_shutdown", "");
ESP_LOGD("on_shutdown", " >>>> A >>>> wakeup_cause=%d, wakeup_cause.state=%d, num_wake_cycles=%d",
id(wakeup_cause), id(wakeup_cause).state, id(num_wake_cycles) );
- logger.log:
format: "logger >>>> B >>>> wakeup_cause=%d, wakeup_cause.state=%d, num_wake_cycles=%d "
args: [ 'id(wakeup_cause)', 'id(wakeup_cause).state', 'id(num_wake_cycles)' ]
globals:
- id: num_wake_cycles
type: int
restore_value: yes
initial_value: '0'
sensor:
- platform: template
id: wakeup_cause
name: $devicename Wakeup cause
update_interval: $update_interval_sensor
accuracy_decimals: 0
lambda: |-
ESP_LOGD("wakeup_cause", ">>>> X >>>> esp_sleep_get_wakeup_cause()=%d, wakeup_cause=%d, wakeup_cause.state=%d, num_wake_cycles=%d",
esp_sleep_get_wakeup_cause(), id(wakeup_cause), id(wakeup_cause).state, id(num_wake_cycles) );
return esp_sleep_get_wakeup_cause();
on_raw_value:
then:
- logger.log:
format: "logger >>>> C >>>> wakeup_cause=%d, wakeup_cause.state=%d, num_wake_cycles=%d, x=%d"
args: [ 'id(wakeup_cause)', 'id(wakeup_cause).state', 'id(num_wake_cycles)', 'x' ]
- lambda: |-
ESP_LOGD("wakeup_cause", ">>>> D >>>> wakeup_cause=%d, wakeup_cause.state=%d, num_wake_cycles=%d, x=%d",
id(wakeup_cause), id(wakeup_cause).state, id(num_wake_cycles), x );
- platform: bh1750
name: $devicename BH1750 Illuminance
address: 0x23
update_interval: $update_interval_sensor
on_raw_value:
then:
- logger.log:
format: "logger >>>> E >>>> wakeup_cause=%d, wakeup_cause.state=%d, num_wake_cycles=%d "
args: [ 'id(wakeup_cause)', 'id(wakeup_cause).state', 'id(num_wake_cycles)' ]
- lambda: |-
ESP_LOGD("BH1750", " >>>> F >>>> wakeup_cause=%d, wakeup_cause.state=%d, num_wake_cycles=%d ",
id(wakeup_cause), id(wakeup_cause).state, id(num_wake_cycles) );
- platform: wifi_signal
name: $devicename Wifi signal
update_interval: $update_interval_sensor
#
# the other stuff you still want to know...
#
esp32:
board: esp32-s3-devkitc-1 # devkit from AliExpress
variant: esp32s3
flash_size: 16MB
framework:
type: esp-idf
version: recommended
psram:
mode: octal
speed: 80MHz
wifi:
ssid: !secret upstairs_ssid
password: !secret upstairs_password
manual_ip:
static_ip: 192.168.1.124
gateway: 192.168.1.1
subnet: 255.255.255.0
fast_connect: True
ota:
platform: esphome
password: !secret esphome_ota_password
web_server:
port: 80
api:
encryption:
key: !secret esphome_api_encryption
logger:
level: DEBUG
hardware_uart: uart0
i2c:
- id: bus_a
sda: GPIO5
scl: GPIO4
scan: true
frequency: 400kHz
I have setup a template sensor to store the current wakeup cause, and a global variable for the number of times the ESP32 has woken up. I also have a BH1750 Illuminance and wi-fi signal sensors attached to show that normal sensors are still being handled properly.
I have added logger.log and lambda ESP_LOGD() actions to track the variables, but found that sometimes there are differences even though I have copied and pasted the arguments !
The result (from the more comprehensive UART log) is:
[2025-04-24 12:43:09] ESP-ROM:esp32s3-20210327
[2025-04-24 12:43:09] Build:Mar 27 2021
[2025-04-24 12:43:09] rst:0x5 (DSLEEP),boot:0x2b (SPI_FAST_FLASH_BOOT)
[2025-04-24 12:43:09] SPIWP:0xee
[2025-04-24 12:43:09] mode:DIO, clock div:1
[2025-04-24 12:43:09] load:0x3fce3818,len:0x1750
[2025-04-24 12:43:09] load:0x403c9700,len:0x4
[2025-04-24 12:43:09] load:0x403c9704,len:0xbe4
[2025-04-24 12:43:09] load:0x403cc700,len:0x2d34
[2025-04-24 12:43:09] entry 0x403c9908
[2025-04-24 12:43:09] I (27) boot: ESP-IDF 5.1.5 2nd stage bootloader
[2025-04-24 12:43:09] I (27) boot: compile time Feb 22 2025 12:49:26
[2025-04-24 12:43:09] I (27) boot: Multicore bootloader
[2025-04-24 12:43:09] I (30) boot: chip revision: v0.2
[2025-04-24 12:43:09] I (34) boot.esp32s3: Boot SPI Speed : 80MHz
[2025-04-24 12:43:09] I (38) boot.esp32s3: SPI Mode : DIO
[2025-04-24 12:43:09] I (43) boot.esp32s3: SPI Flash Size : 16MB
[2025-04-24 12:43:09] I (48) boot: Enabling RNG early entropy source...
[2025-04-24 12:43:09] I (53) boot: Partition Table:
[2025-04-24 12:43:09] I (57) boot: ## Label Usage Type ST Offset Length
[2025-04-24 12:43:09] I (64) boot: 0 otadata OTA data 01 00 00009000 00002000
[2025-04-24 12:43:09] I (72) boot: 1 phy_init RF data 01 01 0000b000 00001000
[2025-04-24 12:43:09] I (79) boot: 2 app0 OTA app 00 10 00010000 007c0000
[2025-04-24 12:43:09] I (87) boot: 3 app1 OTA app 00 11 007d0000 007c0000
[2025-04-24 12:43:09] I (94) boot: 4 nvs WiFi data 01 02 00f90000 0006d000
[2025-04-24 12:43:09] I (102) boot: End of partition table
[2025-04-24 12:43:09] I (106) esp_image: segment 0: paddr=007d0020 vaddr=3c0a0020 size=30440h (197696) map
[2025-04-24 12:43:09] I (150) esp_image: segment 1: paddr=00800468 vaddr=3fc9a200 size=04908h ( 18696) load
[2025-04-24 12:43:09] I (154) esp_image: segment 2: paddr=00804d78 vaddr=40374000 size=0b2a0h ( 45728) load
[2025-04-24 12:43:09] I (166) esp_image: segment 3: paddr=00810020 vaddr=42000020 size=99d74h (630132) map
[2025-04-24 12:43:09] I (279) esp_image: segment 4: paddr=008a9d9c vaddr=4037f2a0 size=0aea0h ( 44704) load
[2025-04-24 12:43:09] I (290) esp_image: segment 5: paddr=008b4c44 vaddr=600fe000 size=0005ch ( 92)
[2025-04-24 12:43:09] I (290) esp_image: segment 6: paddr=008b4ca8 vaddr=600fe05c size=00008h ( 8)
[2025-04-24 12:43:09] I (304) boot: Loaded app from partition at offset 0x7d0000
[2025-04-24 12:43:09] I (304) boot: Disabling RNG early entropy source...
[2025-04-24 12:43:09] I (307) cpu_start: Multicore app
[2025-04-24 12:43:09] I (311) octal_psram: vendor id : 0x0d (AP)
[2025-04-24 12:43:09] I (315) octal_psram: dev id : 0x02 (generation 3)
[2025-04-24 12:43:09] I (321) octal_psram: density : 0x03 (64 Mbit)
[2025-04-24 12:43:09] I (327) octal_psram: good-die : 0x01 (Pass)
[2025-04-24 12:43:09] I (332) octal_psram: Latency : 0x01 (Fixed)
[2025-04-24 12:43:09] I (337) octal_psram: VCC : 0x01 (3V)
[2025-04-24 12:43:09] I (342) octal_psram: SRF : 0x01 (Fast Refresh)
[2025-04-24 12:43:09] I (348) octal_psram: BurstType : 0x01 (Hybrid Wrap)
[2025-04-24 12:43:09] I (354) octal_psram: BurstLen : 0x01 (32 Byte)
[2025-04-24 12:43:09] I (359) octal_psram: Readlatency : 0x02 (10 cycles@Fixed)
[2025-04-24 12:43:09] I (365) octal_psram: DriveStrength: 0x00 (1/1)
[2025-04-24 12:43:09] I (371) MSPI Timing: PSRAM timing tuning index: 5
[2025-04-24 12:43:09] I (376) esp_psram: Found 8MB PSRAM device
[2025-04-24 12:43:09] I (381) esp_psram: Speed: 80MHz
[2025-04-24 12:43:09] I (385) cpu_start: Pro cpu up.
[2025-04-24 12:43:09] I (388) cpu_start: Starting app cpu, entry point is 0x40376f28
[2025-04-24 12:43:09] I (0) cpu_start: App cpu up.
[2025-04-24 12:43:10] I (818) esp_psram: SPI SRAM memory test OK
[2025-04-24 12:43:10] I (826) cpu_start: Pro cpu start user code
[2025-04-24 12:43:10] I (826) cpu_start: cpu freq: 160000000 Hz
[2025-04-24 12:43:10] I (826) cpu_start: Application information:
[2025-04-24 12:43:10] I (829) cpu_start: Project name: esp32s3-test
[2025-04-24 12:43:10] I (835) cpu_start: App version: 2025.4.0
[2025-04-24 12:43:10] I (840) cpu_start: Compile time: Apr 20 2025 15:13:57
[2025-04-24 12:43:10] I (846) cpu_start: ELF file SHA256: a8fd51b9aa6b05a9...
[2025-04-24 12:43:10] I (852) cpu_start: ESP-IDF: 5.1.5
[2025-04-24 12:43:10] I (857) cpu_start: Min chip rev: v0.0
[2025-04-24 12:43:10] I (861) cpu_start: Max chip rev: v0.99
[2025-04-24 12:43:10] I (866) cpu_start: Chip rev: v0.2
[2025-04-24 12:43:10] I (871) heap_init: Initializing. RAM available for dynamic allocation:
[2025-04-24 12:43:10] I (878) heap_init: At 3FCA2A38 len 00046CD8 (283 KiB): DRAM
[2025-04-24 12:43:10] I (884) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DRAM
[2025-04-24 12:43:10] I (891) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
[2025-04-24 12:43:10] I (897) heap_init: At 600FE064 len 00001F84 (7 KiB): RTCRAM
[2025-04-24 12:43:10] I (904) esp_psram: Adding pool of 8192K of PSRAM memory to heap allocator
[2025-04-24 12:43:10] I (912) spi_flash: detected chip: generic
[2025-04-24 12:43:10] I (916) spi_flash: flash io: dio
[2025-04-24 12:43:10] I (920) sleep: Configure to isolate all GPIO pins in sleep state
[2025-04-24 12:43:10] I (926) sleep: Enable automatic switching of GPIO sleep configuration
[2025-04-24 12:43:10] I (934) app_start: Starting scheduler on CPU0
[2025-04-24 12:43:10] I (938) app_start: Starting scheduler on CPU1
[2025-04-24 12:43:10] I (938) main_task: Started on CPU0
[2025-04-24 12:43:10] I (948) main_task: Calling app_main()
[2025-04-24 12:43:10] [I][logger:171]: Log initialized
[2025-04-24 12:43:10] [C][safe_mode:079]: There have been 0 suspected unsuccessful boot attempts
[2025-04-24 12:43:10] [D][esp32.preferences:114]: Saving 1 preferences to flash...
[2025-04-24 12:43:10] [D][esp32.preferences:142]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[2025-04-24 12:43:10] [I][app:029]: Running through setup()...
[2025-04-24 12:43:10] [C][i2c.idf:021]: Setting up I2C bus...
[2025-04-24 12:43:10] [I][i2c.idf:260]: Performing I2C bus recovery
[2025-04-24 12:43:10] [D][esp-idf:000]: I (1065) gpio: GPIO[4]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000]: I (1071) gpio: GPIO[5]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [C][bh1750.sensor:041]: Setting up BH1750 'esp32s3-test BH1750 Illuminance'...
[2025-04-24 12:43:10] [C][wifi:048]: Setting up WiFi...
[2025-04-24 12:43:10] [D][esp-idf:000]: I (1099) pp: pp rom version: e7ae62f
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000]: I (1102) net80211: net80211 rom version: e7ae62f
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000]: I (1113) wifi:
[2025-04-24 12:43:10] [D][esp-idf:000]: wifi driver task: 3fcb3988, prio:23, stack:6656, core=0
[2025-04-24 12:43:10] [D][esp-idf:000]:
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: I (1154) wifi:
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: wifi firmware version: bbd58fc31
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: I (1154) wifi:
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: wifi certification version: v7.0
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: I (1159) wifi:
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: config NVS flash: enabled
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: I (1179) wifi:
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: config nano formating: disabled
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: I (1190) wifi:
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: Init data frame dynamic rx buffer num: 32
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: I (1210) wifi:
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: Init static rx mgmt buffer num: 5
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: I (1231) wifi:
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: Init management short buffer num: 32
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: I (1251) wifi:
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: Init dynamic tx buffer num: 32
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: I (1262) wifi:
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: Init tx cache buffer num: 32
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: I (1282) wifi:
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: Init static tx FG buffer num: 2
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: I (1302) wifi:
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: Init static rx buffer size: 1600
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: I (1313) wifi:
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: Init static rx buffer num: 10
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: I (1333) wifi:
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: Init dynamic rx buffer num: 32
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000]: I (1354) wifi_init: rx ba win: 6
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000]: I (1354) wifi_init: tcpip mbox: 32
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000]: I (1364) wifi_init: udp mbox: 6
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000]: I (1374) wifi_init: tcp mbox: 6
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000]: I (1374) wifi_init: tcp tx win: 5760
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000]: I (1384) wifi_init: tcp rx win: 5760
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000]: I (1384) wifi_init: tcp mss: 1440
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000]: I (1394) wifi_init: WiFi IRAM OP enabled
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000]: I (1405) wifi_init: WiFi RX IRAM OP enabled
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [C][wifi:061]: Starting WiFi...
[2025-04-24 12:43:10] [C][wifi:062]: Local MAC: 98:3D:AE:EB:24:F4
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: I (1416) phy_init: phy_version 680,a6008b2,Jun 4 2024,16:41:10
[2025-04-24 12:43:10]
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: I (1451) wifi:
[2025-04-24 12:43:10] [D][esp-idf:000][wifi]: mode : sta (98:3d:ae:eb:24:f4)
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:11]
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: I (1451) wifi:
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: enable tsf
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:11]
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: I (1467) wifi:
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: Set ps type: 1, coexist: 0
[2025-04-24 12:43:11]
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:11]
[2025-04-24 12:43:11] [D][wifi:760]: Loaded saved fast_connect wifi settings
[2025-04-24 12:43:11] [I][wifi:313]: WiFi Connecting to 'dagoba'...
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: W (1487) wifi:
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: Password length matches WPA2 standards, authmode threshold changes from OPEN to WPA2
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:11]
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: I (1508) wifi:
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: Set ps type: 1, coexist: 0
[2025-04-24 12:43:11]
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:11]
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: I (2058) wifi:
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: new:<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:11]
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: I (2059) wifi:
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: state: init -> auth (b0)
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:11]
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: I (2076) wifi:
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: state: auth -> assoc (0)
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:11]
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: I (2088) wifi:
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: state: assoc -> run (10)
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:11]
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: I (2114) wifi:
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: connected with dagoba, aid = 5, channel 1, BW20, bssid = 64:66:b3:ed:08:c4
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:11]
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: I (2115) wifi:
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: security: WPA2-PSK, phy: bgn, rssi: -62
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:11]
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: I (2135) wifi:
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: pm start, type: 1
[2025-04-24 12:43:11]
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:11]
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: I (2155) wifi:
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: dp: 1, bi: 102400, li: 3, scale listen interval from 307200 us to 307200 us
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:11]
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: I (2176) wifi:
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: set rx beacon pti, rx_bcn_pti: 0, bcn_timeout: 25000, mt_pti: 0, mt_time: 10000
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:11]
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: I (2197) wifi:
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]: AP's beacon interval = 102400 us, DTIM period = 1
[2025-04-24 12:43:11] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:11]
[2025-04-24 12:43:11] [D][esp-idf:000][sys_evt]: I (2219) esp_netif_handlers: sta ip: 192.168.1.124, mask: 255.255.255.0, gw: 192.168.1.1
[2025-04-24 12:43:11]
[2025-04-24 12:43:11] [D][esp-idf:000]: I (2228) mdns_mem: mDNS task will be created from internal RAM
[2025-04-24 12:43:11]
[2025-04-24 12:43:11] [C][api:026]: Setting up Home Assistant API server...
[2025-04-24 12:43:11] [D][on_boot:025]:
[2025-04-24 12:43:11] [D][on-boot:026]: #################### ON_BOOT ####################
[2025-04-24 12:43:11] [D][on_boot:027]: >>>>>> on_boot: initial values wakeup_cause=1070226904, wakeup_cause.state=-2147483648, num_wake_cycles=0
[2025-04-24 12:43:11] [D][main:033]: ##### on_boot finished
[2025-04-24 12:43:11] [C][deep_sleep:013]: Setting up Deep Sleep...
[2025-04-24 12:43:11] [I][deep_sleep:018]: Scheduling Deep Sleep to start in 300000 ms
[2025-04-24 12:43:11] [I][app:062]: setup() finished successfully!
[2025-04-24 12:43:11] [W][component:172]: Component wifi cleared Warning flag
[2025-04-24 12:43:11] [W][component:157]: Component api set Warning flag: unspecified
[2025-04-24 12:43:11] [I][app:100]: ESPHome version 2025.4.0 compiled on Apr 24 2025, 12:26:48
[2025-04-24 12:43:11] [C][wifi:600]: WiFi:
[2025-04-24 12:43:11] [C][wifi:428]: Local MAC: 98:3D:AE:EB:24:F4
[2025-04-24 12:43:11] [C][wifi:433]: SSID: 'dagoba'
[2025-04-24 12:43:11] [C][wifi:436]: IP Address: 192.168.1.124
[2025-04-24 12:43:11] [C][wifi:439]: BSSID: 64:66:B3:ED:08:C4
[2025-04-24 12:43:11] [C][wifi:441]: Hostname: 'esp32s3-test'
[2025-04-24 12:43:11] [C][wifi:443]: Signal strength: -62 dB ▂▄▆█
[2025-04-24 12:43:11] [C][wifi:447]: Channel: 1
[2025-04-24 12:43:11] [C][wifi:448]: Subnet: 255.255.255.0
[2025-04-24 12:43:11] [C][wifi:449]: Gateway: 192.168.1.1
[2025-04-24 12:43:11] [C][wifi:450]: DNS1: 0.0.0.0
[2025-04-24 12:43:11] [C][wifi:451]: DNS2: 0.0.0.0
[2025-04-24 12:43:11] [C][logger:177]: Logger:
[2025-04-24 12:43:11] [C][logger:178]: Max Level: DEBUG
[2025-04-24 12:43:11] [C][logger:179]: Initial Level: DEBUG
[2025-04-24 12:43:11] [C][logger:181]: Log Baud Rate: 115200
[2025-04-24 12:43:11] [C][logger:182]: Hardware UART: UART0
[2025-04-24 12:43:11] [C][i2c.idf:083]: I2C Bus:
[2025-04-24 12:43:11] [C][i2c.idf:084]: SDA Pin: GPIO5
[2025-04-24 12:43:11] [C][i2c.idf:085]: SCL Pin: GPIO4
[2025-04-24 12:43:11] [C][i2c.idf:086]: Frequency: 400000 Hz
[2025-04-24 12:43:11] [C][i2c.idf:092]: Recovery: bus successfully recovered
[2025-04-24 12:43:11] [I][i2c.idf:102]: Results from i2c bus scan:
[2025-04-24 12:43:11] [I][i2c.idf:108]: Found i2c device at address 0x23
[2025-04-24 12:43:11] [C][template.sensor:022]: Template Sensor 'esp32s3-test Wakeup cause'
[2025-04-24 12:43:11] [C][template.sensor:022]: State Class: ''
[2025-04-24 12:43:11] [C][template.sensor:022]: Unit of Measurement: ''
[2025-04-24 12:43:11] [C][template.sensor:022]: Accuracy Decimals: 0
[2025-04-24 12:43:11] [C][template.sensor:023]: Update Interval: 120.0s
[2025-04-24 12:43:12] [C][psram:017]: PSRAM:
[2025-04-24 12:43:12] [C][psram:021]: Available: YES
[2025-04-24 12:43:12] [C][psram:023]: Size: 8192 KB
[2025-04-24 12:43:12] [C][bh1750.sensor:118]: BH1750 'esp32s3-test BH1750 Illuminance'
[2025-04-24 12:43:12] [C][bh1750.sensor:118]: Device Class: 'illuminance'
[2025-04-24 12:43:12] [C][bh1750.sensor:118]: State Class: 'measurement'
[2025-04-24 12:43:12] [C][bh1750.sensor:118]: Unit of Measurement: 'lx'
[2025-04-24 12:43:12] [C][bh1750.sensor:118]: Accuracy Decimals: 1
[2025-04-24 12:43:12] [C][bh1750.sensor:119]: Address: 0x23
[2025-04-24 12:43:12] [C][bh1750.sensor:124]: Update Interval: 120.0s
[2025-04-24 12:43:12] [C][web_server:285]: Web Server:
[2025-04-24 12:43:12] [C][web_server:286]: Address: 192.168.1.124:80
[2025-04-24 12:43:12] [C][mdns:116]: mDNS:
[2025-04-24 12:43:12] [C][mdns:117]: Hostname: esp32s3-test
[2025-04-24 12:43:12] [C][esphome.ota:073]: Over-The-Air updates:
[2025-04-24 12:43:12] [C][esphome.ota:074]: Address: 192.168.1.124:3232
[2025-04-24 12:43:12] [C][esphome.ota:075]: Version: 2
[2025-04-24 12:43:12] [C][safe_mode:018]: Safe Mode:
[2025-04-24 12:43:12] [C][safe_mode:019]: Boot considered successful after 60 seconds
[2025-04-24 12:43:12] [C][safe_mode:021]: Invoke after 10 boot attempts
[2025-04-24 12:43:12] [C][safe_mode:022]: Remain in safe mode for 300 seconds
[2025-04-24 12:43:12] [C][api:140]: API Server:
[2025-04-24 12:43:12] [C][api:141]: Address: 192.168.1.124:6053
[2025-04-24 12:43:12] [C][api:143]: Using noise encryption: YES
[2025-04-24 12:43:12] [C][wifi_signal.sensor:010]: WiFi Signal 'esp32s3-test Wifi signal'
[2025-04-24 12:43:12] [C][wifi_signal.sensor:010]: Device Class: 'signal_strength'
[2025-04-24 12:43:12] [C][wifi_signal.sensor:010]: State Class: 'measurement'
[2025-04-24 12:43:12] [C][wifi_signal.sensor:010]: Unit of Measurement: 'dBm'
[2025-04-24 12:43:12] [C][wifi_signal.sensor:010]: Accuracy Decimals: 0
[2025-04-24 12:43:12] [C][deep_sleep:026]: Setting up Deep Sleep...
[2025-04-24 12:43:12] [C][deep_sleep:029]: Sleep Duration: 180000 ms
[2025-04-24 12:43:12] [C][deep_sleep:032]: Run Duration: 300000 ms
[2025-04-24 12:43:12] [D][esp-idf:000][wifi]: I (3440) wifi:
[2025-04-24 12:43:12] [D][esp-idf:000][wifi]: <ba-add>idx:0 (ifx:0, 64:66:b3:ed:08:c4), tid:0, ssn:0, winSize:64
[2025-04-24 12:43:12] [D][esp-idf:000][wifi]:
[2025-04-24 12:43:12]
[2025-04-24 12:43:12] [D][api:103]: Accepted 192.168.1.98
[2025-04-24 12:43:12] [D][api:103]: Accepted 192.168.1.98
[2025-04-24 12:43:13] [W][component:172]: Component api cleared Warning flag
[2025-04-24 12:43:13] [W][component:239]: Component api took a long time for an operation (86 ms).
[2025-04-24 12:43:13] [W][component:240]: Components should block for at most 30 ms.
[2025-04-24 12:43:13] [D][api.connection:1801]: Home Assistant 2025.4.2 (192.168.1.98): Connected successfully
[2025-04-24 12:43:13] [D][api.connection:1801]: ESPHome Logs 2025.4.0 (192.168.1.98): Connected successfully
[2025-04-24 12:43:15] [D][wakeup_cause:057]: >>>> X >>>> esp_sleep_get_wakeup_cause()=4, wakeup_cause=1070226904, wakeup_cause.state=0, num_wake_cycles=2146
959360
[2025-04-24 12:43:15] [D][main:423]: logger >>>> C >>>> wakeup_cause=1070226904, wakeup_cause.state=-2147483648, num_wake_cycles=0, x=2146959360
[2025-04-24 12:43:15] [D][wakeup_cause:066]: >>>> D >>>> wakeup_cause=1070226904, wakeup_cause.state=-2147483648, num_wake_cycles=0, x=2146959360
[2025-04-24 12:43:15] [D][sensor:093]: 'esp32s3-test Wakeup cause': Sending state 4.00000 with 0 decimals of accuracy
The X line shows shows that the esp_sleep_get_wakeup_cause() function returns a 4 to indicate that the ESP32 was woken by the timer after a deep_sleep, and num_wake_cycles has changed. The next line in the yaml returns the esp_sleep_get_wakeup_cause() into the wakeup_cause template sensor.
The C and D lines indicate that the on_raw_value: clause is then executed … and the same values are reported by both. ESPHome docs state that the sensor reading is stored in ‘x’ while we are executing filters and other processing … however ‘x’ is instead now storing what was in my global num_wake_cycles !
to continue …
[2025-04-24 12:43:17] [D][sensor:093]: 'esp32s3-test Wifi signal': Sending state -62.00000 dBm with 0 decimals of accuracy
[2025-04-24 12:43:34] [D][esp32.preferences:114]: Saving 1 preferences to flash...
[2025-04-24 12:43:34] [D][esp32.preferences:142]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[2025-04-24 12:43:51] [D][bh1750.sensor:159]: 'esp32s3-test BH1750 Illuminance': Got illuminance=7.1lx
[2025-04-24 12:43:51] [D][main:062]: logger >>>> E >>>> wakeup_cause=1070226904, wakeup_cause.state=-16777216, num_wake_cycles=0
[2025-04-24 12:43:51] [D][BH1750:079]: >>>> F >>>> wakeup_cause=1070226904, wakeup_cause.state=3, num_wake_cycles=0
[2025-04-24 12:43:51] [D][sensor:093]: 'esp32s3-test BH1750 Illuminance': Sending state 7.13090 lx with 1 decimals of accuracy
I added a couple of print statements into the unrelated BH1750 sensor’s yaml just to detect the situation after the wakeup_cause sensor completed. My guess is that large number in id(wakeup_cause)
is a pointer to either the memory location of the value, or to the esp_sleep_get_wakeup_cause() function, and so id(wakeup_cause).state
will be the value of the sensor - but why is the id().state
value reported differently by logger.log and ESP_LOGD() ?
[2025-04-24 12:44:10] [I][safe_mode:041]: Boot seems successful; resetting boot loop counter
[2025-04-24 12:44:10] [D][esp32.preferences:114]: Saving 1 preferences to flash...
[2025-04-24 12:44:10] [D][esp32.preferences:142]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[2025-04-24 12:45:15] [D][wakeup_cause:057]: >>>> X >>>> esp_sleep_get_wakeup_cause()=4, wakeup_cause=1070226904, wakeup_cause.state=0, num_wake_cycles=1074
790400
[2025-04-24 12:45:15] [D][main:423]: logger >>>> C >>>> wakeup_cause=1070226904, wakeup_cause.state=153, num_wake_cycles=0, x=1074790400
[2025-04-24 12:45:15] [D][wakeup_cause:066]: >>>> D >>>> wakeup_cause=1070226904, wakeup_cause.state=1070179868, num_wake_cycles=0, x=1074790400
[2025-04-24 12:45:15] [D][sensor:093]: 'esp32s3-test Wakeup cause': Sending state 4.00000 with 0 decimals of accuracy
[2025-04-24 12:45:17] [D][sensor:093]: 'esp32s3-test Wifi signal': Sending state -62.00000 dBm with 0 decimals of accuracy
[2025-04-24 12:45:51] [D][bh1750.sensor:159]: 'esp32s3-test BH1750 Illuminance': Got illuminance=7.5lx
[2025-04-24 12:45:51] [D][main:062]: logger >>>> E >>>> wakeup_cause=1070226904, wakeup_cause.state=-16777216, num_wake_cycles=0
[2025-04-24 12:45:51] [D][BH1750:079]: >>>> F >>>> wakeup_cause=1070226904, wakeup_cause.state=0, num_wake_cycles=0
[2025-04-24 12:45:51] [D][sensor:093]: 'esp32s3-test BH1750 Illuminance': Sending state 7.47047 lx with 1 decimals of accuracy
[2025-04-24 12:47:15] [D][wakeup_cause:057]: >>>> X >>>> esp_sleep_get_wakeup_cause()=4, wakeup_cause=1070226904, wakeup_cause.state=0, num_wake_cycles=1074
790400
[2025-04-24 12:47:15] [D][main:423]: logger >>>> C >>>> wakeup_cause=1070226904, wakeup_cause.state=153, num_wake_cycles=0, x=1074790400
[2025-04-24 12:47:15] [D][wakeup_cause:066]: >>>> D >>>> wakeup_cause=1070226904, wakeup_cause.state=1070179868, num_wake_cycles=0, x=1074790400
[2025-04-24 12:47:15] [D][sensor:093]: 'esp32s3-test Wakeup cause': Sending state 4.00000 with 0 decimals of accuracy
[2025-04-24 12:47:17] [D][sensor:093]: 'esp32s3-test Wifi signal': Sending state -62.00000 dBm with 0 decimals of accuracy
[2025-04-24 12:47:51] [D][bh1750.sensor:159]: 'esp32s3-test BH1750 Illuminance': Got illuminance=8.0lx
[2025-04-24 12:47:51] [D][main:062]: logger >>>> E >>>> wakeup_cause=1070226904, wakeup_cause.state=-16777216, num_wake_cycles=0
[2025-04-24 12:47:51] [D][BH1750:079]: >>>> F >>>> wakeup_cause=1070226904, wakeup_cause.state=0, num_wake_cycles=0
[2025-04-24 12:47:51] [D][sensor:093]: 'esp32s3-test BH1750 Illuminance': Sending state 8.03642 lx with 1 decimals of accuracy
[2025-04-24 12:48:11] [I][deep_sleep:060]: Beginning Deep Sleep
[2025-04-24 12:48:11] [I][deep_sleep:062]: Sleeping for 180000000us
[2025-04-24 12:48:11] [D][esp32.preferences:114]: Saving 1 preferences to flash...
[2025-04-24 12:48:11] [D][esp32.preferences:142]: Saving 1 preferences to flash: 1 cached, 0 written, 0 failed
[2025-04-24 12:48:11] [D][on_shutdown:037]:
[2025-04-24 12:48:11] [D][on_shutdown:038]: >>>> A >>>> wakeup_cause=1070226904, wakeup_cause.state=1070528852, num_wake_cycles=0
[2025-04-24 12:48:11] [D][main:042]: logger >>>> B >>>> wakeup_cause=1070226904, wakeup_cause.state=-1287651329, num_wake_cycles=0
and the same repeats for the next awake cycle.