Monitor a HA sensor in ESPHome

I’m trying to accomplish something with ESPHome and have run into a significant hurdle that I can’t seem to overcome. So, with apologies, I’m reaching out to this community for some basic help.

I want an ESPHome device that monitors a handful of HA sensors and appropriately represents their values using simple LEDs–like if the outside garage door is open, show a red LED, closed show a green LED. I can then use that device for a quick home safety check before bed.

While prototyping this device, I set up a Toggle Helper in HA and I’m trying to generate debug output on its value. However, the ESPHome device (mini-ESP32) doesn’t seem to track the value (or my code is whacked).

No matter the value of the toggle, the ESP debug output always reads:

[15:35:11][D][custom:064]: 3 sec heartbeat
[15:35:11][D][custom:068]: 0

Here’s the minimal YAML code I’m using, with the test_toggle helper in HA. Any hints would be greatly appreciated! (FWIW, using the latest HA and ESPHome)

substitutions:
  name: esphome-web-13ab64
  friendly_name: status-tracker-bedroom

esphome:
  name: ${name}
  friendly_name: ${friendly_name}
  min_version: 2024.6.0
  name_add_mac_suffix: false
  project:
    name: esphome.web
    version: dev

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:
  level: DEBUG
  logs:
    esp32_ble_tracker: DEBUG

# Enable Home Assistant API
api:

# Allow Over-The-Air updates
ota:
- platform: esphome

# Allow provisioning Wi-Fi via serial
improv_serial:

wifi:
  # Set up a wifi access point
  ap: {}

captive_portal:

dashboard_import:
  package_import_url: github://esphome/example-configs/esphome-web/esp32.yaml@main
  import_full_config: true

# Sets up Bluetooth LE (Only on ESP32) to allow the user
# to provision wifi credentials to the device.
esp32_improv:
  authorizer: none

# To have a "next url" for improv serial
web_server:

binary_sensor:
  - platform: homeassistant
    name: "Test Toggle"
    entity_id: input_boolean.test_toggle
    id: test_toggle

interval:
  - interval: 3000ms
    then:
     # - switch.toggle: builtinLED
     - lambda: |-
         ESP_LOGD("custom", "3 sec heartbeat");
         if (id(test_toggle).state) {
           ESP_LOGD("custom", "1");
         } else {
           ESP_LOGD("custom", "0");
         }

I think the imported sensor reports OFF and ON, rather that the expected Boolean 0 and 1. Try testing for those states.

Try setting this to VERY_VERBOSE then paste what Test Toggle shows in the logs when you toggle the input Boolean. I suspect Daryl is probably right.

I did try Daryl’s suggestion with no change. In additional testing, the ESP32 doesn’t seem to be listening to HA.

VV doesn’t show any activity on the test_toggle. It only shows the interval event firing:

[16:10:52][D][custom:069]: 0
[16:10:54][VV][scheduler:226]: Running interval ‘’ with interval=10000 last_execution=72370 (now=82370)
[16:10:55][VV][scheduler:226]: Running interval ‘update’ with interval=3000 last_execution=79935 (now=82935)
[16:10:55][D][custom:064]: 3 sec heartbeat
[16:10:55][D][custom:069]: 0
[16:10:58][VV][scheduler:226]: Running interval ‘update’ with interval=3000 last_execution=82935 (now=85941)
[16:10:58][D][custom:064]: 3 sec heartbeat
[16:10:58][D][custom:069]: 0

I tried another non-helper entity (switch) with the same result–no logs. And adding in a non-existent sensor (input_boolean.test_toggle2) gives no error (IDK if the API checks HA for the existence of the defined sensor…)

I’m thinking the API isn’t configured correctly and/or jsut not working. I have another ESPHome implementation feeding HA Bluetooth data, which is working fine. I think I’ll try to add the toggle into its configuration and see if that implementation tracks it…

BTW, thank you for the suggestions!

Yep. The working ESP32 implementation shows what is expected when I toggle the sensor:

[16:40:50][D][homeassistant.binary_sensor:026]: ‘input_boolean.test_toggle’: Got state OFF
[16:40:50][D][binary_sensor:036]: ‘Test Toggle’: Sending state OFF

So I’m probably going to burn down the new implementation and start over with the prototyping (after a quick comparison of configs).

1 Like