Esphome with BLE_Tracker

Hello,

I have a very simple esphome device that I’m using to collect data from a bunch of sensors. There are about 20 sensors scattered around the yard and the configuration I have works and collects the data, but I want the device to sleep for 2 hours after operating for 20 minutes because it is battery operated. The problem is, when the ble_tracker is set to continuous scan, it prevents the device from sleeping. If I set continuous = false, it goes to sleep as expected. Is there a way to get this working? Here is my config:

esphome:
  name: growbot01
  friendly_name: growbot01

esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "blahblah"

ota:
  password: "blahblah"

wifi:
  reboot_timeout: 4min
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Growbot01 Fallback Hotspot"
    password: "blahblah"

captive_portal:
  
deep_sleep:
  id: deep_sleep_1
  run_duration: 20min
  sleep_duration: 120min

mqtt:
  broker: blah.blah.blah
  port: 1883
  username: mqtt
  password: !secret mqtt_pw
  topic_prefix: backyard/sensors
  birth_message:
  will_message:
  #on_message:
  #  - topic: devices/miflora02/ota_mode
  #    payload: 'ON'
  #    then:
  #      - deep_sleep.prevent: deep_sleep_1
  #  - topic: devices/miflora02/ota_mode
  #    payload: 'OFF'
  #    then:
  #      - deep_sleep.enter: deep_sleep_1

esp32_ble_tracker:
  id: ble_tracker
  scan_parameters:
    continuous: false
text_sensor:
  - platform: ble_scanner
    name: "BLE Devices Scanner"

sensor:
  - platform: xiaomi_hhccjcy01
    mac_address: 'C4:7C:8D:6B:3B:B2'
    temperature:
      name: "Herb Garden 1 Temperature"
      force_update: true

Any suggestions are much appreciated!

Jason

You should do a “star_scan” on wakeup, if you don’t want continuous.

But it probably won’t do what you expect. The devices themselves decide when they broadcast information, you don’t “interrogate” them. The scan only detect the devices themselves.

Bottom-line: doing BLE proxying with an ESP (anything, really) requires the ESP to be always ON.
Here, you’ll likely miss your xiaomi sensor updates unless you are sure there is at least one update broadcasted every 20 minutes or less.

I run my in NON continuous mode.

time:
  - platform: sntp
    id: sntp_time
    timezone: Europe/Rome
    on_time:
      - seconds: 0
        minutes: 0/5
        then:
          - esp32_ble_tracker.start_scan:
      - seconds: 30
        minutes: 0/5
        then:
          - esp32_ble_tracker.stop_scan:

Thank Karosm!

This is great, but doesn’t this fire at a specific time of day? I’d like something that will start after boot and run for 20 mins.

For anyone else struggling with this, I figured it out:

  on_boot:
    priority: -100
    # ...
    then:
    - esp32_ble_tracker.start_scan:
  on_shutdown: 
    priority: 800
    then:
      - esp32_ble_tracker.stop_scan: 

Then, in the scanning parameters:

esp32_ble_tracker:
  id: ble_tracker
  scan_parameters:
    continuous: false
    duration: 18min

Thanks to everyone that tried to help!