I configured several ESPresense stations and a bunch of beacons. My plan was to do automations based on distance comparisons. E.g. I could make a reasonable guess that a beacon is in the backyard if:
1. The distance between the Beacon and the ESPresense-Station-1 is less than 100 ft, AND 2. The distance between the Beacon and the ESPresense-Station-2 is less than 100 ft, AND 3. The difference between (1) and (2) distances is less than 80 ft.
But i am only able to retrieve the distance from the closest station at the time and the name of the closest station. How can I have the distances between the beacon and all stations?
I’m not sure if this applies to beacons (as I only have Apple devices configured using irk), but for me all of the distances are available under the MQTT topic "espresense/devices/(device)/(room). Therefore you could subscribe to all of them for a device (using “+” for room) to get the distances you need. Also assuming you have it configured to use MQTT.
Thank you but I am very confused what steps I should take to follow your advise. Yes, all ESPresense devices send data to the MQTT. I even installed MQTT explorer app on my phone and I see the data coming in. I suppose I could write a python app to parse the json from MQTT. But is it possible to do in Home Assistant, using it’s existing capabilities?
Here we go - a python script which gets distances for each device from each station:
import requests
esps=['192.168.1.61','192.168.1.62','192.168.1.63']
distances={}
devices=[]
for esp in esps:
response = requests.get('http://'+esp+'/json/devices')
data = response.json()
for device in data['devices']:
id=device['id']+"-"+device['mac']
devices.append(id) if id not in devices else devices
distances[id+esp]=device['distance']
for device in devices:
line=device
for esp in esps:
if device+esp in distances:
line=line+" "+str(distances[device+esp])
else:
line=line+" ---"
print (line)
Is this possible in HA? To see all the beacons and their distances from all the stations? Or would it be better to format this output as HTML, run it somewhere else, and have an iframe in HA dashboard?
Did you get this figured out? I’m attempting basically the same thing. Using the distance between them all for a particular device will let me triangulate roughly where it is.
I stopped trying to make this work in HA. It’s so much easier to write your own code than configure HA. http://[ESPresense IP]/json/devices returns all distances to all BT devices. You can do any math/logic you need in Python and then set HTTP sensor value for use inside HA.
I dont really understand why you would want distances from each base station? The way a beacon broadcasts its signal in a circular fashion, it seems like it would be a logic nightmare and not that but the more walls and obstructions that signal goes through, it causes it to report distances that arent even close to being accurate. I can put a beacon 15’ away in the next room and the distance will fluctuate 10’ depending on if it has a clear line of sight or the door is closed and theres an obstruction.
Yes, results are very poor. Not only the numbers are inaccurate, they change drastically without any movement of the beacon. ESPs have BT 4.2 which is technology from 2011. BT 5 (2016) has made leaps in positioning accuracy, and 5.2 and 5.3 specs are truly impressive. But i wasn’t able to find any workable options in the DIY word. It would be really interesting to hear if anyone was able to build BT 5.* based indoor positioning system…
i’ve been playing with one i found on Git. It gives pure distances from each beacon but again, obstructions and the further away it is, it’s less accurate. I would look for more creative ways to do what you want that doesn’t exclusively use beacon distance
We are stuck in BT 4.* world with this which is extremely inaccurate. It’s been 8 years since BT 5 came out which is more accurate beyond comparison. The BT 5.1, which has precision of a fraction of an inch, just had it’s 5 year anniversary. Is there any HA support for this in sight? It’s about time!