Internal position tracking with co-ordinates using an iphone and room-assistant

I do indeed

can you try it to see if it works?

it wont work for my house, as I’m the only one who owns one,
plus it doesn’t broadcast a BLE address (apple seems to randomize them) - so on the surface it wont work.
The reason this is possible is due to the room-assistant app that broadcasts a consistent BLE address.

If you can find a way around that issue, i’ll try it out

the room assistant app you use says it supports apple watches

The beta app (released by the dev to circumnavigate the random BLE mac broadcast issue i mentioned above) i’m using on the iphone to broadcast BLE, I don’t believe supports running on an apple watch to broadcast its BLE currently.

Bluetooth Classic will work with Apple watch, and in the past I have tried and succeeded with that for detection but not triangulation. I’ve also experienced more interference with 2.4GHz WiFi with BT classic than BLE.

Your post is getting quite a bit of attention :slight_smile:

I started over and went through the 3d part… 4 pi nodes, all ethernet connections.
Installed Node-Red on one (pi 4 8gb) and created the flow.

I’m not sure if I missed something or not but I am not getting any sensors from Node-Red into HA although the Person X & Y show to be running. Since this weekend has been a learning experience for me with Node-Red, I assume I did something wrong.

Any thoughts?


I did see this in the node red logs. I really do not understand the http://supervisor/core as i did not enter that anywhere, just the 192.168.30.177 into the flow.

4 Jan 01:33:25 - [info] [server:Home Assistant] Connecting to http://192.168.30.177:8123
4 Jan 01:33:25 - [info] [server:Home Assistant] Connecting to http://supervisor/core
4 Jan 01:33:30 - [info] [server:Home Assistant] Connecting to http://supervisor/core
4 Jan 01:33:30 - [info] [server:Home Assistant] Connecting to http://supervisor/core
1 Like

are you getting values at the sensor?
throw a debug node in one of the sensor nodes place, and set msg to entire msg and trigger the inject node on the left/start.

Then we can debug based on whether you are getting a value

also you need to add the node-red integration in the HA UI
Configuration > Integrations > + button (bottom right) - search for node-red.

well crap… I had 2 other 'node-red’s installed but not that last one… smh.

Doing that got your first example running.

Now back to the 3D version…

I get what appears to be a good message from the switch:

"payload":{"attributes":{"distance":0.4,"lastUpdatedAt":"2021-01-05T01:18:17.664Z"},"id":"bluetooth-classic-a8-34-6a-87-6b-91","name":"a8:34:6a:87:6b:91 Room Presence","distributed":true,"distances":{"sanctumBT":{"lastUpdatedAt":"2021-01-05T01:17:53.464Z","distance":21.3,"outOfRange":false},"lrBT":{"lastUpdatedAt":"2021-01-05T00:50:22.601Z","distance":5.9,"outOfRange":false},"lr2BT":{"lastUpdatedAt":"2021-01-05T01:18:17.664Z","distance":0.4,"outOfRange":false},"officeBT":{"lastUpdatedAt":"2021-01-05T01:18:22.004Z","distance":6.8,"outOfRange":false}},"timeout":40,"state":"lr2BT"},"statusCode":200,"headers":{"x-powered-by":"Express","content-type":"application/json; charset=utf-8","content-length":"2513","etag":"W/\"9d1-w1aHnT1BQNmLh6bm5zq3ebfp7MA\"","date":"Tue, 05 Jan 2021 01:18:32 GMT","connection":"close","x-node-red-request-node":"7f20469b"},"responseUrl":"http://192.168.30.98:6415/entities","redirectList":[],"parts":{"id":"ed8a1a0f.086018","type":"array","count":9,"len":1,"index":8},"_msgid":"9f9e2faf.22191"}

If I go to the 1st function after the switch, I get:

TypeError: Cannot read property 'distance' of undefined

const trilat = global.get('lmTrilateration3d');
 
// 3D
// At least 4 beacons position and distance to locate 3D, if have only 3 beacons, z can not calculate then replace by undefined
var input3D = { data: [
//         X       Y       Z                  R
    [      10,     55,     100,   msg.payload.distances.lr2BT.distance],
    [    100,    80,      10,   msg.payload.distances.lrBT.distance],
    [    90,    100,      100,   msg.payload.distances.officeBT.distance],
    [     55,   30,        10,   msg.payload.distances.sanctum2BT.distance]
]};
msg.payload = trilat.locate3D(input3D);
return msg;

I have the trilateration package installed and referenced in the pi (running node-red).

pi@lr2BT:~/.node-red $ npm install lm-trilateration3d
+ [email protected]
updated 1 package and audited 78 packages in 3.363s

19 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
    //    global.get("os")
    functionGlobalContext: {
        trilateration:require('trilateration'),
        lmtrilateration3d:require('lm-trilateration3d')
        // os:require('os'),
        // jfive:require("johnny-five"),
        // j5board:require("johnny-five").Board({repl:false})
    },
    //

on first glance it looks like you are only getting SanctumBT not Sanctum2BT

Yep, mis-keyed an extra 2 in the function… the 4 nodes are:
lrBT, lr2BT, officeBT, and sanctumBT. removed that but still getting the same error.

TypeError: Cannot read property ‘locate3d’ of undefined

Searched for similar error and tried defining it as blank first but that didn’t work either… I feel like I am so close :frowning:

const trilat = global.get('lmTrilateration3d');
 
// 3D
// At least 4 beacons position and distance to locate 3D, if have only 3 beacons, z can not calculate then replace by undefined
var input3D = { data: [
//         X       Y       Z                  R
    [      10,     55,     100,   msg.payload.distances.sanctumBT.distance],
    [     100,     80,      10,   msg.payload.distances.lrBT.distance],
    [      90,    100,     100,   msg.payload.distances.lr2BT.distance],
    [      55,     30,      10,   msg.payload.distances.officeBT.distance]
]};
msg.payload = trilat.locate3D(input3D);
return msg;

this seemed to happen to me when one of the values wasn’t correct/present.

Have you parsed the result through a JSON node and checked in a debug note that the path is msg.payload.distances.XXXX.distance ?

also check you are getting the array split properly
and then finally check with a debug before the 3d trilateration step to ensure msg.payload.distances.XXXX.distance all have values

Testing my knowledge here but it looks like the msg.payload.distances.xRAx.distance is correct and they all have values. Is this the array you speak of? If not, not sure where/how to check.

{
	"attributes": {
		"distance": 3.9,
		"lastUpdatedAt": "2021-01-06T00:24:11.681Z"
	},
	"id": "bluetooth-classic-a8-34-6a-87-6b-91",
	"name": "a8:34:6a:87:6b:91 Room Presence",
	"distributed": true,
	"distances": {
		"sanctumBT": {
			"lastUpdatedAt": "2021-01-06T00:24:05.076Z",
			"distance": 22.1,
			"outOfRange": false
		},
		"lrBT": {
			"lastUpdatedAt": "2021-01-06T00:24:11.681Z",
			"distance": 3.9,
			"outOfRange": false
		},
		"lr2BT": {
			"lastUpdatedAt": "2021-01-06T00:23:51.480Z",
			"distance": 14,
			"outOfRange": false
		},
		"officeBT": {
			"lastUpdatedAt": "2021-01-06T00:23:05.849Z",
			"distance": 20.3,
			"outOfRange": false
		}
	},
	"timeout": 50,
	"state": "lrBT"
}

yep, but you need to parse it through a JSON node

so the result is msg.distances[0]distance or msg.distances.sanctumBT.distance

then in the debug node, listen for just the msg above to ensure its coming through ok.

I guess that’s the problem. I’m not getting that (or any other sensor) from the json connected to the switch. Trying to troubleshoot but since the data is there I guess it is a formatting problem?

Now just getting “TypeError: Cannot read property ‘sanctumBT’ of undefined”

When this happens to me I put a debug node in each step and set it to complete msg object to check where it’s breaking down

This looks great! It would definitely make room-assistant usable, this way I often get false positive presences, because one raspi is at a wall to another room.

But unfortunately I do use hassio, so I have Node-Red installed as an add-on. Has anybody tried to install triangulation? There is regrettably no apt-get in hassio, nor is npmavailable by the system. I can find the settings.js but under /config/node-red/settings.js. I think there is no sense in adding the trilateration:require('trilateration') line without it being installed. Maybe there is an option to install it?

I am sill trying to make these works but you may be able to install trilateration by putting this

npm_packages:
   - lm-trilateration3d
   - trilateration

in the configuration file of node red
edit:
it works but only with the two 2d version

Hi @jaburges, this project is looking awesome. Are you still working on it and do you have an update on its performance?

Thanks!

I moved house so that has somewhat set things back - there is a discord channel just for chatting about room presence