Parsing of an WebHook

I have been using the iPhone Geofency app for some time now as a replacement for the Homey Build-In Geofencing feature. For example because…

  • it’s possible to adjust the geofencing radius between 50 and 550 meters
  • it’s possible to monitor multiple locations
  • there is no need for additional Homey apps like the OwnTracks app, because entering and leaving is triggered via WebHooks

…and a lot more features.

Until now, I used only the normal “coming” and “going” features. But the Geofency app can also detect if you enter the geofencing area on foot, by bike or by car. This could be used, for example, to automatically open the garage door only when you come home by car.
The problem now is that the WebHook doesn’t send just an Event and a Tag, but a lot more information. These are the WebHook parameters:

{"id": "{Location identifier)",
"name": "{Name of the location}",
"entry": "{»1« Entry, »O« Exit}",
"date": "{Time stamp (RFC 3339)}",
"latitude": "{Latitude}",
"longitude": "{Longitude}",
"address": "{Address string of the location)",
"radius": "{Monitoring radius)",
"category": "{Frequent, Monitored, iBeacon}"
"device": "{Device identifier}",
"beaconUUID": "{iBeacon UUID}",
"major": "{iBeacon Major No.}",
"minor": "{iBeacon Minor No.}",
"currentLatitude": "{Proximity Latitude}",
"currentLongitude": "{Proximity Longitude}",
"wifiSSID": "{WLAN SSID}",
"wifiBSSID": "{WLAN BSSID}",
"motion": "{Motion type}"}

In addition, the app developer of the iOS Geofency App also provides the following sample codes for download:

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”);
    }
?>

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”);
    }
?>

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”);
    }
?>

However, I have absolutely no idea what to do with it… :thinking:


After I had already tried a few things with the Build-In Webhook flow cards with no success, I found a tutorial where the Homey App Webhooks was used. So I installed the app and did again some tests.
After replacing the webhooks in the iOS Geofency app with the Webhook URL from the Homey Webhooks app and creating just a simple flow with a timeline notification card, I received the following infos:

{"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"}

(Personal information has been made unreadable or has been replaced)

So I created a simple AF that gives me, just for testing purposes, a timeline notification as to whether I came home on foot or by car, and it works!

But I would like to realize it without the Webhooks app and just use internal Flow cards. Is that even possible? If so, can someone show me how?

No, the Logic webhooks don’t pass the request body in any way, and that’s where all the useful information is :frowning:

Also not possible with “The webhook event XYZ has been received” → “Parse (Text) as JSON and…”? Or something with a Homey Script?

I don’t see any way that the body data can be accessed.

Too bad, but thanks anyway.