OH3 icloud Rules

Einrichtung der openHAB Umgebung und allgemeine Konfigurationsthemen.

Moderatoren: seppy, udo1toni

Antworten
Hille
Beiträge: 49
Registriert: 2. Jan 2018 13:59
Answers: 0

OH3 icloud Rules

Beitrag von Hille »

Ich nutze folgende Rule (aus dem Forum), um mir meinen aktuellen Standort auszugeben

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 = "xyz"

//my home location
val PointType home = new PointType(new DecimalType(22.12345446), new DecimalType(8.123456))


// 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=xyz&latlng=" + Coordinates.state.toString.replace(",0.0","") + "&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)", placeName, distance))
      } else {
        message = "unterwegs"
        StatusReached = false
        }
     return message
]

rule "Standortbestimmung: Hille iPhone"
when
    Item iPhone_Hille_Coordinates changed
then
    logInfo(filename, "Standortbestimmung: Hille iPhone")
    iPhone_Hille_Location.postUpdate(locationDistance.apply(iPhone_Hille_Coordinates, home, "zu Hause", 125))
    iPhone_Hille_Location_Address.postUpdate(locationAddress.apply(iPhone_Hille_Coordinates))

        if (now.getHour() >10 && now.getHour() <22) {
        val telegramAction = getActions("telegram","telegram:telegramBot:12345678")
        telegramAction.sendTelegram("zu Hause")
        }

end
Aktuell wird die Telegram Nachricht, im Zeitraum von 10-22Uhr, alle 5min versendet. Mein Ziel wäre folgendes:
Die Nachricht soll einmalig im Zeitraum von 10-22 Uhr versendet werden, wenn ich in den Bereich "zu Hause" befinde. Verlasse ich den Bereich und komme erneut nach Hause, soll wieder eine einmalige Nachricht versendet werden. Wie muss ich die Rule ändern?

Antworten