iCloud device data integration in openHAB

Tags: #<Tag:0x00007f1837e61940> #<Tag:0x00007f1837e61698> #<Tag:0x00007f1837e614b8>

(Paul Miller) #225

I can report that iPhone SE and iPad Air 2 are both working devices.

I still have two minor issues.

  1. The Distance From Home is static and when at home it is saying 750m. I have set the lat/long in the PaperUI regional settings to match my location reported by my iPhone and it still says the same after saving the change.

  2. I am seeing the following error in my logs any ideas?

2017-11-15 16:35:02.868 [INFO ] [.smarthome.model.script.icloud.rules] - Device (iPad Air2):     2
2017-11-15 16:35:02.878 [INFO ] [.smarthome.model.script.icloud.rules] - My iPhone Location
2017-11-15 16:35:02.882 [INFO ] [.smarthome.model.script.icloud.rules] - Function to transform iCloud jsonResponse is called
==> /var/log/openhab2/events.log <==
2017-11-15 16:35:02.883 [ItemStateChangedEvent     ] - IPhoneIPhoneSE_LastLocationUpdate changed from 2017-11-15T16:27:04.537+1300 to 2017-11-15T16:32:04.263+1300
==> /var/log/openhab2/openhab.log <==
2017-11-15 16:35:02.901 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'iPhone Location': The argument 'state' must not be null or empty.
2017-11-15 16:35:02.902 [INFO ] [.smarthome.model.script.icloud.rules] - Owner:         Paul Miller
2017-11-15 16:35:02.925 [INFO ] [.smarthome.model.script.icloud.rules] - Name:          Paul's iPad Air
2017-11-15 16:35:02.939 [INFO ] [.smarthome.model.script.icloud.rules] - Unique ID:     pHrLcNGp5Wv5uYzCD2Aig+EpA0NbkGqoemwWO7lEofQvVOFsRbG2Z+HYVNSUzmWV
2017-11-15 16:35:02.954 [INFO ] [.smarthome.model.script.icloud.rules] - BatteryStatus: NotCharging
2017-11-15 16:35:02.969 [INFO ] [.smarthome.model.script.icloud.rules] - BatteryLevel:  1.0
2017-11-15 16:35:03.007 [INFO ] [.smarthome.model.script.icloud.rules] - Timestamp:      2017-11-15T16:30:08.730+1300
2017-11-15 16:35:03.019 [INFO ] [.smarthome.model.script.icloud.rules] - Latitude:      -41.229795394503725
2017-11-15 16:35:03.033 [INFO ] [.smarthome.model.script.icloud.rules] - Longitude:     174.8199854327131
2017-11-15 16:35:03.045 [INFO ] [.smarthome.model.script.icloud.rules] - Accuracy:      10.0
2017-11-15 16:35:03.052 [INFO ] [.smarthome.model.script.icloud.rules] - Location:      -41.229795394503725,174.8199854327131
2017-11-15 16:35:03.072 [INFO ] [.smarthome.model.script.icloud.rules] - TimeStamp:     2017-11-15T16:30:08.730+1300

It seems to be caused by this line:
val String owner = transform(“JSONPATH”, “$.userInfo.firstName”, jsonResponse) + " " + transform(“JSONPATH”, “$.userInfo.lastName”, jsonResponse)



(Christian) #226

Hi Eric. Thanks for the hint, it works :slight_smile:

You need to integrate a Google API key in the URL:

The concatenation of the URL in my rule looks now as follows:

str_icloud_iPhone_GMap_URL.postUpdate("https://www.google.com/maps/embed/v1/place?key=[My Google API KEY]&q=" + coordinates)

(Patrik Gfeller) #227

Hi Paul,

do you use the binding; or the scripts. If you use the scripts you might want to give the binding a try (from the market place); it automatically provides the distance from home.

with kind regards,

(Nolan Garrett) #228

@smar were you able to use this in a meaningful way to get more timely updates? Can you share your implementation? I want to use the binding to track the location of our Apple devices to determine if we are home. Right now the refresh cycle of 5 minutes plus the iCloud update frequency means OH2 may not know that we are home for up to almost 10 minutes after we’ve arrived.

(Paul Miller) #229

Well that sorted me out.

I was using both! DOH…
I tried the binding but did not seem to get anything so I rtead this thread
and implemented the scripts, needing to change the names of the items and
suchlike to match the ones created by the binding.

More than once I wondered what on earth the binding was doing as it seemed
the scripts were doing all the heavy lifting. With your comment I have
removed the rules file and went back to investigate why the binding was not
working. Then I say the Refresh Switch so set that to ON and started to see
the results in my sitemap.

I will take a look again after I go into work tomorrow to see if it works
there too and reflects the correct data, but looks good right now



[EDIT] Actually it only gets new data when I set the Refresh Switch to ON and only once. I have set the Interval to 5 minutes (default) why is it not automatically refreshing every 5 mins, what have I missed?

(-) #230

@nolan_garrett For my presence at home detection, I use a combination of iCloud, Owntracks and ARP table notifications from my router. iCloud can be up to 10 minutes out of date, but I find that Owntracks is usually quite quick and my ARP table monitoring is also within a minute. Thus presence at home is usually detected by OH2 by the time we have finished parking and reached the front door.

The corollary though is that detection for when the house is empty can take up to 10 to 15 minutes, as it takes that long for my firewall to release the entry in its ARP table. I haven’t looked into reducing this as it is fine for my purposes. However, one work-around could be to give precedence to Owntracks’ geofence Exit message over the ARP table data. Not sure how well that would work in practice, but from my experience of Owntracks, it should be reasonably accurate.

For myself, I use the iCloud (and also similar Android) location solutions more to show where family members are at any time on an openHAB sitemap that each family member has access to.We have refresh buttons on the sitemap such that we can get accurate location data if required. iCloud can be forced to get an updated location at any time by clicking refresh again immediately after it has given you the the stale location info. That way, you don’t have to wait 10 minutes for the iCloud refresh cycle. This will of course impact the iPhone user’s battery, and so probably not something you want to do in a rule.

(Patrik Gfeller) #231

Hi Paul,

what OH version do you use? Do you see anything in the log (if you start OH in debug mode) that shows that it tries to update and fails?

with kind regards,

(Paul Miller) #232

I am using OH 2.1
can you advise the karaf command that will enable binding debug mode?
I cannot easily startup OH server in debug mode as it is my production
system and I do not want to cause disruptions.



(Patrik Gfeller) #233

Hi Paul,

sorry - this I do not know; maybe you´ll find some advice in the following discussion:

with kind regards,

( ) #234

Hey Paul!
There are multiple options. See: http://docs.openhab.org/administration/logging.html
The easiest is you connect to the remote console and type: log:set DEBUG org.openhab.binding.icloud

(Nolan Garrett) #235

Thank you, this is helpful!

(Paul Miller) #236

Thanks @ThomDietrich
I have tried setting the logging to DEBUG using

log:set DEBUG org.openhab.binding.icloud

and then tried filtering using the filter below:

log:tail org.openhab.binding.icloud

I monitored and got no log entries, so I forced a refresh using the switch and got an output. So it would seem to suggest the DEBUG and tailing are working but under normal circumstances there is no 5 minute refreshing going on.

09:53:57.964 [DEBUG] [binding.icloud.handler.BridgeHandler] - iCloud bridge refreshing data ...
09:54:00.686 [DEBUG] [binding.icloud.handler.BridgeHandler] - iCloud device discovery for [iPhone SE]
09:54:00.699 [DEBUG] [binding.icloud.handler.BridgeHandler] - iCloud device discovery for [iPhone 4s]
09:54:00.707 [DEBUG] [binding.icloud.handler.BridgeHandler] - iCloud device discovery for [iPad Air 2]
09:54:00.719 [DEBUG] [binding.icloud.handler.BridgeHandler] - iCloud bridge data refresh complete.

I have never rebooted my device since installing icloud, is there perhaps something that needs a reboot to start the chron item scheduling?

Not sure what to try next other than a reboot, :frowning:

(Tomislav Gudlek) #237

Hey, I’m trying to use the binding as well.

It works fine if I add things through Paper UI, but if it’s done through a config file I get this error for each of the things:

2017-11-18 11:56:36.204 [ERROR] [ome.core.thing.internal.ThingManager] - Exception occurred during bridge handler (‘icloud:account:tgudlek’) notification about handler initialization of child ‘icloud:device:tgudlek:5fe26aff’: null
java.lang.NullPointerException: null
at java.lang.String$CaseInsensitiveComparator.compare(String.java:1193) [?:?]
at java.lang.String$CaseInsensitiveComparator.compare(String.java:1186) [?:?]
at java.lang.String.compareToIgnoreCase(String.java:1239) [?:?]
at org.openhab.binding.icloud.handler.DeviceHandler.getDeviceData(DeviceHandler.java:168) [198:org.openhab.binding.icloud:]
at org.openhab.binding.icloud.handler.DeviceHandler.update(DeviceHandler.java:53) [198:org.openhab.binding.icloud:]
at org.openhab.binding.icloud.handler.BridgeHandler.childHandlerInitialized(BridgeHandler.java:124) [198:org.openhab.binding.icloud:]
at org.eclipse.smarthome.core.thing.internal.ThingManager$10.run(ThingManager.java:811) [105:org.eclipse.smarthome.core.thing:]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
at java.lang.Thread.run(Thread.java:748) [?:?]

Binding-specific log doesn’t contain much information:

11:56:34.694 [DEBUG] [.binding.icloud.handler.BridgeHandler] - iCloud bridge handler started.
11:56:34.699 [DEBUG] [.binding.icloud.handler.BridgeHandler] - lCloud bridge initialized.
11:56:36.105 [DEBUG] [.binding.icloud.handler.BridgeHandler] - iCloud device discovery for [iPhone SE]
11:56:36.119 [DEBUG] [.binding.icloud.handler.BridgeHandler] - iCloud device discovery for [MacBook Pro 13"]
11:56:36.128 [DEBUG] [.binding.icloud.handler.DeviceHandler] - Initializing iCloud device handler.
11:56:36.122 [DEBUG] [.binding.icloud.handler.DeviceHandler] - Initializing iCloud device handler.
11:56:36.146 [DEBUG] [.binding.icloud.handler.BridgeHandler] - iCloud device discovery for [iPad]
11:56:36.144 [DEBUG] [.binding.icloud.handler.DeviceHandler] - Initializing iCloud device handler.
11:56:36.143 [DEBUG] [.binding.icloud.handler.DeviceHandler] - initializeThing thing icloud:device:tgudlek:1e0725f5 bridge status ONLINE
11:56:36.157 [DEBUG] [.binding.icloud.handler.DeviceHandler] - initializeThing thing icloud:device:tgudlek:5fe26aff bridge status ONLINE
11:56:36.153 [DEBUG] [.binding.icloud.handler.BridgeHandler] - iCloud bridge data refresh complete.
11:56:36.149 [DEBUG] [.binding.icloud.handler.DeviceHandler] - initializeThing thing icloud:device:tgudlek:1a6feb50 bridge status ONLINE
11:56:36.181 [DEBUG] [.binding.icloud.handler.BridgeHandler] - iCloud bridge refreshing data …
11:56:37.688 [ERROR] [.binding.icloud.handler.BridgeHandler] - null

Device IDs are set correctly in the config file (following the example from github repo), and the binding is installed manually using SNAPSHOT jar. I’m also using OH2.2.

(Patrik Gfeller) #238

Hi Tomislav,

I checked the code of the binding & it fails during the evaluation of a configured thing device id:

      String deviceId = thing.getProperties().get(IDPROPERTY);
       for (int i = 0; i < content.size(); i++) {
            if (content.get(i).getId().compareToIgnoreCase(deviceId) == 0) {
                return content.get(i);

Can you verify that all three things have the correct id set and maybe post your configuration? To be precise the “compareToIgnoreCase(deviceId)” seems to fail. I´ll also add additional logging to the binding in that area. I´ll let you know once that is ready.

with kind regards,

(Tomislav Gudlek) #239

Hey Patrick,

thanks for the swift reply!

Anyway, here’s the discovery info:

2017-11-18 11:54:42.771 [DEBUG] [binding.icloud.handler.BridgeHandler] - iCloud bridge handler started.
2017-11-18 11:54:42.776 [DEBUG] [binding.icloud.handler.BridgeHandler] - lCloud bridge initialized.
2017-11-18 11:54:44.455 [DEBUG] [binding.icloud.handler.BridgeHandler] - iCloud device discovery for [iPhone SE]
2017-11-18 11:54:44.465 [INFO ] [g.discovery.internal.PersistentInbox] - Added new thing ‘icloud:device:tgudlek:5fe26aff’ to inbox.
2017-11-18 11:54:44.468 [DEBUG] [binding.icloud.handler.BridgeHandler] - iCloud device discovery for [MacBook Pro 13"]
2017-11-18 11:54:44.487 [INFO ] [g.discovery.internal.PersistentInbox] - Added new thing ‘icloud:device:tgudlek:1a6feb50’ to inbox.
2017-11-18 11:54:44.489 [DEBUG] [binding.icloud.handler.BridgeHandler] - iCloud device discovery for [iPad]
2017-11-18 11:54:44.507 [INFO ] [g.discovery.internal.PersistentInbox] - Added new thing ‘icloud:device:tgudlek:1e0725f5’ to inbox.

and this is my config

Bridge icloud:account:tgudlek [appleId="t@gudlek.com", password="hunter2", refreshTimeInMinutes=5] {
    Thing device 5fe26aff "Tomi's iPhone" @ "World"
    Thing device 1e0725f5 "Tomi's iPad" @ "World"
    Thing device 1a6feb50 "bowie (Tomi's MacBook Pro)" @ "World"

(Patrik Gfeller) #240

please remove the password from the example; as it was already posted => change it

(Tomislav Gudlek) #241

No worries, it’s a fake one.

(Patrik Gfeller) #242

Hi Tomislav,

I can confirm that you´ve found a bug in the binding; please use paper UI for the moment for the thing creation. I´ll work on a fix this weekend and let you know once an updated binding is available.

thanks for providing the info and kind regards,

(Tomislav Gudlek) #243

Thanks, Patrick! Kudos for the great work you’re doing here :slight_smile:

(Patrik Gfeller) #244

Hi Tomislav,

a new CI build with the fix is ready; please let me know if it works. If not the .log would be much appreciated.

with kind regards,