Skip to content

ASIsnc/Federico

Repository files navigation

FHEM Presence tracker with Geofency webhook

This code enables FHEM PRESENCE state through Geofencing with the Geofency iOS app.

It consists of:

  • A webhook (server script) that receives JSON POST requests from the Geofency app and writes the enter/exit events to a file.
  • A command line utility that is called from FHEM to generate presence state (1 or 0) from the data.

This script creates a more stable presence than the native "GEOFANCY" presence feature of FHEM: Since the iBeacon has a limited range, the app creates many "Enter" and "Exit" events. These events are "smoothed over" by this app by using a threshold for the absence.

System requirements

Installation

  • After extracting the sources in your web directory, run
    composer install.
  • Change the settings in settings.php if needed.
  • Make sure that the data directory for the data file is writable.
  • Browse to your web directory. You should see the message "Not allowed." If you see the message "Filesystem error" check if the data directory for the data file is writable.
  • (optional) Create a .htaccess file to protect your web directory (see "Security considerations").
  • Install Geofency. Create a new location (either with a geofence or an iBeacon) and use its settings to set up a webhook for it, with the index.php as the endpoint.
  • FHEM: Add the following line to your FHEM cfg:
    define Geofency PRESENCE shellscript "php /path/to/your/webroot/checkpresence.php"

Security considerations

Since the webhook is open for everyone, you should protect it with a .htaccess file and enter the data in Geofency.

Ideas for future expansion

  • Validate JSON
  • Verify phone id(s) and iBeacon UUID
  • Differentiate between several beacon IDs for a more general use case of the webhook
  • Store all events in database (for statistics/debugging)