I will show you how to make a double presence detection, that uses both GPS and wifi connection to detect if you are home or not. This is super stable, reliable, and without false positives.
Many are using the default presence detection in Home Assistant, that rely on GPS only. This works most of the time, but it’s very annoying to sit in your home and watch everything turn off, because the GPS in your phone misplaced you by mistake. So let’s see how we combine the GPS signal with the wifi connection to get a very reliable presence detection. If you live multiple people in the house, you can setup this on all your phones, and combine all the sensors in the group.
Requirements:
– You have installed the Home Assistant companion app on your phone.
– You have network connection to your Home Assistant when you are out of the house.
Let’s start by setting up the normal GPS presence check. If you already have this running, you can skip this step.
Start by enabling the sensor in your Home Assistant companion app on your phone.
Go to “Manage sensors” – “Background location” and enable it.
In Home Assistant, go to “Settings” – Areas & zones” – “Zones” tab – Move the home location to your home location on the map.
Go to “Entities” in Home Assistant and find device_tracker.your_phone, and check that it works.
Next, Let’s setup wifi connection detection.
Start by enabling the sensor in your Home Assistant companion app on your phone.
Go to “Manage sensors” – “Wifi connection and enable it.
Go to “Entities” in Home Assistant and find sensor.your_phone_wifi_connection, and check that it works.
Now we have 2 sensors in Home Assistant that detects our home presence. The next step is to combine them into something useful. This can be done in a lot of ways, but after trying several ways, I found my favorite to be via binary sensors, because its easy to group and use.
Add this to your configuration.yaml. and restart Home Assistant.
Remember to change all the “your_” to match your setup.
This will add 2 new binary sensors in Home Assistant. Find them under entities and check they are working as intended.
They will be named:
binary_sensor.your_gps_home
binary_sensor.your_mobile_home
When you are home they should be “On”, when your are away, they should be “Off”.
You can test the GPS sensor by moving your home location in Home Assistant.
You can test the wifi connection sensor by disabling wifi on your phone.
binary_sensor:
- platform: template
sensors:
your_mobile_home:
value_template: >-
{% if states('sensor.your_phone_wifi_connection') == "your_wifi_name" %}
on
{% else %}
off
{% endif %}
- platform: template
sensors:
your_gps_home:
value_template: >-
{% if states('device_tracker.your_phone') == "home" %}
on
{% else %}
off
{% endif %}
If you have multiple wifi networks in your home, you can use this instead:
binary_sensor:
- platform: template
sensors:
your_mobile_home:
value_template: >-
{% if (states('sensor.your_phone_wifi_connection') == "your_wifi_name1") or ((states('sensor.your_phone_wifi_connection') == "your_wifi_name2")) %}
on
{% else %}
off
{% endif %}
- platform: template
sensors:
your_gps_home:
value_template: >-
{% if states('device_tracker.your_phone') == "home" %}
on
{% else %}
off
{% endif %}
When both sensors work, we can combine them in a group, so it’s easy to use in automations etc.
In Home Assistant, go to “Devices & services” – “Helpers” tab – and create helper. Choose Group – Binary sensor group, give it a name like Residents_Precence, and add the 2 binary sensors as members, make sure to leave “All entities” off and submit.
The group will have status “On” if any of the sensors have status “On”. So you have to be outside the GPS area and outside wifi range for the group to be “Off”.
You can see an example here, where I was outside wifi range for some time, but because the GPS was still in the home area, the group stayed “On” all the time.
Now we can go to automations, and use the group either as a trigger, or as a condition.
I have been using this way of presence detection for quite some time now, and it is rock solid. Of Couse there can be a some minutes delay from you leave your home, to your get a notification, but this delay is often more related to delay in notifications on your phone, than a problem with Home Assistant.
If you are in doubt where the delay is coming from, you can check Home Assistant and see when it detected you as away.
This was made and tested on Home Assistant version 2024.1.2.