iCloud device data integration in openHAB

Tags: #<Tag:0x00007f1825ee0540> #<Tag:0x00007f1825ee0298> #<Tag:0x00007f1825ee00b8>

( ) #326

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

(Patrik Gfeller) #327

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,

(Carsten) #328

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:

(Patrik Gfeller) #329

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,

(Querdenker2k) #330

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

My Rule:

rule Sophia_Home_Distance
	Item ICloud_Sophia_Location changed
	Item Home_Coordinates changed
	System started
	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)

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,

( ) #331

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) {

(Querdenker2k) #332

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?

( ) #333

Correct, the function distanceFrom belongs to PointType.

( ) #334

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

(Querdenker2k) #335

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.

( ) #336

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.

(Querdenker2k) #337

OK, maybe.
Thanks for helping.

(Hans-Jörg Merk) #338

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.

(Stefan) #339

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:

(Hans-Jörg Merk) #340

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.

( ) #341

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.

(Stefan) #342

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

Thanks for your anwser.

(Philipp) #343


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:

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

(Max1968) #344

maybe you have exceeded the limit for the “free” use of the google API and need to use a (free) API Key ? i had the same issue, since using an API Key I dont have that anymore

(Philipp) #345

thanks, how do i implement the api-key into the rule ?