How to integrate GeoFency or Locative app?

I’m trying to use the GeoFency/Locative apps for tracking presence and triggering events when I leave work. Both apps can call a HTTP URL when a geofence (GPS location) is entered/left. Unfortunately both apps insist on posting the whole location data instead of just calling my URL (https://my.openhab.org/CMD?Presence_Fence1=ON). When calling the URL from the command line (with curl and HTP basic auth) it works.
GeoFency does not do anything (It just displays “Forbidden”, probably because it’s doing a POST request why my.openhab expects GET), Locative does a GET request but puts additional parameters in the URL (id, longitude, latitude and device) which is interpreted as additional items, which are then not found.

I could write a simple PHP proxy script that receives the data from the app and then makes the request to my.openhab, but then this script has to be deployed and updated and every year get a new SSL certificate. I’d rather have some other option to do this. Any ideas?

The following alternatives are rather undesirable:

  • use OwnTracks/MQQitude. I don’t want detailed tracking and an additional cloud/server component.
  • Create “id”, “device”, “longitude”, “latitude” items. I don’t want to pollute my item file.

Instead of using the CMD servlet with accepts GET, could you instead use the REST API, which uses POST to send commands to items? That might solve the GeoFency issue, if you can control the POST body.

In order to send a command to an item, you would use the item uri (http://localhost:8080/rest/items/Temperature_FF_Office) and send an HTTP POST with the according command in the request body as text/plain.

As for Locative, could you tell the maker to let you remove those unwanted parameters, and in the meanwhile have dummy items or suppress logging n logback.xml?

Unfortunately I have no control over the POST body of both apps. Both send location data and not the JSON that I want.

Hi,
I tried something similar.
I wrote a two php scripts: one for entering (IN.php) and one for leaving (OUT.php) and used the webhook to get them executed on my home server. The IN sript wrote “Anwesend” and the OUT scrpit “Abwesend” in a thrird file (Presence.php).
Via exec binding I evaluated this file every minute to detect the location and used a text item to visualize it in the sitemap.
It work good.
However: For this to work, I had to drill a hole in my router by opening up a port. I have openhab running on a Netgear NAS and could block certain folders as well as create password use (Geofency allows this). Nevertheless, I believed so far the risk to high, that someone work highjack my server.
Please advise how you intend to use the SSL certificate with Geofency?
Cheers
Björn

Ok, the programmer in me took over and wrote a small PHP application: https://github.com/gbirke/geofency-proxy

I host the script on one of my domains and use the REST API on my.openhab.org (with its https connection) to relay to the local OpenHAB installation.

Hi Gabriel,

After long trial and error I went now a different way, maybe as an alternative to your solution.
As mentioned before I did not want to drill a hole in my router (fritzbox).

On the other end I wanted to use the webhook of Geofency as “post - method”.
Thus I was looking for a way to use VPN automatically to connect to my OpenHab server.

What I found was this:
http://www.meintechblog.de/2015/02/vpn-on-demand-zwischen-iphone-und-fritzbox-einrichten/

This link provides a very extensive a solid description on how to accomplish a VPN-on-demand connection to the server; client is an iphone.

Using this method, the Geofency app (which is really a fantastic presence locator and much more) will automatically set up a VPN connection when I leave a location and execute a php script on my server changing my status from “Anwesend” to “Abwesend” or “Arbeit” or what ever locations you have defined.

Note: I cannot determine any increase in power consumption or of battery life of my iphone.

Cheers
Björn

It sad that there is not decent solution.
All the solutions above are complicated workarounds.

There should be a simple way to forward the location of my phone to openhab without rocket science and potential security wholes

I wrote one php script and used the webhook to get them executed on my web server. the script only wrote on or off in a log file on my webserver. every 1 minute i check with openhab the LOG file. so nothing is open on my openhab server.

rule "Geofency"
when
Time cron "0 0/1 * 1/1 * ? *"
then
val result_home = sendHttpGetRequest(“http://www.server.de/geofency/geofency_home.log”)
Home_String.postUpdate(result_home)
end

Yes, that a solution.
I honestly I do not want to run an own internet exposed webserver.
This should be a function of myopenhab.

For anyone still looking at this who has set up nginx as a secure reverse web proxy to expose a webserver but who doesn’t want to bother with the overhead of php here’s my solution:

nginx proxy_pass a dedicated url to a specifc port
a socat based service running on that port that forwards all queries to a bash script
a bash script that curl’s to openhabs REST api

All works and uses the same security I have set up for my core openhab urls.

Let me know if you need more information.

You could post a tutorial in the Solutions&Tutorials topic with a set-by step of the set-up and examples of code.
There are excellent examples on the forum already MQTT 101 being one of them
I followed the same structure for my tutorial on MQTT and SSL

The iPhone locative app allows you to specify the HTTP Push string for arrival and departure. I don’t have any experience with the android app.

Hello @sohmc,
my daugther lately switched from Android to iOS and I have the mess that my easy PHP script that I could call via a simple weblink from Android does not work anymore as the apps on iOS (Locative and Geofency) only work with wehooks.
I am absolutely no programmer and hence I would just simply like to further use my simple scripts that get triggered by the incoming webhook POST message.
Hence I kindly ask you to share your script which seems to do what I would need. Maybe I completely adopt your smart approach with the decoupled log file :slight_smile:
At a minimum I hope to learn from your PHP script how to trigger my existing PHP scripts to set the item state of the presence detection (even though it is less secure …)

Thank you for sharing your knowledge with a newbie :+1:

Cheers
Justus