ESP8266 reads correct value of Binary Helper; ESP32 does not

I have 2 nodes, one an ESP32 and the other an ESP8266 running the exact same script below:

# 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

# 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:
            - logger.log: 'Binary Helper Enabled!'
          else:
            - logger.log: 'Binary Helper NOT Enabled'
      - script.execute: consider_deep_sleep

The ESP8266 (right) reads the correct value, but the ESP32 (left) always reads it as off.

I didn’t see anything in the logs that would suggest any issues (i’m a newbie to ESPHome). Is there any reason why the ESP32 doesn’t read the correct value?

Please please please stop posting pictures of text files.

And please post the complete log for each one. And the yaml.

But we might, that’s why you’re posting here, for help right? So help us to help you.

Here’s the log from the ESP8266:

INFO Reading configuration /config/esphome/car-battery-monitor.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing car-battery-monitor (board: d1_mini; framework: arduino; platform: platformio/espressif8266 @ 3.2.0)
--------------------------------------------------------------------------------
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
Dependency Graph
|-- <ESPAsyncTCP-esphome> 1.2.3
|-- <ESPAsyncWebServer-esphome> 2.1.0
|   |-- <ESPAsyncTCP-esphome> 1.2.3
|   |-- <Hash> 1.0
|   |-- <ESP8266WiFi> 1.0
|-- <DNSServer> 1.1.1
|-- <ESP8266WiFi> 1.0
|-- <ESP8266mDNS> 1.2
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/api/api_connection.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/api/api_frame_helper.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/api/api_pb2.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/api/api_pb2_service.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/api/api_server.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/api/list_entities.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/api/proto.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/api/subscribe_state.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/api/user_services.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/binary_sensor/automation.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/binary_sensor/binary_sensor.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/captive_portal/captive_portal.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/esp8266/gpio.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/esp8266/preferences.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/homeassistant/binary_sensor/homeassistant_binary_sensor.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/logger/logger.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/md5/md5.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/mdns/mdns_component.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/mdns/mdns_esp32_arduino.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/mdns/mdns_esp8266.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/mdns/mdns_esp_idf.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/network/util.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/ota/ota_backend_arduino_esp32.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/ota/ota_backend_arduino_esp8266.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/ota/ota_backend_esp_idf.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/ota/ota_component.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/script/script.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/socket/bsd_sockets_impl.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/socket/lwip_raw_tcp_impl.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/socket/socket.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/web_server_base/web_server_base.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/wifi/wifi_component.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/wifi/wifi_component_esp32_arduino.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/wifi/wifi_component_esp8266.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/components/wifi/wifi_component_esp_idf.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/core/application.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/core/component.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/core/component_iterator.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/core/controller.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/core/helpers.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/core/log.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/core/scheduler.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/esphome/core/util.cpp.o
Compiling /data/car-battery-monitor/.pioenvs/car-battery-monitor/src/main.cpp.o
Linking /data/car-battery-monitor/.pioenvs/car-battery-monitor/firmware.elf
RAM:   [====      ]  39.8% (used 32584 bytes from 81920 bytes)
Flash: [====      ]  38.8% (used 405377 bytes from 1044464 bytes)
Building /data/car-battery-monitor/.pioenvs/car-battery-monitor/firmware.bin
esp8266_copy_factory_bin(["/data/car-battery-monitor/.pioenvs/car-battery-monitor/firmware.bin"], ["/data/car-battery-monitor/.pioenvs/car-battery-monitor/firmware.elf"])
========================= [SUCCESS] Took 36.82 seconds =========================

********************************************************************************
We found 107.85MB of unnecessary PlatformIO system data (temporary files, unnecessary packages, etc.).
Use `pio system prune --dry-run` to list them or `pio system prune` to save disk space.
INFO Successfully compiled program.
INFO Resolving IP address of car-battery-monitor.local
INFO  -> 192.168.86.140
INFO Uploading /data/car-battery-monitor/.pioenvs/car-battery-monitor/firmware.bin (409536 bytes)
INFO Compressed to 286306 bytes
Uploading: [============================================================] 100% Done...

INFO Waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from car-battery-monitor.local using esphome API
INFO Successfully connected to car-battery-monitor.local
[18:31:17][I][app:102]: ESPHome version 2022.3.1 compiled on Oct 27 2022, 18:30:42
[18:31:17][C][wifi:491]: WiFi:
[18:31:17][C][wifi:353]:   Local MAC: 48:55:19:12:A4:97
[18:31:17][C][wifi:354]:   SSID: [redacted]
[18:31:17][C][wifi:355]:   IP Address: 192.168.86.140
[18:31:17][C][wifi:356]:   BSSID: [redacted]
[18:31:17][C][wifi:358]:   Hostname: 'car-battery-monitor'
[18:31:17][C][wifi:360]:   Signal strength: -58 dB ▂▄▆█
[18:31:17][C][wifi:364]:   Channel: 1
[18:31:17][C][wifi:365]:   Subnet: 255.255.255.0
[18:31:17][C][wifi:366]:   Gateway: 192.168.86.1
[18:31:17][C][wifi:367]:   DNS1: 192.168.86.1
[18:31:17][C][wifi:368]:   DNS2: 0.0.0.0
[18:31:17][C][logger:233]: Logger:
[18:31:17][C][logger:234]:   Level: DEBUG
[18:31:17][C][logger:235]:   Log Baud Rate: 115200
[18:31:17][C][logger:236]:   Hardware UART: UART0
[18:31:17][C][captive_portal:088]: Captive Portal:
[18:31:17][C][mdns:084]: mDNS:
[18:31:17][C][mdns:085]:   Hostname: car-battery-monitor
[18:31:17][C][ota:085]: Over-The-Air Updates:
[18:31:17][C][ota:086]:   Address: car-battery-monitor.local:8266
[18:31:17][C][ota:089]:   Using Password.
[18:31:17][C][api:138]: API Server:
[18:31:17][C][api:139]:   Address: car-battery-monitor.local:6053
[18:31:17][C][api:143]:   Using noise encryption: NO
[18:31:17][C][homeassistant.binary_sensor:039]: Homeassistant Binary Sensor 'Deep Sleep Mode'
[18:31:17][C][homeassistant.binary_sensor:040]:   Entity ID: 'input_boolean.car_battery_monitor_sleep_mode'
[18:31:24][D][main:232]: Binary Helper Enabled!
[18:31:24][D][script:036]: Script 'consider_deep_sleep' queueing new instance (mode: queued)
[18:31:44][D][main:232]: Binary Helper Enabled!
[18:31:44][D][script:036]: Script 'consider_deep_sleep' queueing new instance (mode: queued)

Here’s the complete log for the ESP32:

INFO Reading configuration /config/esphome/test-esp32.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing car-battery-monitor-test (board: esp32dev; framework: arduino; platform: platformio/espressif32 @ 3.5.0)
--------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
Dependency Graph
|-- <AsyncTCP-esphome> 1.2.2
|-- <WiFi> 1.0
|-- <FS> 1.0
|-- <Update> 1.0
|-- <ESPAsyncWebServer-esphome> 2.1.0
|   |-- <AsyncTCP-esphome> 1.2.2
|-- <DNSServer> 1.1.0
|-- <ESPmDNS> 1.0
Compiling /data/car-battery-monitor-test/.pioenvs/car-battery-monitor-test/src/main.cpp.o
Linking /data/car-battery-monitor-test/.pioenvs/car-battery-monitor-test/firmware.elf
RAM:   [=         ]  12.7% (used 41764 bytes from 327680 bytes)
Flash: [=====     ]  50.4% (used 924734 bytes from 1835008 bytes)
Building /data/car-battery-monitor-test/.pioenvs/car-battery-monitor-test/firmware.bin
esp32_create_combined_bin(["/data/car-battery-monitor-test/.pioenvs/car-battery-monitor-test/firmware.bin"], ["/data/car-battery-monitor-test/.pioenvs/car-battery-monitor-test/firmware.elf"])
Wrote 0xf1cb0 bytes to file /data/car-battery-monitor-test/.pioenvs/car-battery-monitor-test/firmware-factory.bin, ready to flash to offset 0x0
========================= [SUCCESS] Took 25.79 seconds =========================
INFO Successfully compiled program.
INFO Resolving IP address of car-battery-monitor-test.local
INFO  -> 192.168.86.139
INFO Uploading /data/car-battery-monitor-test/.pioenvs/car-battery-monitor-test/firmware.bin (924848 bytes)
Uploading: [============================================================] 100% Done...

INFO Waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from car-battery-monitor-test.local using esphome API
INFO Successfully connected to car-battery-monitor-test.local
[18:33:37][I][app:102]: ESPHome version 2022.3.1 compiled on Oct 27 2022, 18:32:53
[18:33:37][C][wifi:491]: WiFi:
[18:33:37][C][wifi:353]:   Local MAC: 34:86:5D:3B:55:78
[18:33:37][C][wifi:354]:   SSID: [redacted]
[18:33:37][C][wifi:355]:   IP Address: 192.168.86.139
[18:33:37][C][wifi:357]:   BSSID: [redacted]
[18:33:37][C][wifi:358]:   Hostname: 'car-battery-monitor-test'
[18:33:37][C][wifi:360]:   Signal strength: -40 dB ▂▄▆█
[18:33:37][C][wifi:364]:   Channel: 1
[18:33:37][C][wifi:365]:   Subnet: 255.255.255.0
[18:33:37][C][wifi:366]:   Gateway: 192.168.86.1
[18:33:37][C][wifi:367]:   DNS1: 192.168.86.1
[18:33:37][C][wifi:368]:   DNS2: 0.0.0.0
[18:33:37][C][logger:233]: Logger:
[18:33:37][C][logger:234]:   Level: DEBUG
[18:33:37][C][logger:235]:   Log Baud Rate: 115200
[18:33:37][C][logger:236]:   Hardware UART: UART0
[18:33:37][C][adc:062]: ADC Sensor 'Car Battery Level'
[18:33:37][C][adc:062]:   Device Class: 'voltage'
[18:33:37][C][adc:062]:   State Class: 'measurement'
[18:33:37][C][adc:062]:   Unit of Measurement: 'V'
[18:33:37][C][adc:062]:   Accuracy Decimals: 2
[18:33:37][C][adc:072]:   Pin: GPIO36
[18:33:37][C][adc:078]:  Attenuation: 0db (max 1.1V)
[18:33:37][C][adc:094]:   Update Interval: 300.0s
[18:33:37][C][captive_portal:088]: Captive Portal:
[18:33:37][C][mdns:084]: mDNS:
[18:33:37][C][mdns:085]:   Hostname: car-battery-monitor-test
[18:33:37][C][ota:085]: Over-The-Air Updates:
[18:33:37][C][ota:086]:   Address: car-battery-monitor-test.local:3232
[18:33:37][C][ota:089]:   Using Password.
[18:33:37][C][api:138]: API Server:
[18:33:37][C][api:139]:   Address: car-battery-monitor-test.local:6053
[18:33:37][C][api:143]:   Using noise encryption: NO
[18:33:37][C][homeassistant.binary_sensor:039]: Homeassistant Binary Sensor 'Deep Sleep Mode'
[18:33:37][C][homeassistant.binary_sensor:040]:   Entity ID: 'input_boolean.car_battery_monitor_sleep_mode'
[18:33:53][D][main:283]: Binary Helper NOT Enabled
[18:33:53][D][script:036]: Script 'consider_deep_sleep' queueing new instance (mode: queued)
[18:34:13][D][main:283]: Binary Helper NOT Enabled
[18:34:13][D][script:036]: Script 'consider_deep_sleep' queueing new instance (mode: queued)

This is the configuration for the ESP8266 (I have removed the lines for the ota and wifi)

esphome:
  name: car-battery-monitor
  on_boot:
    then:
      - script.execute: consider_deep_sleep
  on_shutdown:
    then:
      
esp8266:
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:

captive_portal:

# 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

# 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:
            - logger.log: 'Binary Helper Enabled!'
          else:
            - logger.log: 'Binary Helper NOT Enabled'
      - script.execute: consider_deep_sleep

This is the configuration for the ESP32:

esphome:
  name: car-battery-monitor-test
  on_boot:
    then:
      - script.execute: consider_deep_sleep
  on_shutdown:
    then:

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:

captive_portal:

# 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

# 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:
            - logger.log: 'Binary Helper Enabled!'
          else:
            - logger.log: 'Binary Helper NOT Enabled'
      - script.execute: consider_deep_sleep

They both use the exact same code, save for the platform specific lines.

Thanks, it is helpful to see the whole config.

I wonder if it is a timing issue in on_boot. Perhaps try setting the priority of the on_boot automation to something higher than the default which is 600. Try 800 and then pare it back, ESPHome Core Configuration — ESPHome

Thanks, that didn’t change anything.

The boot priority only should be an issue once, correct (when it starts up)? I would assume that once it’s running, it shouldn’t have any effect on reading the value. If I change the value of the Helper after both boot, the ESP8266 will read the correct value while the ESP32 still won’t.

I’ll try another ESP32 board to see if it’s a glitch with that one.

Edit: Nope. Same results with another board.

I also tried both extremes for the priority (800 & -100) and the same results with each one.

Screen Shot 2022-10-28 at 7.43.29 AM

Yes, but as far as I can see you only run consider_deep_sleep on boot.

The last line if the script queues it again.

      - script.execute: consider_deep_sleep

I had missed the queued

I have no further ideas, except to suggest an issue in github.

Ok, Thanks.

Hoping someone else can come along with any other suggestions.

If anyone wants to try the code I posted and let me know if they get the same results reading a binary sensor value on an ESP32 (I believe what I’m using is a NodeMCU D1 mini) vs an ESP8266, I’d like to see if it isn’t just me.