Skip to main content

Geofency smart home integration, free and open source

Geofency integration for Gladys Assistant

Presence from the zones of the Geofency and Locative iOS apps: arrivals, departures, zones.

Presence in Gladys from the zones of the Geofency iOS app (and of Locative, which sends the same kind of webhook): when your iPhone enters or leaves a zone, the app calls Gladys, which knows at once who is at home, in which zone, and since when. No cloud service in between: the phone talks to your Gladys.

Developed without the hardware: feedback welcome. The webhooks of Geofency and Locative were replayed in their exact formats (JSON and form), not sent by a real iPhone. Tell us how it goes on GitHub.

What you need​

  • Gladys Assistant 5.2.0 or later.
  • An iPhone with Geofency (paid app) or Locative, and your zones set up in the app.
  • From outside your home: Gladys Plus (its webhook URL), or a VPN to your home network.

Getting started​

1. Install the integration​

In Gladys: Integrations → Install from GitHub, address https://github.com/guim31/gladys-geofency.

2. Choose a token​

In the configuration of the integration, type a secret token of at least 8 characters (letters and digits). The local address refuses every request without it.

3. Set up the app​

The configuration screen shows the address to type, for example http://192.168.1.10:49200/my-secret-token.

  • Geofency: open a zone → Webhook, enter the address for Entry and Exit, method POST, format JSON (form also works). Repeat for each zone, or use the same settings for all.
  • Locative: Settings → global HTTP settings, the address for both triggers, method POST. Locative's Send test request button gets an OK: test received answer.

Add ?person=Alice at the end of the address to name the phone (…/my-secret-token?person=Alice). The token can also be sent as the password of the HTTP authentication of the app.

Away from home the phone is no longer on your Wi-Fi, so it cannot reach the local address. Two ways:

  • Gladys Plus: use the webhook URL shown at the bottom of the configuration screen ("Geofency and Locative from anywhere"), without token: the URL itself is the secret. Recommended.
  • VPN (WireGuard, Tailscale…) on the phone, with the local address.

Do not open the port of the integration on your router: anybody could then try tokens.

4. Add the phone​

Make the phone enter or leave a zone (or send a test event from the app): the phone appears in Discovery. Add it, and give it the name you want.

Configuration​

SettingMeaning
Secret tokenRequired by the local address (path, token parameter or HTTP password).
Home zonesNames of the zones meaning "at home", comma separated; case and accents ignored.
Gladys houseThe house used for the distance; empty: the first one with a location.
Share coordinatesOff by default: only the distance leaves the integration. On: map links in widget and scene.
Language of names and textsLanguage of the feature names and of the texts produced (French by default).

The action Forget the phones not added removes from Discovery the phones you never added.

The devices​

One device per phone (the app's device id). Its features:

  • At home: 1 while the phone is in a home zone, 0 otherwise.
  • Presence: a "seen at home" signal every 5 minutes while at home, for Gladys' "Check user presence" scene action.
  • Current zone: the last zone entered and not left yet, or "No zone".
  • Last zone event: for example "Entered Office, 30/11 12:40".
  • Distance from home (last zone): in km, from the position sent with the last event (the phone's own position when Geofency sends it, else the centre of the zone). Only with a Gladys house that has a location.

Zones can overlap: the phone stays at home as long as one of its zones is a home zone. iBeacons of Geofency count as zones. When an app retries a webhook, the repeated event is ignored. An entry into a zone the phone is already in means its exit was lost by iOS: it counts as a new entry (and a new arrival for a home zone). The first event of a new phone in a home zone is an arrival too.

Dashboard​

The Phones and zones widget lists each phone added to Gladys with its zone as a badge (green at home, blue in another zone, grey in none) and since when. Tapping a phone shows its last event, its distance, and a map link if you share coordinates.

Scenes​

Triggers​

  • Phone arrives home: the phone enters a home zone after being away.
  • Phone leaves home: the phone leaves its last home zone.
  • Phone enters a zone: any zone, or the one you type (exact name as in the app).
  • Phone leaves a zone: same, on exit.

Each one can be limited to a phone and passes its name and the time to the actions (and the zone for the last two).

Action​

Get where a phone is returns a sentence such as "Alice is in Office since 14:05", whether the phone is at home, the current zone, since when, the time of the last event, the distance and the map link (if shared).

Scene ideas​

  • Arrival of the last person: turn the heating to comfort and the lights on.
  • Everybody left: "Check user presence" with the Presence feature, then arm the alarm.
  • Leaving the office: send "On my way" with the sentence of the action.

Troubleshooting​

  • Nothing in Discovery: check the address in the app and the token; the logs of the integration count refused requests. Opening the address in a browser answers "Not a Geofency or Locative zone event": the receiver is reachable.
  • 401 Unauthorized: wrong token, or token shorter than 8 characters.
  • Works at home, not outside: normal without Gladys Plus or a VPN, see step 3.
  • Not at home while in the zone: the name of the zone must be in "Home zones".

Limits​

  • The app decides when it sends: iOS can delay a zone event by a few minutes.
  • No GPS track, only zone entries and exits. The coordinates stay in memory, never written to disk.
  • 20 phones at most.
  • Credits: formats checked against the Home Assistant geofency and locative integrations (Apache 2.0). Not affiliated with Geofency or Locative.

Configuration settings​

These are the settings Geofency asks for in its configuration screen in Gladys.

SettingTypeRequiredDescription
Connect Geofency or LocativesectionNoIn Geofency: Webhook settings of each zone, method POST, format JSON or form. In Locative: Settings → global HTTP settings, POST. At home (Wi-Fi of the house), enter http://{{gladys_host}}:{{port:geofency_http}}/ followed by the token below. Away from home the phone is not on that network: use the Gladys Plus webhook URL shown at the bottom of this screen (no token), or a VPN. Add ?person=Alice to name the phone.
Secret token (at least 8 characters)secretYes
HomesectionNoA phone is at home while it is in a zone whose name is in the list below (as typed in the app, case and accents ignored). The distance from home needs a Gladys house with a location.
Home zones (comma separated)stringNo
Gladys house (optional)stringNo
Share coordinates with Gladys (map links)booleanNoOff: only the distance from home leaves the integration. On: the widget and the scene action get an OpenStreetMap link to the position of the last event.
Language of the names and textsselectNo

How to install Geofency in Gladys​

  1. In Gladys, open Integrations: Geofency appears in the catalog, next to the native integrations, with a community badge.
  2. Click Install. Gladys pulls the Docker image (ghcr.io/guim31/gladys-geofency:1.0.0), starts it in a sandbox isolated from the core, and generates the integration's interface (devices, discovery and configuration).
  3. Open the Configuration screen of the integration, fill in the settings, and save.
  4. You can also install it directly from its repository URL: https://github.com/guim31/gladys-geofency.

Geofency requires Gladys >=5.2.0. The catalog inside Gladys refreshes every hour, so a new version becomes available at most one hour after its release.

Not running Gladys yet? It is free and open source: follow the installation guide to get started.

About external integrations​

Geofency is an external integration: a community integration packaged as a Docker container and published on GitHub, that Gladys installs in one click and runs in a sandbox isolated from its core. It is published and maintained by guim31, not by the Gladys core team.

Subscribe to the Gladys Assistant newsletter

A few emails per month about new releases and project news. Sent by Pierre-Gilles Leymarie, founder of the project. Unsubscribe anytime 🙂