Device Tracker
The easiest method is to have the Presence detection module log into your router to check the status of devices. Using this method you can determine if an indivdual is presnet at a particular location by watching how their phone is interacting with the local wifi router. Below you can see the code to enable presense detection on a verizon fios quantam gateway router. The issue here, is the detection speed. First, the router must be polled for presense detection which will result in some lag between a change and the actual event. Second, some hysteresis is required in the algorithm in order to prevent false triggers from just a temporary loss of device wifi signal.
device_tracker:
- platform: quantum_gateway
host: 192.168.1.1
password: your_router_password
We use router based presense detection for "exit area" automation and for simple "who is home" indicators on the home assistant dashboard. It does not, however, serve us well for automating arrival events such as "turn on the heat as I arrive close to the house
IFTTT Based Geo-Fencing
We find the home assistant IFTTT integration much more useful for more advanced geo-fence events. IFTTT can notify home assistant on entry or exit from an area defined by drawing a circle on a map. This is a much more precise method of triggering on location and the app is very easy to integrate with home assistant.
The following is required:
- 1. Home assistant must be reachable from the internet with a signed certificate (follow letsencrypt and duckdns installation guides
- 2. In home assistant, click configurations, integrations, IFTTT webhook. This will install the IFTTT integration and give you the URL you need to setup in IFTTT to notify home assistant when you enter or leave an area.
- 3. Create the proper applet in IFTTT. Create a webhook applet and enter the URL providede by step 2. Set the method to POST and content to application/json. You can then pass additional parameters to home assistant in the body box.
You can test sending the https post request created above in step 2 with this site: apirequest.io or using curl from a linux command line as follows:
$ curl -s -X POST https://hostname.duckdns.org:443/api/webhook/stringcreatedinstep2 -H "Content-Type: application/json" -d '{ "data_key" : "data_value" }'
Your home assistant automation to turn a light on before you get home would then look something like this:
- id: 'garage_light_on'
alias: turn_on_light_when_enter_area
trigger:
- event_data:
action: entered_near_home
event_type: ifttt_webhook_received
platform: event
condition: []
action:
- data:
entity_id: light.garage
service: light.turn_on