Use ESP32 for Bluetooth room presence detection

now we can install ESP32 in each room and connect it to HA, I’m looking for a minimal config integration to do room presence based on BT MAC address of our mobile phones/watches.

This should also include guidance what to put in the ESP32 if needed.

Goal is reliable BT room presence detections that can act as trigger in HA.

4 Likes

Thanks this I already tried without succes.
I put the following in the config file of ESP32.

esp32_ble_tracker:

bluetooth_proxy:

binary_sensor:
  - platform: ble_presence
    mac_address: XXXXX
    name: "BLE Tracker OnePlus"

sensor:
  - platform: ble_rssi
    mac_address: XXXX
    name: "BLE RSSI OnePlus"

But no status update in HA.

Any sugegstions?

Moved to esphome category as this is a configuration question not a WTH.

Android phones do not “emit” a BLE signal. You would have to use the Home Assistant app and turn on the BLE transmitter.

1 Like

Hi There,

I would like to ask for the same.
I can see articles about ESPHome BLE tracker and verbose logs, iBeacon tracker of HA, binary sensor (able presence platform) and sensor (ble_rssi platform) under ESHPHome, but I cannot find out if and how to use them.
What I simply would like to achieve is to activate a BLE ibeacon based presence detector for multiple rooms, and if possible, the related entities should be generated under HA. At the moment if I use iBeacon tracker, it creates multiple entities for the same device (randomized MAC), or if I use binary/sensor under ESPHome, even if I register the relevant MAC address from the verbose log, the entities are created but never go to on state, more report the RSSI…

Is there a consensus how these can be used, what a re differences, advantages/disadvantages, and if they can be used with the Bluetooth proxy?

Thanks, Robert

1 Like

Hi Jules, since the introduction of ESPHome BT Proxy I was looking also in exteding it’s scope making it a room presence tool as well, I made a few topics looking for tips unsucesfully.

I kepp looking at this and I think I am half way to the solution now :slight_smile:

Let me share my steps and maybe with all your thoughts we can have this working perfectly.

The idea:
When my iBeacon is connected to an ESP32 BT Proxy, in it’s attribute we can see “source” that is the name of the BT Proxy it is connected to.
If we know what proxy we are connected to, we know where we are (you must assign area to each BT proxy), that simple!

The steps:

  • Assign an area in home assistant to all your BT Proxy

  • Create a sensor in configuration.yaml like this:

sensor:
      - platform: template
        sensors:
          way_simone:
            friendly_name: Simone Room Presence
            value_template: "{{ area_name(device_id(state_attr('sensor.c6a47b33_56f2_47c2_9884_6835e05caec2_1001_1000_estimated_distance', 'source'))) }}"
  • Replace my beacon (sensor.c6a47b33_56f2_47c2_9884_6835e05caec2_1001_1000_estimated_distance) with yours.
    Please note that I am not using the beacon itself, but I am using the entity ‘estimated_distance’, the reason for this is because I noticed that the beacon retain in it’s attributes the source proxy for a certain (long) time even after it’s disconnected while the estimated_distance entity is updating constantly.
    You still can use the beacon itself as long as you are aware of what explained above.

  • Reboot your home assistant and then you will have the sensor just created and you can use it to track the room you’re in:

The problems:
At the moment I am still facing only one but huge problem: tracking is very inconsistent. Even if I have one or two ESPHome BT Proxy in every room, still several times my iBeacon (Android phone with companion app) seems disconnected from every BT Proxy and I really cannot understand this, as you can see from the screenshot above, sometimes it report me as “Sconosciuto” that means “Unknown”.
I try several settings in the BT Proxy configuration for window, interval, ecc… but none really changed anything. If we can manage to fix this issue we are done with our BT Proxies as room presence tool :slight_smile:

I also tried to change the companion app BLE settings increasing the BT power but also in this case without success.

I hope all this helps somehow :wink:

5 Likes

It’d be great if ESP32 had a better “traditional Bluetooth” support. I’m using a pair of raspberry zeros and a script known as Bluetooth Monitor to this purpose. On any door open/close or motion detected HA sends a SCAN command to the script and updates the Presence entities. But I admit, Raspberry Pis are a bit of an overkill for the purpose… if only we could do it ESP32…

Any news? I’m interested in this solution

2 Likes

I’d love to work with ESPHome as it is more integrated in HA, easier to upgrade ESP devices and I expect with ESPHOME I would have the option to combine functions in one ESP (e.g. presence detection and room temperature).

As containment I now installed ESPRESENCE one by one on my ESP’s.
See: Home Assistant | ESPresense

After installing ESPresence, I could see all ESP’s in HA.
image

Next, I created sensors for each of my mobile devices;


# Iphone 11 - Vannessa
- platform: mqtt_room
  device_id: "apple:1007:11-8"
  name: 'ESP iphone11'
  state_topic: 'espresense/devices/apple:1007:11-8'
  timeout: 3
  away_timeout: 120


# oneplus9pro - Jules (ibeacon)
- platform: mqtt_room
  device_id: "iBeacon:6d730000-b686-471a-bf6b-84d1c05fa550-100-1"
  name: 'ESP OnePlus9pro'
  state_topic: 'espresense/devices/iBeacon:6d730000-b686-471a-bf6b-84d1c05fa550-100-1'
  timeout: 3
  away_timeout: 120

This works great, no false negatives.
image

I created a helper to track home status per person and an automation to switch the helper based on the status of the ESP’s.

This all works perfect for home presence, but for room presence I notice that the presence is jumping from room-to-room too often. So, room accuracy is not accurate enough yet. All the lines in the screenshot on history show how many changes are registered.

I guess that if I play around with the “max distance” I could find an optimum between nervous/unreliable room detection vs false negatives on away detection. Nice exercise for coming Christmas break.

image

If anyone has a good idea how to get room presence in ESPHOME I’m very interested and happy to abandon ESPRESENCE.

Grtz
Jules

4 Likes

Sounds like you are getting close to a really good system.

Re the distance thing, I made a comment on another thread about adjusting the “Factor” setting in ESPresence. This should help to dial in the distance calculation that the ESP is using. Personally I think that ESPresence needs to add a few more adjustable settings to allow the distance accuracy and trigger reliability to be a bit better, but in the meantime, you can try this:

How did you get the areas working?

For mine, device_id seems to return the MAC address of the ESP32 and then area_name reports “None” even after I have gone to the esp32 in “Devices” and use the pencil to set an area.

Dev Template:

value_template: "{{ area_name(device_id(state_attr('sensor.trash_can_estimated_distance', 'source'))) }}"
value_template: "{{ device_id(state_attr('sensor.trash_can_estimated_distance', 'source')) }}"
value_template: "{{ state_attr('sensor.trash_can_estimated_distance', 'source') }}"

Result:

value_template: "None"
value_template: "None"
value_template: "78:21:84:e2:1e:80"

Hi Matt, this was something I did more than one year ago, at that time it was working returning me the area of the BT Proxy closer to the device, I don’t know if anything changed since then.
I gave up trying to use BT Proxy for room presence mainly for 2 reasons, it’s slow and unreliable in detecting room presence and simply ESPresense works much better for me.

Fair enough. I’m not familiar with ESPresence but it sounds like it might be different firmware vs just adding 1 line to an existing ESPHome device.

It is different firmware just like Tasmota is different firmware but, they bothwork seamlessly with HA over mqtt. The biggest thing is you have to play around with the settings to weed out excessive signal overlap and base station placement is important too. For example you wouldt want 2 base stations sharing a common wall like one was in bedroom1 and the other was on the other side of the wall in bedroom2 or else youll have to much signal overlap and device/presence will bounce between the 2 rooms which isnt very useful.