Re: openHAB 2.2 iCloud Präsenzerkennung
Verfasst: 1. Dez 2018 12:30
Die 0.0 wird über new PointType gesetzt. Hier die Funktion:
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 = "XXX"
//my home location
val PointType home = new PointType(new DecimalType(XX.641807), new DecimalType(7.180585))
//my work location
val PointType work = new PointType(new DecimalType(XX.705791), new DecimalType(7.144194))
// Function to transform location coordinates to address
val Functions$Function1<GenericItem, String> locationAddress= [ Coordinates |
//Hack to use googles geocode funtion with openhabs PointType
val geocodeURL = "https://maps.googleapis.com/maps/api/geocode/json?key=XXX&latlng=" + Coordinates.state.toString.replace(",0.0","") + "&language=german&sensor=true"
//logInfo("iCloud",Coordinates.state.toString)
//logInfo("icloud", geocodeURL)
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, "XXX"))
message = "home"
} else {
message = "unterwegs"
}
return message
]