I am working on an ESP32-S3 devkit board for a greenhouse, so I want to use deep sleep and tried merging bits of @Mahko_Mahko’s code … and things got rather weird. Almost all the log messages disappeared, except for a few about seep sleep starting and starting being successful, and a whole pile of ones about JSON.
So I have gone back and reduced the number of sensors and comments in my code to make it easier to debug, added some debugging logger.log actions, used the built-in LED to indicate program status, cleaned the build files, and physically powered off my ESP32 before loading the program below … but issues now are:
- actions in the on_boot do not appear to have been actioned
- my logger.log actions (starting ####) are not showing in the log
- Are the lines “Attempting to allocate 512 bytes for JSON serialization” expected from verbose logging, or do they indicate a problem. I note that flash usage has jumped from around 18% to 71%.
- why the delays from 20:23 to 20:32, 20:32 to 20:34, 20:34 to 20:39 ? It looks as though ESPHome is deliberately spacing its processing out to fill the update_interval.
#
# To control the greenhouse I have an ESP32-S3-DevKitC-1 (v1) board
#
# THIS FILE SERIOUSLY CUT DOWN FOR EASE OF DEBUGGING !!!
substitutions:
devicename: "greenhouse"
deviceIP: "97" # last octet of the IP Address
wifi_ssid: !secret upstairs_ssid ### which wi-fi to connect to
wifi_password: !secret upstairs_password
update_interval_network: "30 min" # How often to measure and report network values
update_interval_sensor: "15 min" # How often to measure and report other values
sleep_run_duration: "5 min" # how long to run (be awake)
sleep_duration: $update_interval_sensor # how long to sleep for
packages:
wi-fi: !include _common_wifi.yaml
# Enable logging
logger:
level: VERBOSE # DEBUG
esphome:
name: $devicename
platformio_options:
board_build.flash_mode: dio
on_boot:
- priority: -100 # everything has been set up
then:
# enable all the peripheral sensors
- logger.log: "##### on_boot started"
- light.turn_on:
id: rgb_led
red: 0%
blue: 50%
green: 50%
brightness: 20%
- logger.log: "....Starting sensor updates"
preferences:
flash_write_interval: 60min
esp32:
board: adafruit_feather_esp32s3 # esp32-s3-devkitc-1
variant: esp32s3
flash_size: 16mb
framework:
type: arduino
psram: # but PSRAM is NOT being accepted !
mode: octal
speed: 80MHz
#
# The RGB LED is built into the board
#
light:
- platform: esp32_rmt_led_strip
name: $devicename RGB LED
id: rgb_led
rgb_order: GRB
pin: GPIO48
num_leds: 1
rmt_channel: 0
chipset: ws2812
# hardware configuration
i2c:
- id: bus_a
sda: GPIO1
scl: GPIO2
scan: true
frequency: 400kHz
###################################################################
# #
# Place the ESP32 in Deep Sleep between sensor readings #
# #
###################################################################
#deep_sleep:
# #Auto deep sleep shouldn't actually get used if data updates are happening properly (should sleep sooner).
# #But if something is wrong with data updates this will kick-in to protect battery discharge.
# id: deep_sleep_1
# run_duration: $sleep_run_duration # how long to run (be awake)
# sleep_duration: $sleep_duration # how long to sleep for
# wake up if it starts raining while asleep
# wakeup_pin: GPIO21 # wake up if a rain gauge pulse is detected
# wakeup_pin_mode: KEEP_AWAKE # stay awake if rain is happening when otherise would sleep
switch:
- platform: gpio
id: relay_solar
name: $devicename Solar Power relay
pin: GPIO9
restore_mode: ALWAYS_ON # Solar Power on when waking from sleep.
# Control peripheral power (on solar power manager)
# DFRobot solar power manager can turn on/off the 5V header pins,
# making them ideal for powering sensors from
- platform: gpio
id: peripheral_power
name: $devicename peripheral power
pin: GPIO47
restore_mode: ALWAYS_ON #Power on when waking from sleep.
sensor:
# # DHT22 is also available
- platform: dht
model: DHT22
pin: GPIO5
temperature:
name: $devicename DHT22 Temperature
humidity:
name: $devicename DHT22 Humidity
update_interval: $update_interval_sensor
# lux sensor to detect sun or storm, day or night
- platform: bh1750
name: $devicename BH1750 Illuminance
address: 0x23
update_interval: $update_interval_sensor
# Power Module sensors #
# MAX1704x is specifically for Li-ON battery
# My board is a MAX14048, but seems functionally a MAX17043
# (adafruit driver available) but with a few extra unimplemented features
- platform: max17043
id: i2c_max17048
battery_level:
name: "Max17048 Battery level"
battery_voltage:
name: "MAX17048 Battery Voltage"
id: batt_voltage
on_value_range:
- above: 4.1 # battery fully charged
then:
- logger.log: "##### battery is full charge 4.1v"
- switch.turn_off: relay_solar #- switch.turn_off: solarPanel
- below: 3.3 # battery is running low
then:
- logger.log: "##### battery is LOW charge 3.3v"
# raise an alarm / notification / email
- switch.turn_off: peripheral_power # turn off all the sensors until power is restored
update_interval: $update_interval_sensor
resulted in:
Linking .pioenvs/greenhouse/firmware.elf
RAM: [== ] 15.1% (used 49576 bytes from 327680 bytes)
Flash: [======= ] 70.9% (used 1022829 bytes from 1441792 bytes)
Building .pioenvs/greenhouse/firmware.bin
Creating esp32s3 image...
Successfully created esp32s3 image.
esp32_create_combined_bin([".pioenvs/greenhouse/firmware.bin"], [".pioenvs/greenhouse/firmware.elf"])
Wrote 0x109cf0 bytes to file /data/build/greenhouse/.pioenvs/greenhouse/firmware.factory.bin, ready to flash to offset 0x0
esp32_copy_ota_bin([".pioenvs/greenhouse/firmware.bin"], [".pioenvs/greenhouse/firmware.elf"])
========================= [SUCCESS] Took 57.89 seconds =========================
INFO Successfully compiled program.
INFO Connecting to 192.168.1.97 port 3232...
INFO Connected to 192.168.1.97
INFO Uploading /data/build/greenhouse/.pioenvs/greenhouse/firmware.bin (1023216 bytes)
Uploading: [============================================================] 100% Done...
INFO Upload took 10.74 seconds, waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from 192.168.1.97 using esphome API
INFO Successfully connected to greenhouse @ 192.168.1.97 in 3.124s
INFO Successful handshake with greenhouse @ 192.168.1.97 in 0.091s
[20:22:41][I][app:100]: ESPHome version 2024.12.4 compiled on Feb 2 2025, 20:22:03
[20:22:41][C][wifi:600]: WiFi:
[20:22:41][C][wifi:428]: Local MAC: 98:3D:AE:EB:24:F4
[20:22:41][C][wifi:433]: SSID: [redacted]
[20:22:41][C][wifi:436]: IP Address: 192.168.1.97
[20:22:41][C][wifi:440]: BSSID: [redacted]
[20:22:41][C][wifi:441]: Hostname: 'greenhouse'
[20:22:41][C][wifi:443]: Signal strength: -66 dB ▂▄▆█
[20:22:41][C][wifi:447]: Channel: 13
[20:22:41][C][wifi:448]: Subnet: 255.255.255.0
[20:22:41][C][wifi:449]: Gateway: 192.168.1.1
[20:22:41][C][wifi:450]: DNS1: 0.0.0.0
[20:22:41][C][wifi:451]: DNS2: 0.0.0.0
[20:22:41][C][logger:185]: Logger:
[20:22:41][C][logger:186]: Level: VERBOSE
[20:22:41][C][logger:188]: Log Baud Rate: 115200
[20:22:41][C][logger:189]: Hardware UART: USB_CDC
[20:22:41][C][i2c.arduino:071]: I2C Bus:
[20:22:41][C][i2c.arduino:072]: SDA Pin: GPIO1
[20:22:41][C][i2c.arduino:073]: SCL Pin: GPIO2
[20:22:41][C][i2c.arduino:074]: Frequency: 400000 Hz
[20:22:41][C][i2c.arduino:086]: Recovery: bus successfully recovered
[20:22:41][I][i2c.arduino:096]: Results from i2c bus scan:
[20:22:41][I][i2c.arduino:102]: Found i2c device at address 0x23
[20:22:41][I][i2c.arduino:102]: Found i2c device at address 0x36
[20:22:41][I][i2c.arduino:102]: Found i2c device at address 0x40
[20:22:42][I][i2c.arduino:102]: Found i2c device at address 0x45
[20:22:42][I][i2c.arduino:102]: Found i2c device at address 0x48
[20:22:42][C][template.text_sensor:020]: Template Sensor 'greenhouse Uptime Human Readable'
[20:22:42][C][template.text_sensor:020]: Icon: 'mdi:clock-start'
[20:22:42][C][esp32_rmt_led_strip:187]: ESP32 RMT LED Strip:
[20:22:42][C][esp32_rmt_led_strip:188]: Pin: 48
[20:22:42][C][esp32_rmt_led_strip:189]: Channel: 0
[20:22:42][C][esp32_rmt_led_strip:214]: RGB Order: GRB
[20:22:42][C][esp32_rmt_led_strip:215]: Max refresh rate: 0
[20:22:42][C][esp32_rmt_led_strip:216]: Number of LEDs: 1
[20:22:42][C][switch.gpio:068]: GPIO Switch 'greenhouse Solar Power relay'
[20:22:42][C][switch.gpio:091]: Restore Mode: always ON
[20:22:42][C][switch.gpio:031]: Pin: GPIO9
[20:22:42][C][switch.gpio:068]: GPIO Switch 'greenhouse peripheral power'
[20:22:42][C][switch.gpio:091]: Restore Mode: always ON
[20:22:42][C][switch.gpio:031]: Pin: GPIO47
[20:22:42][C][uptime.sensor:033]: Uptime Sensor 'greenhouse Uptime'
[20:22:42][C][uptime.sensor:033]: Device Class: 'duration'
[20:22:42][C][uptime.sensor:033]: State Class: 'total_increasing'
[20:22:42][C][uptime.sensor:033]: Unit of Measurement: 's'
[20:22:42][C][uptime.sensor:033]: Accuracy Decimals: 0
[20:22:42][C][uptime.sensor:033]: Icon: 'mdi:timer-outline'
[20:22:42][V][uptime.sensor:033]: Unique ID: '983daeeb24f4-uptime'
[20:22:42][C][uptime.sensor:034]: Type: Seconds
[20:22:42][C][light:092]: Light 'greenhouse RGB LED'
[20:22:42][C][light:094]: Default Transition Length: 1.0s
[20:22:42][C][light:095]: Gamma Correct: 2.80
[20:22:42][C][dht:017]: DHT:
[20:22:42][C][dht:018]: Pin: GPIO5
[20:22:42][C][dht:024]: Model: DHT22 (or equivalent)
[20:22:42][C][dht:027]: Update Interval: 900.0s
[20:22:42][C][dht:029]: Temperature 'greenhouse DHT22 Temperature'
[20:22:42][C][dht:029]: Device Class: 'temperature'
[20:22:42][C][dht:029]: State Class: 'measurement'
[20:22:42][C][dht:029]: Unit of Measurement: '°C'
[20:22:42][C][dht:029]: Accuracy Decimals: 1
[20:22:42][C][dht:030]: Humidity 'greenhouse DHT22 Humidity'
[20:22:42][C][dht:030]: Device Class: 'humidity'
[20:22:42][C][dht:030]: State Class: 'measurement'
[20:22:42][C][dht:030]: Unit of Measurement: '%'
[20:22:42][C][dht:030]: Accuracy Decimals: 0
[20:22:42][C][bh1750.sensor:118]: BH1750 'greenhouse BH1750 Illuminance'
[20:22:42][C][bh1750.sensor:118]: Device Class: 'illuminance'
[20:22:42][C][bh1750.sensor:118]: State Class: 'measurement'
[20:22:42][C][bh1750.sensor:118]: Unit of Measurement: 'lx'
[20:22:42][C][bh1750.sensor:118]: Accuracy Decimals: 1
[20:22:42][C][bh1750.sensor:119]: Address: 0x23
[20:22:42][C][bh1750.sensor:124]: Update Interval: 900.0s
[20:22:42][C][max17043:076]: MAX17043:
[20:22:42][C][max17043:077]: Address: 0x36
[20:22:42][C][max17043:081]: Update Interval: 900.0s
[20:22:42][C][max17043:082]: Battery Voltage 'MAX17048 Battery Voltage'
[20:22:42][C][max17043:082]: Device Class: 'voltage'
[20:22:42][C][max17043:082]: State Class: 'measurement'
[20:22:42][C][max17043:082]: Unit of Measurement: 'V'
[20:22:42][C][max17043:082]: Accuracy Decimals: 3
[20:22:42][C][max17043:083]: Battery Level 'Max17048 Battery level'
[20:22:42][C][max17043:083]: Device Class: 'battery'
[20:22:42][C][max17043:083]: State Class: 'measurement'
[20:22:42][C][max17043:083]: Unit of Measurement: '%'
[20:22:42][C][max17043:083]: Accuracy Decimals: 3
[20:22:42][C][version.text_sensor:021]: Version Text Sensor 'greenhouse ESPHome Version'
[20:22:42][C][version.text_sensor:021]: Icon: 'mdi:new-box'
[20:22:42][V][version.text_sensor:021]: Unique ID: '983daeeb24f4-version'
[20:22:42][C][wifi_info:014]: WifiInfo Mac Address 'greenhouse Wifi MAC Address'
[20:22:42][V][wifi_info:014]: Unique ID: '983daeeb24f4-wifiinfo-macadr'
[20:22:42][C][psram:020]: PSRAM:
[20:22:42][C][psram:021]: Available: NO
[20:22:42][C][captive_portal:089]: Captive Portal:
[20:22:42][C][web_server:153]: Web Server:
[20:22:42][C][web_server:154]: Address: 192.168.1.97:80
[20:22:42][C][sntp:042]: SNTP Time:
[20:22:42][C][sntp:045]: Server 0: '0.pool.ntp.org'
[20:22:42][C][sntp:045]: Server 1: '1.pool.ntp.org'
[20:22:42][C][sntp:045]: Server 2: '2.pool.ntp.org'
[20:22:42][C][mdns:116]: mDNS:
[20:22:42][C][mdns:117]: Hostname: greenhouse
[20:22:42][V][mdns:118]: Services:
[20:22:42][V][mdns:120]: - _esphomelib, _tcp, 6053
[20:22:42][V][mdns:122]: TXT: version = 2024.12.4
[20:22:42][V][mdns:122]: TXT: mac = 983daeeb24f4
[20:22:42][V][mdns:122]: TXT: platform = ESP32
[20:22:42][V][mdns:122]: TXT: board = adafruit_feather_esp32s3
[20:22:42][V][mdns:122]: TXT: network = wifi
[20:22:42][V][mdns:122]: TXT: api_encryption = Noise_NNpsk0_25519_ChaChaPoly_SHA256
[20:22:42][V][mdns:120]: - _http, _tcp, 80
[20:22:42][C][esphome.ota:073]: Over-The-Air updates:
[20:22:42][C][esphome.ota:074]: Address: 192.168.1.97:3232
[20:22:42][C][esphome.ota:075]: Version: 2
[20:22:42][C][safe_mode:018]: Safe Mode:
[20:22:42][C][safe_mode:020]: Boot considered successful after 60 seconds
[20:22:42][C][safe_mode:021]: Invoke after 10 boot attempts
[20:22:42][C][safe_mode:023]: Remain in safe mode for 300 seconds
[20:22:42][C][api:140]: API Server:
[20:22:42][C][api:141]: Address: 192.168.1.97:6053
[20:22:42][C][api:143]: Using noise encryption: YES
[20:22:42][D][api:103]: Accepted 192.168.1.98
[20:22:42][C][wifi_signal.sensor:010]: WiFi Signal 'greenhouse Wifi signal'
[20:22:42][C][wifi_signal.sensor:010]: Device Class: 'signal_strength'
[20:22:42][C][wifi_signal.sensor:010]: State Class: 'measurement'
[20:22:42][C][wifi_signal.sensor:010]: Unit of Measurement: 'dBm'
[20:22:42][C][wifi_signal.sensor:010]: Accuracy Decimals: 0
[20:22:42][V][wifi_signal.sensor:010]: Unique ID: '983daeeb24f4-wifisignal'
[20:22:42][V][api.connection:1428]: Hello from client: 'Home Assistant 2025.1.3' | 192.168.1.98 | API Version 1.10
[20:22:42][C][wifi_info:012]: WifiInfo SSID 'greenhouse Wifi connected to SSID'
[20:22:42][V][wifi_info:012]: Unique ID: '983daeeb24f4-wifiinfo-ssid'
[20:22:42][D][api.connection:1446]: Home Assistant 2025.1.3 (192.168.1.98): Connected successfully
[20:22:42][C][wifi_info:010]: WifiInfo IPAddress 'greenhouse Wifi IP Address'
[20:22:42][V][wifi_info:010]: Unique ID: '983daeeb24f4-wifiinfo-ip'
[20:23:38][I][safe_mode:041]: Boot seems successful; resetting boot loop counter
[20:23:38][D][esp32.preferences:114]: Saving 3 preferences to flash...
[20:23:38][V][esp32.preferences:126]: sync: key: 233825507, len: 4
[20:23:38][V][esp32.preferences:163]: nvs_get_blob('3978338398'): ESP_ERR_NVS_NOT_FOUND - the key might not be set yet
[20:23:38][V][esp32.preferences:126]: sync: key: 3978338398, len: 7
[20:23:38][V][esp32.preferences:137]: NVS data not changed skipping 2523860430 len=1
[20:23:38][D][esp32.preferences:143]: Saving 3 preferences to flash: 1 cached, 2 written, 0 failed
[20:23:52][V][json:038][async_tcp]: Attempting to allocate 512 bytes for JSON serialization
[20:23:52][V][json:058][async_tcp]: Size after shrink 92 bytes
[20:23:52][V][json:038]: Attempting to allocate 512 bytes for JSON serialization
[20:23:52][V][json:058]: Size after shrink 236 bytes
[20:23:53][V][json:038]: Attempting to allocate 512 bytes for JSON serialization
[20:23:53][V][json:058]: Size after shrink 156 bytes
[20:23:53][V][json:038]: Attempting to allocate 512 bytes for JSON serialization
[20:23:53][V][json:058]: Size after shrink 164 bytes
[20:23:53][V][json:038]: Attempting to allocate 512 bytes for JSON serialization
[20:23:53][V][json:058]: Size after shrink 164 bytes
At this point the LED is blue, and there is a pause in the log.
I then noticed that the [View] page’s log shows some different messages … though I assume the entries at 20:22 are before the new firmware booted.
Time level Tag Message
20:22:37 [I] [app:132] Rebooting safely...
20:22:37 [D] [esp32.preferences:114] Saving 1 preferences to flash...
20:22:37 [V] [esp32.preferences:137] NVS data not changed skipping 233825507 len=4
20:22:37 [D] [esp32.preferences:143] Saving 1 preferences to flash: 1 cached, 0 written, 0 failed
20:22:37 [D] [main:988] #### Turning off peripheral power...
20:22:37 [D] [light:036] 'greenhouse RGB LED' Setting:
20:22:37 [D] [light:047] State: OFF
20:22:37 [D] [light:085] Transition length: 1.0s
20:22:37 [V] [json:038] Attempting to allocate 512 bytes for JSON serialization
20:22:37 [V] [json:058] Size after shrink 176 bytes
20:22:37 [D] [main:974] ##### on_shutdown started
20:22:37 [D] [light:036] 'greenhouse RGB LED' Setting:
20:22:37 [D] [light:047] State: ON
20:22:37 [D] [light:051] Brightness: 20%
20:22:37 [D] [light:059] Red: 100%, Green: 0%, Blue: 0%
20:22:37 [D] [light:085] Transition length: 1.0s
20:22:37 [V] [json:038] Attempting to allocate 512 bytes for JSON serialization
20:22:37 [V] [json:058] Size after shrink 176 bytes
20:23:52 [V] [json:038]e[1;31m[async_tcp]e[0;37m Attempting to allocate 512 bytes for JSON serialization
20:23:52 [V] [json:058]e[1;31m[async_tcp]e[0;37m Size after shrink 92 bytes
at 20:32 both logs resumed
[20:32:51][D][dht:048]: Got Temperature=29.6°C Humidity=59.1%
[20:32:51][V][sensor:043]: 'greenhouse DHT22 Temperature': Received new state 29.600000
[20:32:51][D][sensor:094]: 'greenhouse DHT22 Temperature': Sending state 29.60000 °C with 1 decimals of accuracy
[20:32:51][V][json:038]: Attempting to allocate 512 bytes for JSON serialization
[20:32:51][V][json:058]: Size after shrink 96 bytes
[20:32:51][V][sensor:043]: 'greenhouse DHT22 Humidity': Received new state 59.100002
[20:32:51][D][sensor:094]: 'greenhouse DHT22 Humidity': Sending state 59.10000 % with 0 decimals of accuracy
[20:32:51][V][json:038]: Attempting to allocate 512 bytes for JSON serialization
[20:32:51][V][json:058]: Size after shrink 88 bytes
[20:32:51][W][component:237]: Component dht.sensor took a long time for an operation (98 ms).
[20:32:51][W][component:238]: Components should block for at most 30 ms.
[20:34:18][V][sensor:043]: 'MAX17048 Battery Voltage': Received new state 3.892500
[20:34:18][D][sensor:094]: 'MAX17048 Battery Voltage': Sending state 3.89250 V with 3 decimals of accuracy
[20:34:18][V][json:038]: Attempting to allocate 512 bytes for JSON serialization
[20:34:18][V][json:058]: Size after shrink 88 bytes
[20:34:18][V][sensor:043]: 'Max17048 Battery level': Received new state 66.000000
[20:34:18][D][sensor:094]: 'Max17048 Battery level': Sending state 66.00000 % with 3 decimals of accuracy
[20:34:18][V][json:038]: Attempting to allocate 512 bytes for JSON serialization
[20:34:18][V][json:058]: Size after shrink 88 bytes
[20:34:18][W][component:237]: Component max17043.sensor took a long time for an operation (96 ms).
[20:34:18][W][component:238]: Components should block for at most 30 ms.
[20:34:19][V][bh1750.sensor:151]: L result: 7.419355 -> Calculated mode=2, mtreg=254
[20:34:19][D][bh1750.sensor:159]: 'greenhouse BH1750 Illuminance': Got illuminance=6.5lx
[20:34:19][V][sensor:043]: 'greenhouse BH1750 Illuminance': Received new state 6.451771
[20:34:19][D][sensor:094]: 'greenhouse BH1750 Illuminance': Sending state 6.45177 lx with 1 decimals of accuracy
[20:34:19][V][json:038]: Attempting to allocate 512 bytes for JSON serialization
[20:34:19][V][json:058]: Size after shrink 92 bytes
[20:34:19][W][component:237]: Component bh1750.sensor took a long time for an operation (56 ms).
[20:34:19][W][component:238]: Components should block for at most 30 ms.