iCloud device data integration in openHAB

Tags: #<Tag:0x00007f6cea1c1340> #<Tag:0x00007f6cea1c1200> #<Tag:0x00007f6cea1c0f80>

(Max1968) #346

I’m using this rule, it seems you don’t need this “sensor” and “language” stuff you are using. somewhere here is a message about how to register for the API key in case you don’t have one yet

rule "MacBook Dad formatted address"
        Item MacBookDadLocation changed
        val _url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + MacBookDadLocation.state.toString + "&key=abcdef"
        val _geocodeJSON = sendHttpGetRequest(_url)
        val _address = transform("JSONPATH", "$.results[0].formatted_address", _geocodeJSON)

(Martin Puff) #347

Can someone help me to create an rule when my distance is less then 5000m from home, open the garage door?
Maybe someone have a rule like this already and can post this for me :slight_smile:
This would be great.

(Oliver K.) #348


i´ve a problem with this part of the rule:

iPhone_Location.postUpdate(locationDistance.apply(iPhone_Coordinates, home, "Home", 200))

it generates this error message:

[ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Standortbestimmung: iPhone': Number of arguments did not match. Expected: 4 but was: 2

When the rule file is loaded then i get this mesages:

   [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'icloud.rules', using it anyway:

   Incorrect number of arguments for type Function2<P1, P2, Result>; it cannot be parameterized with arguments <GenericItem, PointType, String, Number, String>


I found the error. I made a mistake in the Lambda function. I used type Function2 but i need type Function4.

(Cyborg) #349

Can anyone confirm that on OH2.2 and latest version of the binding, you can persist the location of a device? It doesn’t seems to log it, not even attempt to do it (when looking at influxDB logs).

Seems to be a bug.

(Martin Korsrud) #350

I do not have exactly what you are looking for, but I´ve made an example rule that calculates the distance from home. Maybe you can use part of it…

 Rule - Distance from home
 This rule is triggered by an updated location item (Martin_Location). The location 
 item holds the coordinates to my iPhone and is updated by the Bridge/Thing in an 
 iCloud binding. The rule updates an item (Distance_From_Home) by calculating the 
 differene between two locations (a static HOME location and Martin_Location)
 1. An .items file with the following content

 Location Home_Location 
 Number Distance_From_Home

2. A configured Bridge/Thing using the iCloud binding with a location item (in this case Martin_Location)

rule "Distance from home"

	Item Martin_Location changed

// ***************************************************************************
//  Set the location for HOME (tip - use google maps to find the coordinates).
// *************************************************************************** 

 // The Norwegian Royal Palace (Lat, Lon)... 
 Home_Location.state = new PointType(new DecimalType(59.916940), new DecimalType(10.726740))

// ******************************************************************************
// Calculate the distance from HOME (Home_Location) and iCloud (Martin_Location)
// ******************************************************************************


// Optional logging to /var/log/openhab2/openhab2.log
 logInfo("Distance from home : ", Distance_From_Home.state.toString())

(Cyborg) #351

Thanks for that but it’s not what I am looking for.

I am looking to persist the data in InfluxDB so I can plot it overtime in Grafana, which doesn’t seems to work.

Pretty much like persisting a temperature value, the coordinates doesn’t seems to

(Philipp) #352

since OH 2.2 i have problems with my rules - i didnt use the binding now.

the first rule for my phone works, the second one for my watch is broken now and i get this:

[ERROR] [ore.transform.actions.Transformation] - Error executing the transformation 'JSONPATH': Invalid path '$.content[1].location.positionType' in '{"userInfo":{"accountFormatter":0,"firstName":.......

any ideas ? or should i switch to the binding ?

(Patrik Gfeller) #353

Why not give the binding a try :slight_smile:

(Armin Rauscher) #354


I tried now with several different steps to get the icloud binding running, but the PaperUI allways shows offline.
Does someone have an idea what i can do?

I tried to use my normal icloud password and later i tried an application-specific password, generated in my icloud account, but both ending in the following error:

Thanks, Armin

(Kevin) #355

Code 401 -> Unauthorized

Wrong Password ? You must use the Password for Login into icloud.com website … application based password don’t work

(Kevin) #356

is xue1204@gmail.com really a iCloud Account or only a AppleID?

(Armin Rauscher) #357

Hello, Thanks for the information, but what is the difference? i can login with this account to icloud.com. Thanks, Armin

(Armin Rauscher) #358

Hello, i tried to use both, but both not working.


(Kevin) #359

There must be an @icloud or if its older an @me / @mac Adress for an complete iCloud Account …

Are your devices in FindMyIphone in the @gmail account?

(Armin Rauscher) #360

Yes all devices are visible under this account in the FindMyPhone area.
How can i get such an icloud account?

Thanks, Armin

(Armin Rauscher) #361

Thanks for the Information, its working now.

(Oliver K.) #362


could somebody explain how to call the function with different “places”. The function itself is clear to me. Call the function with one place…also fine.

iPhone7_Location.postUpdate(locationDistance.apply(iPhone7_Coordinates, home, "Home" 200))

But if i have 4 places, do i need 4 rules with different iPhone7_Location Items?


(Hans-Jörg Merk) #363

No, as your phone has just one location which is passed to the function as coordinates.
What you need is several places (home, work, school, etc.) which will be compared to your actual location.

(Oliver K.) #364


thanks for your fast reply.

Ok, i have several places as you mentioned. So now when the rule is fired it will pass this to the function
(iPhone7_Coordinates, home, "Home" 200))
and compares actual location against “home”.

Should i now add 4 line to the rule like
iPhone7_Location.postUpdate(locationDistance.apply(iPhone7_Coordinates, office, "Office" 200))
iPhone7_Location.postUpdate(locationDistance.apply(iPhone7_Coordinates, home, "Home" 200))
iPhone7_Location.postUpdate(locationDistance.apply(iPhone7_Coordinates, school, "School" 200))
Sorry, i´m confused :thinking:

(Hans-Jörg Merk) #365

Sorry, my fault, did not read your post carefully enough.
Indeed, you need different items for showing your results.