Presence detection with iCloud binding

Tags: #<Tag:0x00007f6ce538b8d8> #<Tag:0x00007f6ce538b798> #<Tag:0x00007f6ce538b630>

(Robert) #1

I have the iCloud binding running, including fetching the location. Next step would be to get presence detection working in a generic way.

I was thinking to compare the location of my iPhone with the location of the openHAB location (which can be set in the system settings).

Is there already a way to determine the distance between any location and the ‘home’ location? Or should I build some kind of rule myself?

Any suggestions are appreciated.

If I get a working solution I will post back the results

(Rich Koshak) #2

There is an Item type Location and it has a distanceFrom method. So if you have your home location set in a Location Item and the phone location in a Location Item its as simple as:

if(Phone.distanceFrom(Home) as Number > 100)

I do not know whether the location built into OH is available to be used to populate an Item, but you can use Design Pattern: Encoding and Accessing Values in Rules to create and initialize one.

(Martin Korsrud) #3

I’m using a rule to do what @rlkoshak mentioned. Please see below

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

(Robert) #4

Note to self:

This thread has some nice examples: