iCloud device data integration in openHAB

I still can’t get the icloud binding to find the device on my second account I setup. I tried starting from scratch by removing the binding and the related thngs, rebooting and then reset everything back up. I can get the devices from the first account again, but not the second account. Anyone have any suggestions?

Really appreciate the work you’ve put into this binding, works pretty well so far. I tested with one of the rules posted in the examples, and while it appears to work I think the rule is not functioning correctly due to my GPS location. If the long is a negative number, it looks to me (I don’t write Java code even a little) that it’s not being evaluated properly. Has anyone else seen something similar, should I declare the value differently? Any help you guys can give would be appreciated.

val PointType home_location = new PointType(new DecimalType(xx.12976188681566), new DecimalType(-xx.30110466301934))

the above appears to always evaluate to null.

I can’t get Find My iPhone to work for my shared members (wife) on my iCloud with the binding. All devices on my own account works but not shared members.

Anyone here with the same problem or a solution?

Has anybody had success getting the ICloud binding account to discover the devices on a second ICloud account? My first Icloud account discovered all my apple devices. The second account I added (which Openhab2 shows as online in the PaperUI) is unable to find any devices. And I am unable to add it manually because I don’t now the device ID.

hey guys,

i finally moved from a flat to my own house :heart_eyes: and wasnt using openhab in the last couple of months…
last year my iCloud rules worked perfectly, my setup looks like in the first posting. (without the BINDING needed)

but something seems to be broken now - if i manually check my iCloud i get this error:

2018-08-09 13:18:57.149 [INFO ] [.smarthome.model.script.icloud.rules] - Retrieving PHILIPP iCloud Data ...
2018-08-09 13:18:57.165 [INFO ] [.smarthome.model.script.icloud.rules] - Function to retrieve iCloud data is called
2018-08-09 13:18:57.406 [ERROR] [marthome.model.script.iCloudRetrieve] - Error in iCloudRetrieve: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
2018-08-09 13:18:57.429 [INFO ] [.smarthome.model.script.icloud.rules] - Function to transform iCloud jsonResponse is called
2018-08-09 13:18:57.436 [ERROR] [ore.transform.actions.Transformation] - Error executing the transformation 'JSONPATH': the given parameters 'JSonPath' and 'source' must not be null
2018-08-09 13:18:57.441 [ERROR] [ore.transform.actions.Transformation] - Error executing the transformation 'JSONPATH': the given parameters 'JSonPath' and 'source' must not be null
2018-08-09 13:18:57.447 [INFO ] [.smarthome.model.script.icloud.rules] - Owner:         null null
2018-08-09 13:18:57.453 [ERROR] [ore.transform.actions.Transformation] - Error executing the transformation 'JSONPATH': the given parameters 'JSonPath' and 'source' must not be null
2018-08-09 13:18:57.459 [INFO ] [.smarthome.model.script.icloud.rules] - Name:          null
2018-08-09 13:18:57.464 [ERROR] [ore.transform.actions.Transformation] - Error executing the transformation 'JSONPATH': the given parameters 'JSonPath' and 'source' must not be null
2018-08-09 13:18:57.470 [ERROR] [ore.transform.actions.Transformation] - Error executing the transformation 'JSONPATH': the given parameters 'JSonPath' and 'source' must not be null
2018-08-09 13:18:57.476 [INFO ] [.smarthome.model.script.icloud.rules] - BatteryStatus: null
2018-08-09 13:18:57.482 [ERROR] [ore.transform.actions.Transformation] - Error executing the transformation 'JSONPATH': the given parameters 'JSonPath' and 'source' must not be null
2018-08-09 13:18:57.486 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'iCloud Data Retrieval': null

whats the best way to get it back to work ?
just change something in the config/rules or should i start using the binding ?
what do i need to change in my setup to use it with the binding ?
delete my whole config and start over ? or just change some little things ?

does this all work with “two-factor-authentication” !?

please help me out - thanks guys!

Is this still not working for you? I installed the binding this morning and I get a similar error

Status: Offline-communication_Error

sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Hello,
I have a need:
when the distance is smaller as X starts a rule, he sends me a pop up with the question “Do you want to open?” yes / no on ios with openhab app.
Based on the response, send an ON command.
It can be done?

Hello,

I have tried to use your functions and rules to get my iPhone location data, and got the following in the log (similar to the last few posts):

2019-02-05 22:04:26.027 [INFO ] [.smarthome.model.script.icloud.rules] - Retrieving My iCloud Data ...
2019-02-05 22:04:26.035 [INFO ] [.smarthome.model.script.icloud.rules] - Function to retrieve iCloud data is called
2019-02-05 22:04:31.313 [ERROR] [marthome.model.script.iCloudRetrieve] - Error in iCloudRetrieve: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
2019-02-05 22:04:31.322 [INFO ] [.smarthome.model.script.icloud.rules] - Function to transform iCloud jsonResponse is called
2019-02-05 22:04:31.347 [INFO ] [.smarthome.model.script.icloud.rules] - Owner:         null null
2019-02-05 22:04:31.355 [INFO ] [.smarthome.model.script.icloud.rules] - Name:          null
2019-02-05 22:04:31.363 [INFO ] [.smarthome.model.script.icloud.rules] - Unique ID:     null
2019-02-05 22:04:31.372 [INFO ] [.smarthome.model.script.icloud.rules] - BatteryStatus: null

Is there any way to make it work?

Hans-Jorg Merk, sorry to bring back a year old post, but for address translation you noted what needs to be configured. you have imports…, Functions… and Rule. I know where Rules go, but where do Imports and Functions go – would they be defined in an item file? Thanks, i have been away for some time.

Imports have to be at the top of your .rules file and functions (lambdas) are going into the same file. Functions are some kind of reusable rules.

Thank you. I will try it out.

I am pretty lost here. This is what i have – my long/lat from the iphone is “iPhoneK_Location” . I put all this into a rules file. I tried to output some of the strings in a sitemap, but they come up blank. Can take a look and see where I am off. And then how you would display in a sitemap? No worries if not, I will keep plugging away. Best.

import org.eclipse.xtext.xbase.lib.Functions

val String filename = "icloud.rules"
//my home location
val PointType home = new PointType(new DecimalType(41.xxxLONGxxx), new DecimalType(-73.xxxLATxxx))
//my work location
val PointType work = new PointType(new DecimalType(41.xxxLONGxxx), new DecimalType(-73.xxxLATxxx))

// Function called to calculate location distance
	val Functions$Function4<GenericItem, PointType, String, Number, String> locationDistance= [ Coordinates, place, placeName, distance2 |
	  val PointType location = Coordinates.state as PointType
	  var int distance
	  var String message
	  // my home location
	  distance = location.distanceFrom(place).intValue()
	  if (distance < distance2) {
	    message = (String::format("%s (%dm)", placeName, distance))
	  } else {
	    message = "(unknown location)"
	    }
	  return message
	]

// Function to transform location coordinates to address
val Functions$Function1<GenericItem, String> locationAddress= [ Coordinates |
	val geocodeURL = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + iPhoneK_Location.state.toString + "&language=german&sensor=true"
	val String geocodeJson = sendHttpGetRequest(geocodeURL)
	var String formattedAddress = transform("JSONPATH", "$.results[0].formatted_address", geocodeJson)
	formattedAddress = formattedAddress.replace(", USA", "")
	return formattedAddress
]

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

Please post your items and sitemap

Thank you.
Here is items

Group    iCloud_Group "iPhones"


//Kerry 6S
String   iPhone_BatteryStatus             "Battery Status [%s]" <battery> 	 (iCloud_Group) {channel="icloud:device:TKDiCloud:Kerry6S:batteryStatus"}
Number   iPhone_BatteryLevel              "Battery Level [%d %%]"  <battery> (iCloud_Group) {channel="icloud:device:TKDiCloud:Kerry6S:batteryLevel"}
Switch   iPhone_FindMyPhone               "Trigger Find My iPhone"           (iCloud_Group) {channel="icloud:device:TKDiCloud:Kerry6S:findMyPhone", autoupdate="false"}
Switch   iPhone_Refresh                   "Force iPhone Refresh"             (iCloud_Group) {channel="icloud:device:TKDiCloud:Kerry6S:location", autoupdate="false"}
Location iPhoneK_Location                 "Coordinates"                      (iCloud_Group) {channel="icloud:device:TKDiCloud:Kerry6S:location"}
Number   iPhone_LocationAccuracy          "Coordinates Accuracy [%.0f m]"    (iCloud_Group) {channel="icloud:device:TKDiCloud:Kerry6S:locationAccuracy"}
DateTime iPhone_LocationLastUpdate        "Last Update [%1$td.%1$tm.%1$tY, %1$tH:%1$tM]" <time> (iCloud_Group) {channel="icloud:device:TKDiCloud:Kerry6S:locationLastUpdate"}
Switch   iPhone_Home                      "Phone Home"            <presence> (iCloud_Group)
String   iPhoneK_Location_Address 		  "iPhone Location Address [%s]" 

And my try at sitemap - I have remarked out some where i played around with different rules output.

sitemap icloud label="iCloud" {
    Frame item=iCloud_Group {
        Text item=iPhone_BatteryStatus
        Text item=iPhone_BatteryLevel
        Text item=iPhone_Home
        Text item=iPhone_LocationAccuracy
		//Text item=iPhoneK_Location
        Text item=iPhone_LocationLastUpdate
		//Text item=formattedAddress
		Text item=iPhoneK_Location_Address
		//Text item=Kerry6S_LocationString
        Switch item=iPhone_FindMyPhone mappings=[ ON="Find!" ]
        Switch item=iPhone_Refresh mappings=[ REFRESH='Refresh now' ]
        // Mapview for BasicUI and Applications (Android/iOS)
        Mapview item=iPhoneK_Location height=10
    }
}

Has anybody had success getting the ICloud binding to discover the devices on a second ICloud account? My first Icloud account discovered all my apple devices. The second account I added (which Openhab2 shows as online in the PaperUI) is unable to find any devices. And I am unable to add it manually because I don’t now the device ID. Any help would be appreciated.

So far, I’ve got mine and my wife’s icloud accounts connected as 2 separate things and both are working fine. I just added the binding, then followed the docs for mine, got mine working perfectly and then just replicated it for my wife’s account…

The issue I have is that it refreshes too slowly for it to be totally useful as a presence detector, I’ve got to work out how to get it refreshing quicker to be relevant. I got 10 miles towards work before it told me I’d left my house, so if I’d set it to alarm cameras etc there is a time when no one is home and the camera isn’t set, and the same goes for coming home, the cameras were still armed so I set off the motion for 5 minutes before it got me as home…

EDIT

NB, I did have to be patient when I installed each one. I kept getting that my phone was offline and nothing updated etc, but I went away, made a cup of tea and then returned and it worked…I guess it just needs some time to set up / authenticate and then get it’s first few pings back and forth before it starts reporting properly.

I’ve not used the things in anger yet, nor have I rebooted the Pi so I’ll be monitoring the real life workings over the next week or so…

One question, I’m sure it’s pretty simple but I can’t see how I can make the refresh rate a bit shorter…

Is this set in the original binding set up, do I have to uninstall the binding to do it or is there another way?

EDIT

Found it, not sure why I couldn’t find it before, for anyone looking it’s in the icloud account thing.

So, that fixed, next question…

To use this as a proper presence detection I want to set it up with a bit of wasp in box methodology so that if a sensor detects movement it uses the ‘find my iphone’ option of this binding to do a manual refresh of my phones to determine if if is the family member returning home or not, (an idea I had to avoid having to set refresh of the binding to 1 minute and blow phone battery life).

Obviously, if the motion sensor records motion but the phones are not at home then it’s not a family member and the rule will trigger cameras to record, messages sent etc.

My question is over the item in the binding example:

Switch iPhone_FindMyPhone “Trigger Find My iPhone”

I know I can set it up on the basic UI as a button to press to update but

(a) can I use it as an action in a rule, ie if motion sensor = on then trigger find my iPhone and if so would the syntax be:

iPhone_Refresh.sendcommand(“REFRESH”)

and

(b) does it have limitations on the number of times it can be used or on battery life etc? I can’t imagine that it would be triggered too often as I’d set the rule to run only if the presence rule was set to ‘no one home’ but don’t want to max out the service as my presence rules would then fail…

Thanks in advance

Hi guys
Very impresive indeed. Currently I use network binding to locate my phone for presence detection on home WiFi but it’s not always 100%.
I would like to get more data on OH2 from my phone such battery level, location , etc.
Was planning to use owntracks for the above but was concerned about battery drainage.
What impact has iCloud monitoring on your phone’s batteries ? Would you suggest to stick to this method or to choose owntracks ?

Hi @patrik_gfeller

Is your approach able to get the location of friends as well (beside members from my family)?
Means:
I have setup my wife’s and my son’s phone to be in my “famliy”.
These have different AppleIDs but are associated with my AppleID to be in the same family.
I can see their phone’s location in the “find Friends” App.

However, I have friends which share their location permamently with me.
I can see them in the icloud.com web interface when opening “Find Friends”.
So I wonder, if these are retrievable with your approach (they are not visible in the iCloud binding).

Thanks in advance.

This would be pretty nice!
We´re currently able to receive a device location but not a persons location.
When using an Apple Watch, the “Where is?” app shows the Watch position when the phone stays at home.
This would allow an presence detection even when the phone is at home.

kind regards
Michael