iCloud device data integration in openHAB

Tags: #<Tag:0x00007f616f5d9a80> #<Tag:0x00007f616f5d9968> #<Tag:0x00007f616f5d9850>

@patrik_gfeller I’ve already tried both ways…

First setup was using the console, then I reentered the passwd through UI several time’s. And yes I’m aware of App specific passwd’s, read it in the doc’s before I started…

I copy&pasted my login passwd tried it on icloud.com in the browser and pasted it into pUI right away, but it didn’t work out! :frowning:

@patrik_gfeller Rechecked the passwd in icloud.things and realized PaperUI never updated the passwd. I had one character to much in my passwd… removed the typo from the things file and tada Inbox is loaded!!!

THX for helping my wrap my head around it once more!!!

But I’ld consider it a bug that the pUI isn’t updating the things file! So as an EBI I’ld at least wish that to be mentioned in the doc’s… :wink:

Marcus,
How did you add a second account to the iCloud binding? I use the paperUI and don’t see any option to do it.

add another thing for the icloud binding

Ok, I was able to add a another iCloud account. But the binding is not finding any devices, like it did with the first account I added. In the paperUI the account shows its “Online”. Any ideas for getting it to find the devices.

Hello everybody,

I’ve explored the iCloud Binding a little bit more on the weekend.

First I switched from an old BETA version to the current release in 2.3.0 snapshot.

When integrating two iCloud accounts, I noticed that I also see the devices of the second iCloud account, via the family sharing, in the Paper UI Inbox.
The devices from the family sharing, do not provide the location but only for example the battery level back.
So I had to be careful when integrating things, which device I would add, came over which iCloud account.
After a few new rules (distance from home, formatted Address) I had achieved the status as with the BETA Binding.

Now I was interested, after I had read here of the many battery consumption, how big this is?

I had a test iPhone SE configured for this as follows:

  • The device had only the basic device configurations after reset.
  • Mobile -> connected to 4G (3-4 bars)
  • Wi-Fi -> on and connected (good connection)
  • Bluetooth -> off
  • Location service -> on

The battery was always fully charged (100%) for the test and operated for exactly 12 hours on battery power (8 am to 8 pm).

  1. Without iCloud integration, the battery still had 95% after 12 hours

  2. With iCloud integration and a refresh interval of 10 min. still 91%
    image

  3. With iCloud integration and a refresh interval of 5 min. still 86%
    image

From this it can be deduced, for the iphone SE, that within 12 hours the battery consumption by the iCloud binding with a refresh time of 10 min. -> 4-5% and at 5 min. -> 9-10%.

What can still be stated is that with every refresh the binding sends a request to the iCloud account and from the iCloud account at the same time a request is sent to the devices.

This means at a refresh time of 10 min. the scanned values are between 10-20 min. old.
At a refresh time of 5 min. correspond to 5-10 min. old.

So if you want to get a current value, you have to send the refresh twice in the case of a manual refresh (see Binding description), because the returned value is always from the previous request. Between the two refreshes should be 10-15 seconds.

Furthermore, in case of a manual refresh of the location for a device, a request will be sent from the account to all devices of the iCloud account!

image

Maybe this will help one or the other …

2 Likes

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
    }
}