Triangulating Tile Location via ESPresence

My cat away last week, thankfully we found her. I am now hoping to triangulate her location via the tile tracker in her collar. As it will help me prevent her from escaping unnoticed again. Any help would be much appreciated!

Issue: I have set up three ESPresence sensors that work great but only provide me with a sensor that tell the distance from the tile (beacon) to the nearest ESPresence (base station).

Goal: Get a single sensor with distances from each base station the beacon is.

I found the following post that provided a Python script for getting a distance from each beacon from each station but I could not get the Python script to work: ESPresense: how to know the distance from every station rather than just the closest one
I think that it is likely due to the output not correlating to a sensor. Which led me to: How to best run sensor reading the output of a Python script?
However, I am unable to merge the two.

I asked help from a family member who knows Python very well but doesn’t know HA. He helped me alter the script from the first link to get the following:

import requests

def print_response(state = ‘unknown’):
  print'{"state": "%s", "attributes": {"unit_of_measurement": "m", "friendly_name": "Tango Mango"}}' % state

#retrieve the data
response = requests.get('')
if response is None:

#if no data
data = response.json()
if data is None:

#check data for tile distance 
for device in data.get('devices', {}):
  if device.get('mac', '') == 'dec2f1061282':
    distance = device.get('distance', '')
    if distance != '':


We formatted the output based on the information in the HTTP sensor documentation but I now think that it should output a hass variable as noted in the Python Scripts documentation and as shown in the second forum post I linked.

Any assistance in altering my script to output a sensor with distances from each base station would be greatly appreciated.

I dont know if you considered this but, i did something similar with my dog but instead of tracking distance which can be hit and miss. Instead i just use presense in general. I have a base station on each porch and if she goes from one room to the porch and then ‘away’ it sends me a notification that she may have escaped… distance can be difficult because the zone is a circular radius around the beacon and you cant reallydo directions.

I have given that some thought but I also want to know the direction my cat is heading. I can put a beacon by the door but I also want at least one more to tell me if she went through the door or back inside the house.

I get ya. I wouldnt say its impossible, but i thnk it will be difficult using distance. I have been playing with this repo as well as espresence. I like both, espresence is simple and works but, additional options or uses for the boaed are limited. This BT repo does a pretty good job showing distance and i can request BT devices battery level or any other esphome functions.

The one issue i havnt quite worked out is interference like walls and such, they throw the distance reading off a good amount. If you can position them where interference wont be an issue, this may work good for you.

Thanks, I was hoping to avoid switching to esphome after I just set up ESPressence but I am seriously considering it.

I would just try both honestly. Like i said, i like things avout each. You may be able to find some good non-esphome repos too. Straight C++ like from Arduino. The only problem there is youd have to send your distance data to esphome via mqtt or something else.

Ive been playing with this card in HA to display BT beacons. I can send you the info if you want it.
Tells you the room and distance. Its pretty cool.

Yes please! Anything helps

type: entities
title: Bluetooth Beacons
  - entity: sensor.golf_cart_key_beacon
    name: Golf Cart Key
    type: custom:secondaryinfo-entity-row
    secondary_info: >-
      <b style='color:green'>[[ sensor.golf_cart_key_beacon.attributes.distance
      ]] Ft.</b>
  - entity: sensor.sam_s_beacon
    name: Sam's Beacon
    type: custom:secondaryinfo-entity-row
    secondary_info: >-
      <b style='color:green'>[[ sensor.sam_s_beacon.attributes.distance ]]
  - entity: sensor.paula_s_keychain
    name: Paula's Keys
    type: custom:secondaryinfo-entity-row
    secondary_info: >-
      <b style='color:green'>[[ sensor.paula_s_keychain.attributes.distance ]]

Herw is the card.

Of you need help, im definitely not an expert here but, i can help if you need it. Im kind of interested to see where you take BT as well.

Thank you! I am turning one of my ESPresense into an ESPhome now

Are you in the US?

I was just gonna say, the person that runs blueCharmBeacons is pretty active on here and makes good BLE beacons but, last i checked they only ship within the US. Theyre really good and personally i like them better than Tile.