iOS Geofency App: Analyse eines eingehenden WebHooks

Ich nutze jetzt schon seit längerer Zeit die Geofency App als Ersatz für die Homey Build-In Geofencing Funktion. U.A. weil…

  1. …man den Geofencing Radius zwischen 50 und 550 Metern anpassen kann
  2. …man mehrere Orte überwachen kann
  3. …man keine zusätzliche Homey App benötigt wie z.B. bei der OwnTracks App, da das Eintreten und Verlassen per WebHooks getriggert wird

Bis jetzt habe ich mit der Geofency App nur das normale “Kommen” und “Gehen” genutzt. Die Geofency App kann aber sogar unterscheiden, ob man zu Fuß, mit dem Rad oder per Auto den Geofencing Bereich betritt. Damit könnte man z.B. das Garagentor nur dann automatisch öffnen lassen, wenn man mit dem Fahrzeug nach Hause kommt.

Das Problem ist nur, dass der WebHook nicht nur ein Event liefert, sondern einige Informationen mehr, u.A. die Info zur Bewegungsaktivität. Der WebHook muss also inhaltlich analysiert werden.
Dank der Anleitung von @Stefan_Doring zum Thema “Nuki und WebHook” (Topic-Link) und der Homey App Webhooks habe ich es geschafft den Inhalt des WebHooks auszulesen und einen einfachen AF zu erstellen, der mir eine Timeline Notification ausgibt, ob ich zu Fuß oder per Auto nach Hause gekommen bin. Hier dazu die entsprechenden Infos:

Header

{}

Query

{"event":"eintritt"}

Body

{"latitude":"52.51608","longitude":"13.37993","device":"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX","entry":"1","radius":"100","id":"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX","address":"Unter den Linden 77\n10117 Berlin\nDeutschland","name":"Webhook-Test","category":"Monitored","date":"2024-11-17T12:07:35Z","motion":"automotive"}

(pers. Infos wurden unkenntlich gemacht bzw. ersetzt)

In der Geofency App sieht die Einstellung wie folgt aus.
– URL Einstellung: Ein
– WebHook für Eintritt *1: https://webhooks.athom.com/webhook/123a1abc1a1ab12ab123ab12?homey=0123456789a012345678901a&event=eintritt
– WebHook für Austritt *1: https://webhooks.athom.com/webhook/123a1abc1a1ab12ab123ab12?homey=0123456789a012345678901a&event=austritt
– HTTP Methode: POST als JSON
*1: Bis auf die Events wird der Rest der URL von der Webhooks App vorgegeben. Die originalen Strings wurden unkenntlich gemacht.

Da ich für diesen Anwendungsfall aber gerne auf die App Webhooks verzichten möchte, würde ich das gerne mit den Build-In Logik-Karten machen.
Also irgendetwas mit Das WebHook-Ereignis “eintritt” ist eingegangen dann Parse…, dann Was auch immer….
Ich habe auch schon etwas hin und her probiert, habe dem Webhook aber nicht entlocken können.

Vielleicht auch nicht ganz unwichtig, diese folgenden Codes mit Beispielen stellt der App Entwickler zur Verfügung:

Code-Bezeichnung: geo.php

<?php
	// This is a sample php script on how to integrate the http POST request interface for the Geofency app on iOS.
	// This is only a short demo and not a productive script.
	// Feel free to modify this script according to your wishes.
    
    // Incoming POST parameters provided by Geofency.
	// Extract parameters from http request (using “_POST” or "_REQUEST").
	// $date is a rfc3339 formatted date in the form: yyyy-MM-ddTHH:mm:ssZ
	$date=$_POST["date"];
	$isEntry=($_POST["entry"] == "1");
	$locationName=$_POST["name"];
	$locationID=$_POST["id"]; 
	$longitude=$_POST["longitude"];				   // Center longitude of the location.
	$latitude=$_POST["latitude"];				   // Center latitude of the location.
	$radius=$_POST["radius"];
	$address=$_POST["address"];
	$beaconUUID=$_POST["beaconUUID"];
	$major=$_POST["major"];
	$minor=$_POST["minor"];
	$deviceID=$_POST["device"];
	$currentLongitude=$_POST["currentLongitude"];  // Current longitude when entering or leaving the location.
	$currentLatitude=$_POST["currentLatitude"];    // Current latitude when entering or leaving the location.
	$wifiSSID=$_POST["wifiSSID"];				   // Connected Wi-Fi SSID. 
	$wifiBSSID=$_POST["wifiBSSID"];				   // Connected Wi-Fi BSSID.
	$motion=$_POST["motion"];					   // Motion activity.

    if ($isEntry)
        $out = date('Y-m-d H:i:s') . " entryDate: " . $date . ", entered at " . $locationName . "\n";
    else
        $out = date('Y-m-d H:i:s') . "  exitDate: " . $date . ", exited  at " . $locationName . "\n";

    echo $out;

    $filename = "geofency.log";
    file_put_contents($filename, $out, FILE_APPEND | LOCK_EX);


    // Example condition:
    // Send http request if it's later than 8pm (20:00).
    $hour=substr($date, 8, 2);

    if ($hour > '20' && $isEntry) {
        echo "It’s time to eat <After Eight> and switch on lights.\n";
        // Integrate your e.g. house automation system here ...
        // http_get("http://www.mypage.com/switchOnLights.html”);
    }
?>

Code Bezeichnung: geo_json.php

<?php
	// This is a sample php script on how to integrate the http POST request interface for the Geofency app on iOS.
	// This is only a short demo and not a productive script.
	// Feel free to modify this script according to your wishes.

    // Extract json encoded parameters from http POST request.
    $data = json_decode(file_get_contents('php://input'));
    
    // Incoming POST parameters provided by Geofency.
    // $date is a rfc3339 formatted date in the form: yyyy-MM-ddTHH:mm:ssZ
    $date=$data->{"date"};
    $isEntry=($data->{"entry"} == "1");
    $locationName=$data->{"name"};
    $locationID=$data->{"id"};
    $latitude=$data->{"latitude"};					// Center latitude of the location.
    $longitude=$data->{"longitude"};					// Center longitude of the location.
    $radius=$data->{"radius"};
    $address=$address->{"address"};
    $beaconUUID=$data->{"beaconUUID"};
    $major=$data->{"major"};
    $minor=$data->{"minor"};
    $deviceID=$data->{"device"};
    $currentLatitude=$data->{"currentLatitude"};    // Current latitude when entering or leaving the location.
    $currentLongitude=$data->{"currentLongitude"};  // Current longitude when entering or leaving the location.
    $wifiSSID=$data->{"wifiSSID"};				    // Connected Wi-Fi SSID. 
    $wifiBSSID=$data->{"wifiBSSID"};				// Connected Wi-Fi BSSID.
    $motion=$data->{"motion"};					    // Motion activity.

    if ($isEntry)
        $out = date('Y-m-d H:i:s') . " entryDate: " . $date . ", entered at " . $locationName . "\n";
    else
        $out = date('Y-m-d H:i:s') . "  exitDate: " . $date . ", exited  at " . $locationName . "\n";

    echo $out;

    $filename = "geofency.log";
    file_put_contents($filename, $out, FILE_APPEND | LOCK_EX);


    // Example condition:
    // Send http request if it's later than 8pm (20:00).
    $hour=substr($date, 8, 2);

    if ($hour > '20' && $isEntry) {
        echo "It’s time to eat <After Eight> and switch on lights.\n";
        // Integrate your e.g. house automation system here ...
        // http_get("http://www.mypage.com/switchOnLights.html”);
    }
?>

Code Bezeichnung: geo_get.php

<?php
	// This is a sample php script on how to integrate the http GET request interface for the Geofency app on iOS.
	// This is only a short demo and not a productive script.
	// Feel free to modify this script according to your wishes.
    
    // Incoming POST parameters provided by Geofency.
	// Extract parameters from http request (using “_POST” or "_REQUEST").
	// $date is a rfc3339 formatted date in the form: yyyy-MM-ddTHH:mm:ssZ
	$date=$_GET["date"];
	$isEntry=($_GET["entry"] == "1");
	$locationName=$_GET["name"];
	$locationID=$_GET["id"];
	$longitude=$_GET["longitude"];
	$latitude=$_GET["latitude"];
	$radius=$_GET["radius"];
	$beaconUUID=$_GET["beaconUUID"];
	$major=$_GET["major"];
	$minor=$_GET["minor"];
	$deviceID=$_GET["device"];
    $wifiSSID=$_GET["wifiSSID"];
    $wifiBSSID=$_GET["wifiBSSID"];
    $motion=$_GET["motion"];

    if ($isEntry)
        $out = date('Y-m-d H:i:s') . " entryDate: " . $date . ", entered at " . $locationName . ", deviceID: " . $deviceID . ", wifiSSID: " . $wifiSSID . ", wifiBSSID: " . $wifiBSSID . ", motion: " . $motion . "\n";
    else
        $out = date('Y-m-d H:i:s') . "  exitDate: " . $date . ", exited  at " . $locationName . ", deviceID: " . $deviceID . ", wifiSSID: " . $wifiSSID . ", wifiBSSID: " . $wifiBSSID . ", motion: " . $motion . "\n";

    echo $out;

    $filename = "geofency.log";
    file_put_contents($filename, $out, FILE_APPEND | LOCK_EX);


    // Example condition:
    // Send http request if it's later than 8pm (20:00).
    $hour=substr($date, 8, 2);

    if ($hour > '20' && $isEntry) {
        echo "It’s time to eat <After Eight> and switch on lights.\n";
        // Integrate your e.g. house automation system here ...
        // http_get("http://www.mypage.com/switchOnLights.html”);
    }
?>

Blickt da jemand durch und könnte mir helfen?

Ich habe gerade Deinen ( schon älteren) Post entdeckt. Ich suche Informationen welche Daten im Webhook von Geofency übertragen werden. Bist Du da weitergekommen ?
Mit der Homey eigenen Webhook Funktion wird bei mir mit “Tag” nichts übertragen, also nach meinem Kenntnisstand nicht auswertbar.
Mit der Webhook App kommen die von Dir im “Body” beschriebenen Daten auch an. Mich interessieren vor allem Dingen Motion Eigenschaften. Da habe ich zwei rausgefunden: stationary und walking. Gibt es irgendwo eine Liste wo die Eigenschaften aufgelistet sind? In der deutschen App sind die Aktivitäten auch deutsch, eventuell für die weiteren Eigenschaften dann noch: running, driving cycling, unknown ?
Lieber wäre mir natürlich auch die homeyeigene App, weil der Webhookbefehl ja auch ein anderer ist.

Da es mit den Build-In WebHook Flow Karten ja nicht funktioniert, hatte ich es damals nicht weiter verfolgt.

Aber neben stationary und walking kenne ich allerdings noch automotive. Wie die Begriffe für Unbekannt, Laufen, Radfahren konkret lauten, weiß ich allerdings nicht. Auch in Home Assistant habe ich keine weiteren Infos dazu gefunden, sorry.
Du könntest beim App Entwickler aber vielleicht mal direkt nachfragen (info@geofency.com).

Hier die Antwort vom Entwickler (Auszug):

The motion parameter reports the device’s detected physical activity at the moment of the event. It is always one of these five lowercase English values:

Motion value Description
stationary Device is not moving / standing still
walking User is walking
running User is running
cycling User is riding a bicycle
automotive User is traveling in a motor vehicle (car, bus, etc.)

A few additional notes:
* The values are always in English and lowercase, regardless of the device language.

* The motion field is only included when Motion Activity is enabled for that webhook. If iOS cannot determine the activity with sufficient confidence, the field is omitted entirely, so your automation should treat a missing field as a valid case.
* These correspond directly to the raw iOS Core Motion activity types, so stationary, walking, running, cycling, and automotive are the complete set of possible values.
I’ve also updated the in-app Webhook Reference (the ? help sheet on the webhook screen) so it now lists all five values explicitly.

There isn’t a separate online documentation page—the in-app reference is the canonical source. It also documents every other webhook field (id, name, latitude, entry, date, etc.), the supported HTTP methods, and includes sample payloads.

Also die englischen Namen klein geschrieben, wie vermutet.