iCloud device data integration in openHAB

@Markus92
Hi Markus,

sorry for the late reply; I´m quite busy processing the feedback from the code review from the binding :slight_smile: . Unfortunately the binding is only compatible with the upcomming OH 2.2 release; it will not work properly with OH 2.1 anymore.

A short update to all: The code review for the binding is in process and I hope it will make it into the OH 2.2 release. Thanks to all who helped with testing. Some important information: The release version of the binding is a “reduced to the max” version, that does not support address lookup anymore. This funcionality was considered not specific to the binding and might be implemented later in a more generic way to make it available for all coordinates.

Also the “refresh” mechanism will use the standard OH refresh; thus the specific channel will be gone. But a refresh can be triggered by sending a refresh command to a device channel.

with kind regards,
Patrik

1 Like

Hey @patrik_gfeller,
you should also mention, that the address lookup can easily be implemented in a rule for the time being. So no need to be sad about the removal of that function. The rules needed are already available in the first posting of this thread: https://community.openhab.org/t/icloud-device-data-integration-in-openhab/32329/1

1 Like

Hi all,

I´m happy to report that the 1st version of the binding was merged to OH 2.2 and will be part of the release :slight_smile:. Once more a big thank to @ThomDietrich, @Kai, @martinvw, @hmerk for their patience and help. Without them the binding would not be possible.

Also many thanks to all who tested early versions of the binding and provided valuable feedback.

I have one small request: Documenting is not my strongest part; thus if you have improvements for the readme that would be beneficial for new users please provide me feedback. Prefered in a form that I can directly use in the document to improve it :slight_smile:.

with kind regards,
Patrik

4 Likes

Can you provide us the icons for the sitemap?
Is it also possible to set a standard zoom for the map? at the moment i think the view is a bit too high :stuck_out_tongue:

Not sure if the default widget can do this; but if you use basic ui (not the apps) the following might help you to create your map of dreams:

Unfortunately that does not work in the applications for an unknown reason.
with kind regards,
Patrik

I am getting a problem calling the distanceFrom method from the PointType class.

My Rule:

rule Sophia_Home_Distance
when
	Item ICloud_Sophia_Location changed
	or
	Item Home_Coordinates changed
	or 
	System started
then
	logInfo(Sophia_Home_Distance.name, "Current Location: {}", ICloud_Sophia_Location.state.class)
	logInfo(Sophia_Home_Distance.name, "Home Location: {}", Home_Coordinates.state.class)
	var DecimalType distanceType = ICloud_Sophia_Location.state.distanceFrom(Home_Coordinates.state)
	var long km = distanceType.intValue / 1000
	logInfo(Sophia_Home_Distance.name, "Distance: {}", km)
	Sophia_Home_Distance.sendCommand(km)
end

Log Output:

2017-12-19 15:04:45.264 [INFO ] [me.model.script.Sophia_Home_Distance] - Current Location: class org.eclipse.smarthome.core.library.types.PointType
2017-12-19 15:04:10.773 [INFO ] [me.model.script.Sophia_Home_Distance] - Home Location: class org.eclipse.smarthome.core.library.types.PointType
2017-12-19 15:04:10.775 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Sophia_Home_Distance': 'distanceFrom' is not a member of 'org.eclipse.smarthome.core.library.types.PointType'; line 316, column 35, length 65

Can somebody tell me why this method should not be available? Other peoples are using them as well and in the sourcecode i can see this method.

Kind regards,
robert

Did you overlook the working rule in the first posting here? iCloud device data integration in openHAB
The problem is your use of .state

Correction: it needs an update. @patrik_gfeller are you going to do that?

Here you go:

val PointType location = iPhone_Location.state as PointType
val PointType home = new PointType(new DecimalType(48.123456), new DecimalType(11.123456))
if (location.distanceFrom(home).intValue() < 150) {
   ...
}

You mean this rule:

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
	]

But location and place are of PointType and not of LocationItem?

Correct, the function distanceFrom belongs to PointType.

Btw this is kinda funny. Do you live in a trailer? :slight_smile:

OK, but i used PointType already (i thought because of the log output)
When i change the code like this (with this extra ‘cast’)

var DecimalType distanceType = (ICloud_Sophia_Location.state as PointType).distanceFrom(Home_Coordinates.state as PointType)

its working

Took some time why this should be funny, but i got it :wink:
No, but i like it to have some things be configurable (not in rules) and next year i will move.

1 Like

My explanation which (without checking) might be wrong: .state will return a generic type. This generic type doesn’t offer the distanceFrom function. If that is the case you can probably leave out the second “as PointType” because it’s implicit.

OK, maybe.
Thanks for helping.

You originally used

var DecimalType distanceType = ICloud_Sophia_Location.state.distanceFrom(Home_Coordinates.state)

where Home_Coordinates is not of Type PointType, so would need to be casted to PointType.

1 Like

Hello @patrik_gfeller,

until today I used an older binding from iCloud. It is a fantastic binding for my presence detection, thanks a lot for that.

But today, after updating the openHAB 2.2 from snapshot to the official release, I also wanted to switch to the official icloud binding.
I noticed that some channels were missing in the offical binding to earlier one.

Why are these channels no longer included?

Especially the channel Distance from home I missed, because I would have to rebuild this channel over a rule?

Now I downgraded to the older binding version. :wink:

I am not Patrick but might be able to answer on this.
Missing channels have been removed by intention, as those reflected not binding specific functionality, especially distance from home.
We have started discussing a more global approach.

Patrick did write something about that here:

Solution: Check out the first posting here to find rules which will give you the ability to do distance calculation and address resolution.

Sorry, I had skipped that.
I will try my luck between the Christmas holidays.

Thanks for your anwser.

1 Like

hi

i am on 2.2 now but it was the same on 2.1 - i have it done all with rules and not with the new binding.

but my “Location Adress” isnt working :frowning: this is my rule:

  // ===========================================================
  // 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=" + iPhone5s_Philipp_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
  ]

my item:

Location  iPhone5s_Philipp_Coordinates          "Koordinaten"             <suitcase>   (IOS)
String    iPhone5s_Philipp_Location_Address     "Location Address [%s]"                (IOS)

my result:
41

any ideas ? LogInfo of my Coordinates (iPhone5s_Philipp_Coordinates) is correct - thanks!