Save Device Data to variable for math conversion


#1

1) Give a description of the problem

I’m trying a quick-and-dirty method of determining if two presence devices are close to each other. The math requires saving the latitude/longitude data to a variable for the equation, but nothing I’ve tried works. I’ve variables as dynamic, strings, decimals, maximum, sum, count, and many others, but nothing gets the data I need.

2) What is the expected behaviour?

The piston will pull latitude and longitude from the first person who enters an area (LatLeader, LonLeader) and compare them to the other presence devices (LatFollow, LonFollow). It’ll give the absolute value of (LatLeader-LatFollow)+(LonLeader-LonFollow) and, if the answer is below a threshold, will determine if they are close to each other.

3) What is happening/not happening?

I cannot get the lat/lon of the devices, nor save them to variables.

**4) Post a Green Snapshot of the piston![image|45x37]


#2

Having read your other post, just wondering if these are real or simulated devices? If simulated, I wonder if they return any data for lat/long?


#3

Dammit… You’re right. It was suggested to use simulated devices to test one part of the piston, and I’ve continued using them for this part as well.


#4

I’ve not used virtual devices for testing. Is it possible to assign values in the ide/app?


#5

Well, I’ve used virtual switches a lot to connect pistons to Alexa, and they just show an On/Off setting. I assumed the virtual presence sensors had my computer’s lat/lon, but they only show present/not present. Would be nice if I could throw coordinates into these devices, but I don’t see a way to do that.


#6

I think someone could write a device handler that would allow this, its just an addition to the current functionality. However the coding is beyond my understanding.


#7

I challemge you to rethink this formula… It only partially works if the two are in the same city.

For example, lets say

  • Leader lat 80, lon 80
  • Follow lat 75, lon 85

Your formula would return “0”…
(IE “near each other”)

Yet they would actually be 308 miles apart!


#8

Hey, WC! Nice to see you again. Haven’t seen you around in awhile. :slight_smile:

And actually, it worked rather well. Luckily, I changed the devices and had it running when my wife and daughter left together. It worked PERFECTLY!

(Now that it’s working, I’ll need to work on the “has/have” aspect, but that’s easy. I’ve already done it for several other pistons.)

I used this website to help me understand the range/distance of each decimal point.

http://wiki.gis.com/wiki/index.php/Decimal_degrees

I rewrote the piston a little, but my threshold was 0.00100, which iirc, looks to see if they’re within 300 feet of each other. They were well under that when they left. My son was still at home, and he wasn’t added to the group.

Actually, it would return “10” (The absolute value of 75-85, added to the difference of 80-80, which would be “0”.)


#9

For the record, I’m on a tiny screen, so did not look at your pisron at all. Glad that part works.

I’m trying to convey that the formula’s core logic is not precise.

(LatLeader-LatFollow)+(LonLeader-LonFollow)

…although using absolute numbers does help a lot. (I didn’"t see that mentioned earlier… My last post referred to 5 plus neg 5 = zero)

… But even using all positive numbers in your math, the distance cam be off over 30% ., if the two sensors are diagonall each other.

IE: 300 feet in that formula equates to real life between 210-300 feet as the crow flies.

As long as you are aware of the diagonal offsets, (that grows with larger numbers) then you can code accordingly.


#10

Oh, I wasn’t even expecting it to work so well the first time, but it looks like I nailed it. I had rewritten my Arrival piston before the wife and daughter came home, and when they came into my radius, the piston caught them and ignored me and my son, which was exactly what I wanted. The “300” radius assumes they are in the same car, and while I know from watching Life360 in real time that the icons are never exactly with each other, they’re certainly close enough for my piston to function as intended.

"I love it when a piston comes together."

image

(Google it, Millenials) :stuck_out_tongue: