Comparing distances

new2me07
Posts: 84
Joined: Fri Apr 07, 2017 9:40 pm

Comparing distances

Post by new2me07 »

First off thanks for all the time and effort on a great plugin!

I only have on rPI at the moment and I simply want to run a conditional action based on who is closer to said rPi. I imagine it will have to be script based and wondering if I should use txpowerreceived or Pi_0_Distance or something else?

Its a big PITA as the rPi I completely out of range of indigo so I can't really see anything real time, and I'm ok at modifying python, not so much its creation....

For reference I have a dummy switch connected to an aeotec microswitch that I use to set my receiver to Speaker B output, source as Apple TV, and airplay the shuffled "bathroom" playlist. I'd like to have it specific to who ever hits the switch. It's pretty much the highest WAF rating I've ever gotten with automation.
User avatar
kw123
Posts: 8705
Joined: Sun May 12, 2013 4:44 pm
Location: Dallas, TX
Contact:

Re: Comparing distances

Post by kw123 »

txpowerreceived or Pi_0_Distance:
distance is calculated from signalreceived and txPower:

Code: Select all

dist =  sqrt( 10**(  (txPower-rssi)/10 )  )
you can find discussion on how to calculate it on the web at many places.

"rPi is completely out of range of indigo", what does this mean : far away, not connected ..?

If you want to know which iBeacon is closest, yes currently you have to do this yourself. with triggers for each ibeacon and then rank the ibeacons.. But that is actually a good idea to add.

Give me a day. I can add a field that gives the device name of the closest ibeacon.

Q: what if no beacon is connected = all gone: should it keep that last name or make it blank? or "none"

Karl

[edit]
was easy to add..
next Q: should there be a cut off in distance: ie if distance > 10m (= not in room) ignore?
and should it be a parameter for each RPI or same for all?
User avatar
kw123
Posts: 8705
Joined: Sun May 12, 2013 4:44 pm
Location: Dallas, TX
Contact:

Re: Comparing distances

Post by kw123 »

here some screen shots:
1. RPI device edit
Screen Shot 2018-12-06 at 10.48.06.png
Screen Shot 2018-12-06 at 10.48.06.png (11.2 KiB) Viewed 1784 times
2. RPI device state:
Screen Shot 2018-12-06 at 10.47.51.png
Screen Shot 2018-12-06 at 10.47.51.png (4.26 KiB) Viewed 1784 times
you can get the device name ... w:

Code: Select all

		yyyy = indigo.devices["name of your rpi"].states
		xxx = yyyy["closestiBeacon"]
		if xxx.find("@")>-1:  
			nameOfBeacon = xxx.split("@")[0]
			distToRPI    = float(xxx.split("@")[1])
			indigo.server.log(" closest beacon to RPi is "+nameOfBeacon+" at distance of "+str(distToRPI))
			# do something with dist
			if distToRPI < 3: 
				indigo.server.log("beacon is very close" )
		else:
			indigo.server.log("no iBeacon is close" )
will publish later today . still need to do some testing and optimizing

Karl
User avatar
kw123
Posts: 8705
Joined: Sun May 12, 2013 4:44 pm
Location: Dallas, TX
Contact:

Re: Comparing distances

Post by kw123 »

@new2me07 check out the latest release v7.97.252. It should do everything you requested.

Karl
Post Reply

Return to “piBeacon”