This rule can be copied for every single device and location you want to be monitored, just change the item names.

rule "My Work iPhone Location"
when
Item iPhone7_Coordinates changed
then
logInfo(filename, "My Work iPhone Location")
iPhone7_Location.postUpdate(locationDistance.apply(iPhone7_Coordinates, home, "Home" 200))
// If you don't want to translate your GPS coordinates to an address, just remove the following line
iPhone7_Location_Address.postUpdate(locationAddress.apply(iPhone7_Coordinates))
end

Hey @patrik_gfeller, that looks interesting indeed. I shall test it at my brothers home
As you can grasp from @dan12345 's answer it might be beneficial to explain the way this script works, mention limitations and evaluate the accuracy. I’d for sure be interested in these details. Best and Thanks!

that looks fabulously useful… but a stupid question: is this is a normal OH rule? Doesn’t look like XTend…

I´m not an expert - I just checked the source code of the vera plugin and some other sources & with the help of OH-Designer ported it to a rule. It works as a normal rule - the syntax is probably closer to JAVA; but as said … other may elaborate the differences.

It works as a rule if the imports are present & of course the json transform needs to be present. If I understood right xtend is an extension to java - thus some things might be not as elegant as possible as there might be syntax suger that I could have used …

mention limitations and evaluate the accuracy. I’d for sure be interested in these details.

Sorry - I´m not sure about limitations … but let me know if you have problems; I´ll do my best to help. The script requests a json from apple server; in the answer you´ll also find the current accuracy, battery state as well as other information about the device queried.

Note: if there are more than one device registered the JSON paths need to be adjusted. Again - I´ll try to help if necessary.

Never even knew that’s possible. Wonder if we should not “promote” it further via a tutorial. Will just confuse some newbies.
I’ll test the script as soon as my brother is back in his apartment next week and will send possible rule improvements

I can’t get it to work, and i suspect that having many devices, might be the case.

Hi Robert,

yes - if you have multiple devices some small adjustments are required. For each device you´ll get a “content” in the JSON response. You can extract the location of the device by using the index in the JSON path. Below example will get the location of the 2nd device:

1st add the logInfo to your rule to check the response (I recommend an online json viewer); then you should be able to find yout which device has what index. As a second step adjust the JSON path accordingly. You can also extract the location of more than one device for the response of course.

@patrik_gfeller, this is great. We were able to retrieve some nice data from the API. You should think about renaming the thread to something like “iCloud device data integration in openHAB”.

As promised I did some digging myself and cam up with a few enhancements and corrections. The following is your code but extended. Please feel free to copy it to the first posting, I’ll redact it here later.

This looks excellent!! I’ve been looking for a way of switching off a smart switch when my iPhone is fully charged, so that it doesn’t continually over charge. This looks like the starting point to a solution! I’ll have to have a play…