iCloud device data integration in openHAB

No worries! :wink:

…by the way, THANKS for your great work :+1:

I dont know how to initiate a bridge update ?
I only want to get the iphone location on demand, so i set up the refresh cycle in the binding
to a big count 1000 for example
And the wenn “receive” command i want to get the actual Location
Any Idea ?

Hi @colognebroker

you can send a refresh command to the location item; that should trigger an manual update. In a rule use

itemName.sendCommand(REFRESH)

with kind regards,
Patrik

Hi Patrik

i have a family share
when i want to execute “find my Iphone” it only works for the initial accout
not for my family members
Other functions work as “location” or Battery
but not “Find my Iphone” for my Kids
If i configure a bridge for each Family meber it works, but thats not the best solution for me
It there a bug or a config error?

Hi @colognebroker,

the binding “just” sends a “find my device” request using the given account and device id; do you see something in the logs (TRACE) when such a request fails?

It might be that this is the way apple designed it; and you have to use multiple bridges - but I´m not sure … let´s see if the logs will tell us something.

with kind regards,
Patrik

Hello Guys,

maybe someone can help me.
I installed the iCloud Binding and i works well.

Now i want to use a Presence Detection so Openhab can run a Rule when i arrive at home.
But i am not sure how to do this.

In the first post is a rule for Loaction matching:

rule “My Work iPhone Location”
when
Item iPhone7_Coordinates changed
then
logInfo(filename, “My Work iPhone Location”)
iPhone7_Location.postUpdate(locationDistance.apply(iPhone7_Coordinates, home, “Home” 200))
// If you don’t want to translate your GPS coordinates to an address, just remove the following line
iPhone7_Location_Address.postUpdate(locationAddress.apply(iPhone7_Coordinates))
end

But in my opinion i must somewhere put my Cordinates in for my Home Location or i am wrong?

Sorry i am realtiv new to openhab.

Can someone post a tutorial about how to create a location based rule?
I want to control my heater depending to my location.
If i think about it it’s a pretty huge effort to calculate vectors and stuff to determine the distance from home …

Thank you :slight_smile:

If you don‘t mind reading the beginning of this conversation, you will find a rule exactly doing this, calculating distance between two locations.

2 Likes

Oh my … sorry … i even found that before (a few weeks ago) but could not remember.
Thank you! I’ll give it a try!

I came across a situation, where the provided Location Match rule didn’t worked well. The better approach was, to check if the iPhone is within a area that is shaped like a rectangular. So I came to this solution (the area is defined by the top left and the lower right corner), I’d like to share with the community:

rule "iPhone Location Match - Rectangular"
when
  Item your_iPhone_Location changed
then

val Double top_left_corner_lat = 51.911111   //replace this by your needs
val Double top_left_corner_lon = 11.611111  //replace this by your needs
val Double lower_right_corner_lat = 51.811111  //replace this by your needs
val Double lower_right_corner_lon = 11.511111  //replace this by your needs

val PointType iPhone_Location = your_iPhone_Location.state as PointType
val Double iPhone_lat = iPhone_Location.getLatitude()
val Double iPhone_lon = iPhone_Location.getLongitude()

if (iPhone_lon > top_left_corner_lon && iPhone_lon < lower_right_corner_lon && iPhone_lat < top_left_corner_lat && iPhone_lat > lower_right_corner_lat){
   // do something, when the iPhone is within the area
} else {
  // do something else
}
end
3 Likes

Hi,

sorry I’m not a Software guy and I have read this up and down. I end up totally confused. is working, is not working or has been removed in the latest release. A short tutorial for guys like me would be help full. over 300 site’s describes a lot things were I understood are now atomized by the binding. would it be possible to give us a Idea what is needed to get distance calculation and Adresse display done with the existing binding status?
At the beginning you start with Items (that is clear!), then you have 6 rules in total. Do I need all of them? Or is it okay just to import definitions and add rule distance calculation plus translate position to address? What about other examples? Do I need “Rule for location matching and address translation“ or is it a other way to get the same result?

Any help with that would be highly appreciated.

Thanks in advance

Marcel

If you have a look at the Binding documentation, you can see that it does not do the address translation or location matching. So if you want to have both features, you need the 2 rules.

Hallo Hans-Jörg,

Thanks for your replay. Unfortunately I read this fact to late. At this time I tried almost everything I have read in that discussion.

I know now that I need write a rule for that. I also understood that I have to import some variables to get the rule to work but I don’t know if I still need additional jason transform scripts or if it is just okay to use the specified rules. I learned a lot during last month how to use openHAB and can write easy rules but I still challenging with does rules. I need a point were I can start ( working rule) so I can play with but for right now I didn’t get this rules to work. The binging self is fine and I can display the items provided but the rules I have no luck.

Thanks

Marcel

So let’s start.
All references can be found in the first post of this conversation.

imports and definitions

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

val String filename = "icloud.rules"
//my home location
val PointType home = new PointType(new DecimalType(51.xxxxxxxxxxxxxx), new DecimalType(6.xxxxxxxxxxxxxxx))
//my work location
val PointType work = new PointType(new DecimalType(51.xxxxxxxxxxxxxx), new DecimalType(6.xxxxxxxxxxxxxxx))

Function to calculate distance from location

	// 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 translate location to address

// 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=" + iPhone7_Coordinates.state.toString + "&language=german&sensor=true"
	val String geocodeJson = sendHttpGetRequest(geocodeURL)
	var String formattedAddress = transform("JSONPATH", "$.results[0].formatted_address", geocodeJson)
	formattedAddress = formattedAddress.replace(", Germany", "")
	return formattedAddress
]

Rule for location matching and address translation

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

Thank you very very much. As soon as I come home I will try that. I really appreciate this abstract.

I keep you updated.

Marcel

Hallo Hans-Jörg,

thanks for the short instruction. this was the Info I missed or just didn’t understood. it works now.

thanks

Marcel

Hallo Guys,

I do have one more challenge. the distance from home calculation seems to have some challenges. When I’m at home and the distance are just a few meters I get displayed the correct value but when I’m far away from it shows “unknown”. Do you have any idea what the problem could be?

Thanks in advance

Marcel

Hi Marcel,
that‘s the way the rule works. If you are within a defined distance around your home, than you get back „Home“. Otherwise it‘s always unknown. But you can use the address translation to display a human readable translation of your iDevices coordinates.

Hi Christoph,

thanks for your replay. now I understood. I use already adress translation and it works well.

Thanks

Marcel

Hi!

I recognized huge battery consumption while using this binding on my iPhone 6s and the 5s of my wife.
The time was set to 9 mins.
I tried to increase the time but it stops working when using numbers larger than 9.
Can someone confirm that?

1 Like