Presence detection with iCloud binding

Tags: #<Tag:0x00007fd32202eb60> #<Tag:0x00007fd32202ea20> #<Tag:0x00007fd32202e7f0>

(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

Presence Detection Problems
(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:

(Gad Ofir) #5

Hi i copy and paste and i think its working

but DistanceFromHome changed from 47.59414801918072 to 47.70985558406823

i was expcting some number value , can you tell me if i did somthing wrong
or i need to take this and calc this some how?
or maybe add some import ? using OH2.2

rule “Distance from home”

Item BatmenVsGod_Location changed
infoHomeLocation.state = new PointType(new DecimalType(31.274104), new DecimalType(34.809167))
logInfo("Distance from home : ", infoDistanceFromHome.state.toString())
logInfo("home : ", infoHomeLocation.state.toString())

(Gad Ofir) #6

igonire all that its working and its great!!!

(Michael Shore) #7

I would be interested to know what your battery life is like, I also used this method to determine presence, but I found it killed both my wife’s and my own battery life

when it was configured i will admit it worked like a dream.

now playing with Wifi and bluetooth BLE presence.

(Gad Ofir) #8

sure let me test it :slight_smile:
give me some time