Esphome ble-presence scan parameters advice

Hi all ,

I could use some advice, I currently have 2 Espruino pucks being used as presence detection, advertising to a Esp32 dev kit via BLE running ESphome. I’m trying to get the scan parameters right so I dont get any false away triggers.

The Esphome documentation confuses me with regards the scan parameters I’m not qute sure I understand them correctly. Currently I have the scan set for

interval: 1s
window: 1s
duration: 30s

However last night the Esphome device must of rebooted or something similar as both Pucks showed as being away for 10secs before reconnecting.

I believe the Puck by default advertises every 375ms so I’m trying to get my head around all the variables so that it connects within 3-5 secs but will show away after maybe 45 secs to one minute

currently this is roughly the case but I had that one false away where something must have happened and Pucks showed away.

here is my full .yaml file

esphome:
  name: esphome-presence

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: ""

ota:
  password: ""

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  reboot_timeout: 6h

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esphome-Presence"
    password: "password"

captive_portal:

esp32_ble_tracker:
  scan_parameters:
    interval: 1s
    window: 1s
    duration: 30s


binary_sensor:
  # Presence based on MAC address
  - platform: ble_presence
    device_class: presence
    mac_address: C1:77:DE:D9:0A:9P
    name: "My Puck"
  - platform: ble_presence
    device_class: presence
    mac_address: C2:55:88:C3:60:23
    name: "Wife's Puck"

Any advice on improving my setup or helping me understand the scan parameters, would be very appreciated

thanks in advance

So I’ve changed the scan parameters to be passive and changed the time for the scan duration to 5 secs, hopefully this is not too low, Ive also added a filter to not show the device away for 2 minutes after receiving an off state, hopefully this rules out false away states .

esphome:
  name: esphome-presence

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: ""

ota:
  password: ""

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  reboot_timeout: 6h

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esphome-Presence"
    password: "password"

captive_portal:

esp32_ble_tracker:
  scan_parameters:
    interval: 1s
    window: 1s
    duration: 5s
    active: false


binary_sensor:
  # Presence based on MAC address
  - platform: ble_presence
    device_class: presence
    mac_address: C1:77:DE:D9:0A:9P
    name: "my Puck"
    filters:
      - delayed_off: 120s
  - platform: ble_presence
    device_class: presence
    mac_address: C2:55:88:C3:60:23
    name: "Wife's Puck"
    filters:
      - delayed_off: 120s

Defaults have been fine for me. I think yours might be too long.

delay_off is a key way to control false aways.

1 Like

Yeah I agree, I might change the window and interval back to defaults, but the Scan duration was the inital issue it would take up 5 minutes (default setting) before it found a new state from the puck, so changing this to a smaller number has made it much more reliable.
I set the delayed off which is working really well so far because, It would sometime pick up the puck again when going from the front door to the car and then show away again shortly after. So far with the settings I have, It detects the Puck’s really quickly and waits a while before showing away which is perfect.

I think the defaults for Window and interval are 30ms and 320ms respectively , did you change yours to 25ms and 50ms ?

scan timings

1 Like

The ones in the image are just random ones from an image I found on the internet. I use the defaults you stated (as per the docs).