nach dem wir das Thema Präsenzerkennung via WLAN und IFTTT ja hier im Forum schon ausführlich behandelt haben, gibt es seit openHAB 2.2 noch eine sehr interessante Möglichkeit sein iPhone zu orten und damit eine Präsenzerkennung abzubilden.
Das neue iCloud-Binding.
Mir kommt es bei der Präsenzerkennung auf zwei Dinge an. Einmal eine gewisse Trägheit, damit das iPhone auch Nachts mal aus sein kann und es trotzdem "zu Hause" angezeigt wird und zum anderen die Geschwindigkeit über die WLAN Präsenzerkennung. Ein weiterer Aspekt ist, dass ich auf allen iPhones die IFTTT-App installieren musste und entsprechende Accounts bei IFTTT anlegen musste. Das ist natürlich von der administrativen Seite her immer recht aufwändig.
Aus diesem Grund kam mir das iCloud-Binding gerade recht. Wer mehr als ein iPhone im Haus hat, sollte sich umbedingt die Familienfreigabe von Apple anschauen. Wenn alle Apple-ID´s in der Familienfreigabe sind, reicht nachher der Hauptaccount(Organisator) aus, damit das iCloud-Binding ALLE iPhones der Familie findet.
So, aber jetzt mal zu dem, was Euch wirklich interessiert

ITEMS:
Code: Alles auswählen
Group gCyreliansiPhone "Cyrelian´s iPhone" <iphone>
String CyreliansiPhone_BatteryStatus "Batteriestatus [%s]" <iphone> (giCloud,gCyreliansiPhone) {channel="icloud:device:iCloud:cf25XXXX:batteryStatus"}
Number CyreliansiPhone_BatteryLevel "Batterie Level [%.0f %%]" <battery> (giCloud,gCyreliansiPhone) {channel="icloud:device:iCloud:cf25XXXX:batteryLevel"}
Switch CyreliansiPhone_FindMyPhone "Find My iPhone" <find_iphone> (giCloud,gCyreliansiPhone) {channel="icloud:device:iCloud:cf25XXXX:findMyPhone"}
Location CyreliansiPhone_Coordinates "iPhone Koordinaten" (giCloud,gCyreliansiPhone) {channel="icloud:device:iCloud:cf25XXXX:location"}
Number CyreliansiPhone_LocationAccuracy "Standortgenauigkeit [%.0f m]" <accuracy> (giCloud,gCyreliansiPhone) {channel="icloud:device:iCloud:cf25XXXX:locationAccuracy"}
DateTime CyreliansiPhone_LocationLastUpdate "Letztes Update [%1$td.%1$tm.%1$tY, %1$tH:%1$tM]" <time> (giCloud,gCyreliansiPhone) {channel="icloud:device:iCloud:cf25XXXX:locationLastUpdate"}
String CyreliansiPhone_Location "Standort [%s]" <suitcase> (giCloud,gCyreliansiPhone)
String CyreliansiPhone_Location_Address "Aktueller Standort [%s]" <map> (giCloud,gCyreliansiPhone)
Code: Alles auswählen
import org.eclipse.xtext.xbase.lib.Functions
val String filename = "icloud.rules"
//API key for Google Maps API
val String GoogleAPIKey = "yourGoogleAPIKey"
//my home location
val PointType home = new PointType(new DecimalType(50.XXXXXXXXX), new DecimalType(7.XXXXXXXXX))
//my work location
val PointType work = new PointType(new DecimalType(50.XXXXXXXXX), new DecimalType(7.XXXXXXXXX))
// Function to transform location coordinates to address
val Functions$Function1<GenericItem, String> locationAddress= [ Coordinates |
val geocodeURL = "https://maps.googleapis.com/maps/api/geocode/json?key=XXXXXXXXXXXXXXXXXXXXXXXXXXX&latlng=" + 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
]
// Function called to calculate location distance
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) - %s", placeName, distance, "Home Sweet Home"))
} else {
message = "unterwegs"
}
return message
]
rule "Standortbestimmung: Cyrelian´s iPhone"
when
Item CyreliansiPhone_Coordinates changed
//Time cron "0/30 * * * * ?"
then
logInfo(filename, "Standortbestimmung: Cyrelian´s iPhone")
CyreliansiPhone_Location.postUpdate(locationDistance.apply(CyreliansiPhone_Coordinates, home, "zu Hause", 125))
CyreliansiPhone_Location_Address.postUpdate(locationAddress.apply(CyreliansiPhone_Coordinates))
end
rule "Cyrelian Presence Update"
when
Item MOBCyrelians_WLAN changed or
//Item MOBCyrelians_IFTTT changed or
Item CyreliansiPhone_Location changed or
System started
then
if (MOBCyrelians_WLAN.state == "Anwesend" || CyrelianssiPhone_Location.state.toString != "unterwegs"){
logInfo(filename, "Cyrelian ist Zuhause")
MOBCyrelian.postUpdate(ON)
}
else {
logInfo(filename, "Cyrelian ist nicht Zuhause")
MOBCyrelian.postUpdate(OFF)
}
end
Code: Alles auswählen
Frame label="iCloud Devices" {
Text item=gCyreliansiPhone label="Cyrelian´s iPhone" icon="iphone"{
Frame item=gCyreliansiPhone {
Text item=CyreliansiPhone_BatteryStatus
Text item=CyreliansiPhone_BatteryLevel
Text item=CyreliansiPhone_LocationAccuracy
Text item=CyreliansiPhone_LocationLastUpdate
Text item=CyreliansiPhone_Location
Switch item=CyreliansiPhone_FindMyPhone mappings=[ON="Find"]
Text item=CyreliansiPhone_Location_Address
Mapview item=CyreliansiPhone_Coordinates height=8
}
}
}
und im Detail:
Das ist natürlich nicht alles auf meinem Mist gewachsen. Als Vorlage dienten mir die ITEMS und Rules von "patrik_gfeller"Klick.
Die Hauptanpassungen habe ich in den Rules im Bereich der Lambda Funktionen vorgenommen.
Ich hoffe, dass hilft dem einen oder anderen von euch weiter

CYA
Cyrelian