iCloud device data integration in openHAB

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

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.

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
    URL=https://Your.IP:8443/basicui/app?sitemap=map
    Tick the “Fill to edges” and “Hide title label” checkbox

Edit:

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

:slight_smile:

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…

1 Like

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"
when
  
  Item iPhone_Coordinates changed
then	
	if (iPhone_Location.state == home )
		{
		sendCommand(DummyItem,ON)	
		}
end

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

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){
    	iPhone_home.postUpdate(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){
    	iPhone_home.postUpdate(OFF)
    	}
    return false
   
  }
  iPhoneM_Location.postUpdate("(unknown location)")
  if(iPhone_home.state != OFF){
    	iPhone_home.postUpdate(OFF)
    	}
...
3 Likes

@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”.

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

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.

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

Sorry, read over it :slight_smile:
Thanks!

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

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.

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

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 …

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

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

I do not think so - as the information is sent to the iCloud anyhow; the rule does not query the device itself.

with kind regards,
Patrik

I’m not agree … when you ask iCloud where is the device iCloud send a request where is the iPhone … ( and may be once every X Time ) so if you send 20 request every day … it gonna affect the battery life !

For exemple : When I use Find my Friends with my girl friend when I open the app find my friends said where she was 1h ago then it refresh to is later location

As said - not sure; my devices are not noticably affected with 5 minutes poll time … also this discussions hints to that iCloud data does not consume as much battery as a tracking app:

1 Like