iCloud device data integration in openHAB

Tags: #<Tag:0x00007fadf73df138> #<Tag:0x00007fadf73defa8> #<Tag:0x00007fadf73ded78>

( ) #21

This: 49.xxxxxxxxx,8.xxxxxxxxxx is not a simple float. You could try %s instead.
However these coordinates are pretty worthless unless you are a walking map.

On your Basic UI all you need to add are those two elements:

  • Text item=iPhone_Battery icon="iphone"
  • Text item=iPhone_Location icon="iphone"

… which are the result of the above rules and which actually are meaningful and comprehendible to the user.

(Christoph) #22

Thank you for your explanations.
%s did’t work either.

Because I’m obvious not a walking map, I finally added

Mapview item=iPhone_Coordinates height=5

to my Sitemap, which work’s well in Basic UI (in Classic UI the zoom level of the map isn’t correct)

( ) #23

Ah right, of course :smiley: sorry I didn’t think of it :slight_smile:

(André Rück) #24

hi there… very intresting solution! thanks for it!
in the log message there are all data but an error also:

"16:40:01.921 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule iCloud Data Retrieval: An error occurred during the script execution: The name 'iPhoneLocation' cannot be resolved to an item or type."

Any ideas?

Best regards

( ) #25

Thanks for the hint. There was a small spelling mistake in the first posting. You can check to see that there was indeed no item with that name in your items file. I’ve done the needed changes, didn’t test them though. Please let us know if all works fine now.

(Christoph) #26

An easy way to show a OpenStreetMap in Habpanel:

  1. Create an extra Sitemap
sitemap map label="Location" {
		Mapview item=iPhone_Coordinates height=13 //height depends from your needs
  1. Create a Frame Widget in HabPanel
    Tick the “Fill to edges” and “Hide title label” checkbox


  1. You can hide the default navigation from the Basic UI as described here to see just the Map in the Frame Widget.

(André Rück) #27


I wondered about the error in the designer but was not clever enough to solve the problem itself…

And yes, now it works very good…

(André Rück) #28

Hi guys,

another problem now: Finding a solution for a rule using this data!
I want to change a switch for presence detection with checking the location has changed

rule "iPhone Anwesenheit"
  Item iPhone_Coordinates changed
	if (iPhone_Location.state == home )

But this doesn´t work…
Also, it does not help to put the word home in quotation marks. The switch is also switched off without that the iphone changes the location.

I forgot to say: there is a second rule which switches the DummyItem to OFF when the iPhone_Location.state != home
Best regards

(Christoph) #29

You could adapt the iPhone Location Match rule (first create a new switch item iPhone_home):

// my home location
  val PointType work = new PointType(new DecimalType(50.12345), new DecimalType(10.12345))
  distance = location.distanceFrom(home).intValue()
  if (distance < 200) {
    iPhone_Location.postUpdate(String::format("%s (%dm)", "home", distance))
    if(iPhone_home.state != ON){
    return false
// my work location
  val PointType work = new PointType(new DecimalType(51.12345), new DecimalType(11.12345))
  distance = location.distanceFrom(work).intValue()
  if (distance < 200) {
    iPhone_Location.postUpdate(String::format("%s (%dm)", "Work", distance))
    if(iPhone_home.state != OFF){
    return false
  iPhoneM_Location.postUpdate("(unknown location)")
  if(iPhone_home.state != OFF){

( ) #30

@Syn 's solution looks just fine!

Besides: Your rule should work with two things in mind: home with and without quotation marks makes a huge difference. In the quote case you are comparing to the string “home”. In the unquoted case you are comparing with the variable named home - > this variable does not exist!!
Furthermore you should react on a change of the item iPhone_Location, not iPhone_Coordinates.
Lastly, if you implemented the rule as proposed, the iPhone_Location item will read “Home (13m)” and never be equal to “home”.

(André Rück) #31

Thank you for showing this solution… I did this before my post but i did it wrong. I will check and report

(Stefaan Bolle) #32

Any possibility to put the cleaned/working config on the OH2 documentation/howto pages at docs.openhab.org?
This would help a lot of people.

( ) #33

Hey! You are talking about the one in the first posting? We could easily add it to the list provided here: http://docs.openhab.org/tutorials/#community

(Stefaan Bolle) #34

Sorry, read over it :slight_smile:

( ) #35

I didn’t do anything yet :smiley: Would that be what you were asking for?

(Stefaan Bolle) #36

I am quite experienced in Openhab, using it since version 1.3, but putting somewhere the working icloud config in one text (forum contains mods, changes, corrections,…) would be great/extremely useful for newcomers using an idevice.

( ) #37

I take this as a yes. Okay then, gladly.

(Marcus) #38

Strange, followed the instructions given here and applied it in two differend scripts, one for myself and one for a second person. Each script is identical beside of apple id and pass.
While the sceond script runs ( I got all locations, battery status and so on) my own account seems to be different:

2017-08-04 06:45:00.019 [INFO ] [home.model.script.iPhone_Loc_M.rules] - Retrieving iCloud data
2017-08-04 06:45:01.563 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule iCloud Data Retrieval : null

Both accounts have the 2 factor auth on. both account have one iPhone each and a windows laptop registered. I verified the settings on both phones as well as on the apple id settings…they are identical.

Any idea what that could be?
Thinking of turning on debug mode, creating a new account …

( ) #39

Sounds like your execution doesn’t even get to the part where:

logInfo(filename, "HTTP Code: " + responseCode)
logInfo(filename, "Message: " + connection.responseMessage)

Try adding log lines to earlier steps in the script to figure out where the unexpected happens

(Dominic Bonneau) #40

Hi I am really interested in your integration of icloud. I have however a question … Does it affect the life of the battery of the iphone to locate them like that with icloud ??