room-assistant icon indicating copy to clipboard operation
room-assistant copied to clipboard

[Feature] Triangulation possible?

Open vswraith opened this issue 7 years ago • 18 comments

Is it technically possible to set 3 room-assistant instances in and they triangulate based on distance to get a better idea where the person is?

vswraith avatar May 18 '17 16:05 vswraith

Possible yes - has to be done by the mqttbroom component on the HASS end. Would need some code adjustments for data collection and calculation.

Definitely something I'd love to try out, but currently I have my hands full with work and a Bachelor Thesis. After that's dealt with (middle of July) I can start putting some more work into this project.

mKeRix avatar May 19 '17 14:05 mKeRix

Similar to this, is it possible to judge presence in the following way:

  • iBeacon(s) per room.
  • iBeacon on person ==> Judge where a person is based on the proximity of their iBeacon to the static one(s) in Room X?

chimpy avatar Jun 07 '17 16:06 chimpy

@chimpy Let me get that right, are you looking for a way to measure the presence by comparing the (combined) signal values of the stationary iBeacons with the "people" beacons?

In that case I am not sure if it's doable with just Bluetooth - room-assistant knows how far away something is from itself by measuring the signal strength. It does not know the direction of the signal by itself (or at least I haven't figured that out yet). The way I understood your proposal it would collide as soon as you use the scanner in a non-linear room setup... basically you'd have to place it at the end of a couple rooms that are more less in a straight line to somehow match the signal strength to the actual location.

If you apply your concept to the triangulation idea already mentioned here you could make it work, it just needs at least 3 scanners then though. I can keep it in mind, won't necessarily be part of the first implementation though as it does add a layer of complexity.

(please do correct me if I got something wrong, it's late already...)

mKeRix avatar Jun 07 '17 23:06 mKeRix

Definitely something I'd love to try out, but currently I have my hands full with work and a Bachelor Thesis. After that's dealt with (middle of July) I can start putting some more work into this project.

Would love to see how this turned out.

zoggels avatar May 25 '19 08:05 zoggels

Came here to ask the same. 3 pis on each floor (to establish upstairs or downstairs and remove any y axis distance, limit to just x & z). Then triangulate based on distance from the 3 pi’s on that floor. I’ve only set this up with 1 pi for testing (but works really well, relatively stable numbers and works with my Apple Watch, so HEROIC work!) I’m not sure how the other distances are broadcast on MQTT. If the current result from the cluster is to just send the nearest room, and distance that won’t be sufficient, I think you would need to send all rooms, and all distances. Ideally in a single JSON MQTT. Then this could be done with some maths in Node-Red.

EDIT: I know what I’ll be testing tomorrow: https://www.npmjs.com/package/node-trilateration EDIT2: there would also be a need to know the distance between 1 node and the next (the anchor points). Maybe during a setup phase have it send a 1 time MQTT msg of the distance from the other nodes? Add the MAC address of the other nodes in the config, but specifically “node addresses”, so that after the distance is reported (and the node isn’t moved) it won’t be needed again until restart. Those values can be used in Node-Red for the formula).

jaburges avatar Feb 26 '20 07:02 jaburges

@mKeRix any thought into whether you'd want to do the math, or provide all the values in a single JSON (possibly including the distance between the nodes in the cluster)?

jaburges avatar Feb 27 '20 04:02 jaburges

@jaburges I'm willing to just integrate this into room-assistant to simplify things for the end user in theory, I'm just not sure how well it would work. RSSI values get really unreliable once there are obstructions (like walls) in-between, which in turn also makes the distance estimation of the BLE integration wonky. For trilateration I suppose you would need pretty solid distance estimations.

mKeRix avatar Feb 29 '20 17:02 mKeRix

Thanks for the reply - that would be epic if you can integrate! as long as the values are consistent I think the RSSI variation shouldn’t matter, especially if just a single plane / 2 axis. As if the nodes are always a fixed distance apart, then the calc should return a consistent value (if you overlaid on to a floor plan then some areas would be falsely stretched or shrunk based on the reduction in RSSI due to walls etc right?) Let me know if I can help test. I’ve now got 3 nodes 2.1.0 on both floors spread out across the space.

jaburges avatar Mar 01 '20 07:03 jaburges

I guess you're right - the coordinate space might be deformed when overlaying on a floor plan, but as long as the output is consistent and differentiable it could be possible to tweak the limits enough to get a good room presence mapping. I'll put this into the list of feature requests to work on and will let you know once there is something that can be tested.

mKeRix avatar Mar 01 '20 11:03 mKeRix

Hi, I'd be interested in this. I have 6 x pi zeros running room-assistant across the house at the moment. Still haven't got it working consistently but that's for another thread.

B-Hartley avatar Mar 04 '20 08:03 B-Hartley

I would definitely love this. It would be awesome if you could set up a coordinate system and put the location that each sensor is at so it can triangulate each device using the Room Assistant cluster. This would pair excellent with lovelace-floorplan.

I already have floorplan hiding/showing images based on if the person is located in the specific room (only have 2 rooms covered, need more RPIs for all of the rooms).

image

AngellusMortis avatar May 01 '20 18:05 AngellusMortis

I would definitely love this. It would be awesome if you could set up a coordinate system and put the location that each sensor is at so it can triangulate each device using the Room Assistant cluster. This would pair excellent with lovelace-floorplan.

I already have floorplan hiding/showing images based on if the person is located in the specific room (only have 2 rooms covered, need more RPIs for all of the rooms).

@AngellusMortis Just looking into this now as I need room base presence detection. How did you integrate this with Floorplan? I know, a little off topic. :)

As far as this feature request, I'd love to see this implemented for a cluster of 3 or more Room Assistant devices and to have someway to integrate it accurately into Home Assistant.

austwhite avatar May 09 '20 10:05 austwhite

That'll be an awesome feature and would make room assistant really stand out.

Here's my floorplan with the position of all (possible) roomassistant devices. Would be great if they could calculate positioning (or at least proper room assignment). Sitting on the couch in the livingroom currently assigns to the office (middle top room) instead of the livingroom (most left room assistant).

floorplan

lociii avatar Jul 12 '20 13:07 lociii

as long as the values are consistent I think the RSSI variation shouldn’t matter, especially if just a single plane / 2 axis. As if the nodes are always a fixed distance apart, then the calc should return a consistent value

floorplan_livingroom That's what I thought too. If we imagine every room as a polygon, can't we teach the system about possible values of each sensor within that polygon. Trilateration should work fine here. Walls might be even beneficial as signal strength between two close coordinates in the apartment might be wildly different if there is a wall in between.

lociii avatar Jul 12 '20 18:07 lociii

https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0205392

lociii avatar Jul 19 '20 07:07 lociii

ok update if others want to join along?

Running node-red in docker. docker exec -it NodeRed /bin/bash /data/ folder

cd /data/node_modules
npm install trilateration
cd ..
nano settings.js

Edit settings.js and look for functionGlobalcontext add the line `trilateration:require('trilateration') [not sure if needed, but reboot node-red docker]

now add this flow:

[{"id":"7baa283a.add398","type":"inject","z":"fa164293.781af","name":"","props":[{"p":"payload"},{"p":"beacon0","v":"5.7","vt":"num"},{"p":"beacon1","v":"6.8","vt":"num"},{"p":"beacon2","v":"6.2","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1265.0116386413574,"y":1344.6202659606934,"wires":[["c4ffddc5.0ee37"]]},{"id":"5d3c170b.59f118","type":"debug","z":"fa164293.781af","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1730.0115966796875,"y":1342.620361328125,"wires":[]},{"id":"c4ffddc5.0ee37","type":"function","z":"fa164293.781af","name":"","func":"var trilateration = global.get('trilateration');\n\ntrilateration.addBeacon(0, trilateration.vector(2, 4));\ntrilateration.addBeacon(1, trilateration.vector(5, 13));\ntrilateration.addBeacon(2, trilateration.vector(11, 2));\n\ntrilateration.setDistance(0, msg.beacon0);\ntrilateration.setDistance(1, msg.beacon1);\ntrilateration.setDistance(2, msg.beacon2);\n\nmsg.payload = trilateration.calculatePosition();\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1489.011573791504,"y":1345.6202659606934,"wires":[["5d3c170b.59f118"]]}]

Thanks to Kermit for the assistance on the flow

jaburges avatar Dec 11 '20 00:12 jaburges

so now just need to get all 3 values from the respective beacons (per floor I think this will be easier)

Anyone able to provide any ideas on how to get each beacon to add its distance to the phone?

jaburges avatar Dec 11 '20 00:12 jaburges

Using the API and some node-red Working triangulation https://community.home-assistant.io/t/internal-position-tracking-with-co-ordinates-using-an-iphone-and-room-assistant/254399

jaburges avatar Dec 12 '20 00:12 jaburges