Home » Blog » Mastering Geofencing in Home Assistant with Proximity and Presence Detection in 2024: An Ultimate Guide

Mastering Geofencing in Home Assistant with Proximity and Presence Detection in 2024: An Ultimate Guide

Hi! Welcome to my ultimate guide on mastering Geofencing in Home Assistant with Proximity and Presence Detection! Whether you’re a beginner or an advanced user, this video will show you how to harness the power of geolocation for automating your smart home. Let’s get started!


โญโญโญ NOTE: โญโญโญ

This article accompanies a YouTube video. I wrote it for people who would rather read than watch a video. To keep doing this, I want to ask you to check out the video, leave a comment under the video, give the video a thumbs up, and subscribe to my YouTube channel. This means that the video is offered more often to new visitors so that they also stay informed of the latest Home Assistant tutorials.

Thank you for your support!

Ed

Click here to watch the video

Introduction

Firstly, I want to mention that there are various ways to detect whether someone is at home or not. Determining if someone is at home is relatively simple by checking if there is someone present in a specific zone or not. However, this tutorial is about something else โ€“ specifically, detecting if someone is approaching or leaving a radius around your home zone. But, next to that, I will also demonstrate how you can determine if everyone has left the house.

You may be familiar with heating devices from certain suppliers that adjust when someone enters or exits a designated radius around the house. We’re going to replicate this functionality in Home Assistant. But before we proceed, let’s explore some scenarios. Imagine your house situated in a city, perhaps the center of Amsterdam. You’ll delineate an area around your house, and the aim is for your home to adapt based on people entering or leaving that defined space. So, your home is already warmed up a little before you actually get there. Let’s consider the first scenario: when nobody is within the area, the heating is set to a low temperature. As soon as one person enters, you’d like to raise the temperature, and if another family member enters, the heating should remain high for a cozy atmosphere. Even when one person leaves the area, you might want the heating to stay high until the last person exits, at which point it should revert to a lower temperature. Now, let’s transition to Home Assistant to see how you can implement this.

Enable remote access for Home Assistant

For the proximity feature to operate, enabling remote access to your Home Assistant server is essential. Numerous methods can accomplish this, with the simplest being to utilize Home Assistant Cloud by Nabu Casa. This not only facilitates remote access but also contributes to supporting developers, fostering ongoing advancements in Home Assistant.
Ensure that you have the Home Assistant companion app installed on your phone as a crucial initial step. This app precisely determines your location on the planet, a necessity for establishing whether you are within the designated area or outside it. Chances are you already have it installed, given its use in managing your entire Home Assistant system. In addition to installing the Home Assistant companion app, verify that location services are activated on your phone specifically for the Home Assistant app. This is essential as the app relies on location data to accurately determine your position on the planet. The process may vary between iPhone and Android devices, but you can typically find it in settings, under privacy or location services. Ensure this setup is operational for seamless functionality.

Now you’ve set up your phone correctly; we are going to Home Assistant to set up the rest of the things.

Assigning tracking devices to people

Let’s first assign tracking devices to the people in your Home Assistant setup.

  • Go to settings.
  • Select people.
  • Select the person that you want to track.
  • Scroll down to the devices section.
  • Here you can select the phone of this specific person.
  • Click the dropdown to select a tracking device.
  • Make sure you select a device with the person icon in front of it. This is your phone. Our focus will be on the device tracker on your phone since it is the source of the GPS data necessary to determine whether you are entering or leaving a radius around your house. You may encounter additional icons, which represent different devices, such as your router, for instance. However, these devices won’t be practical for tracking GPS data.
  • Ensure that you choose the appropriate tracking device for each person in your household and have the Home Assistant companion app installed on their phones.

I have now set up the tracking devices for my son and myself. Now, based on both phones, I can see if someone is within a radius of my house and whether they are approaching it. To detect this, I need the Proximity integration of Home Assistant, so let’s install that now.

Installing the proximity Integration

  • Go to Settings > Devices and Services.
  • Click Add Integration.
  • Search Proximity.
  • Click Proximity.
  • First, select the zone you want to track. In my case it’s Home.
  • Then select the persons or devices to track. You may be curious about why I associated the devices with the person entities earlier, whereas you can also choose the individual devices here. Well, this is a matter of preference. In some cases, one person may have multiple tracking devices. For instance, if they have several phones. In such situations, I prefer to store them under that individual’s name. This way, when setting up automations later on, I only need to check on that person and not on each individual tracking device.
  • You can also add zones to ignore here. If a tracked entity is in an ignored zone, it will not be considered for the nearest sensors, but its dedicated sensor will still update. I am not currently utilizing ignored zones, but perhaps they could be beneficial for your use.
  • Next to this, you can enter a tolerance distance here. The tolerance is used to calculate the direction of travel in meters (m) to filter out small GPS coordinate changes. It’s only considered for the calculation of the direction, so if your movement distance (the distance between two gps measurements) is lower than the tolerance, it will be ignored. I will set it to 10 for this example.
  • Click Submit.

Testing the Proximity Integration

When you open the proximity integration, you can view the distance to the zone and the direction of travel for each person or tracking device. If the person’s phone is not using the Companion App or is turned off, these values will be marked as Unknown.

Next to the values for each person or device, there are also values for the nearest device, the nearest direction of travel, and the nearest distance.

The unit of measurement of these sensors can be changed when you click on the entity and then click on the cog wheel. Here you can change the unit of measurement. In my case, the default unit of measurement is in meters, but I can change it to kilometers if I want. For now, I will leave it to meters, so I have to check the distance in meters in my automation later on.

Great, the proximity sensors are working. Now, we are going to set up the automation to switch the heating.

I need your help!

You will be doing me a huge favor if you subscribe to my channel if you haven’t already. And, you will help me a lot if you also give this video a thumbs up and leave a comment. This way, YouTube will present this video to new people, making the channel grow! In the video description, you will also find information about how you can sponsor me so that I can continue to make these tutorials for you.

Thank you!

Creating the automation for our use case

Creating the first trigger
  • Go to Settings.
  • Go to Automations and Scenes.
  • Click Create Automation.
  • Click Create New Automation.
  • Click Add Trigger.
  • Select Entity.
  • Select Numeric State.
  • Search for nearest distance and select the entity that holds the nearest distance. In my case it’s sensor.home_nearest_distance
  • I plan to initiate the heating once I come within a 5-kilometer radius of my house. Therefore, if the travel distance falls below 5000 meters, I intend to take appropriate action.
  • Enter 5000 in the Below field.
  • To work with this trigger in the Then Do section of our automation, we will assign a Trigger-ID to this trigger.
  • Click the three dots in this trigger section and click Edit ID.
  • Give this Trigger ID a name. In this case, it will be “Approaching”. I will show you in a minute how we can also verify the nearest direction of travel to ensure we are approaching the house.
CREATING THE SECOND TRIGGER

Now I will add another trigger that checks if the first person enters the house. I need this trigger in case someone leaves the house, but stays within the 5-kilometer radius. For example, when you’re visiting a friend who lives just around the corner. In one of the next actions, the heating will be lowered as soon as you leave the house. So, in case you left the house, but didn’t leave the 5-kilometer zone, we have to make sure the heating will be turned on again as soon as you enter the house. In this scenario, we won’t be utilizing the proximity integration; instead, we’ll be using the standard Zone functionality of Home Assistant.

  • Click Add Trigger.
  • Select Entity.
  • Select Numeric State.
  • In the entity field, search for your Home Zone.
  • In the Above field enter 0. So, if the state of the Home Zone is above 0, someone is home.
  • Assign a Trigger ID by clicking the three dots in this trigger area and selecting Edit ID.
  • Assign the Trigger ID “Approaching” to this trigger.

Now I will create two additional triggers in case someone leaves home or exits the 5-kilometer radius. The first one will check if everybody left the house and the second one will check if the nearest person leaves the 5-kilometer radius around my house. In both cases, we will lower the heat. You might be curious as to why I want to monitor if someone exits the 5-kilometer radius around my house, considering I’ve already adjusted the heating when the last person left. Let’s say I’m traveling from point A to B, and my house is situated between these two locations. In such a scenario, I may enter the 5-kilometer radius without actually visiting my house and subsequently leave the radius without stopping by. In such instances, I want to deactivate the heating once again upon leaving the 5-kilometer radius. So, let’s create the third trigger.

Creating the Third trigger
  • Click Add Trigger.
  • Select Entity.
  • Select State.
  • In the entity field, search for your Home Zone.
  • In the To field enter 0. So, if the state of the Home Zone is 0, nobody is at home.
  • Assign a Trigger ID by clicking the three dots in this trigger area and selecting Edit ID.
  • Assign the Trigger ID “Leaving” to this trigger.

Now add the fourth trigger.

Creating the FOURTH trigger
  • Click Add Trigger.
  • Select entity.
  • Select Numeric State.
  • Search for nearest distance and select the entity that holds the nearest distance. In my case, it’s sensor.home_nearest_distance.
  • I plan to turn down the heating once I exceed a 5-kilometer radius of my house. So, if the travel distance surpasses 5000 meters, I plan to take the necessary action.
  • Enter 5000 in the Above field.
  • Assign a Trigger ID by clicking the three dots in this trigger area and selecting Edit ID.
  • Assign the Trigger ID “Leaving” to this trigger.

So, we now have two triggers, each with the trigger ID ‘Approaching,’ and two triggers, each with the trigger ID ‘Leaving.’.

Creating the actions

Now we are going to create the actions that should be taken when the triggers are triggered. Let’s begin by creating the action that should take place as soon as someone enters the 5-kilometer radius or the house. It is not necessarily required, but for the sake of completeness, I will perform an additional check here to confirm whether this person is actually approaching the house.

Creating the first Action THAT turns on the heating

To determine which of the four triggers has become active, we can use a Choose building block. In our case, we can even opt for an If-Then building block since we have only defined two Trigger IDs. I choose to use a Choose building block now.

  • Go to the Then Do section.
  • Click Add Building Block.
  • Click Choose.
  • Expand Option 1.
  • In Conditions, click Add Building Block.
  • Select And.
  • Click Add Condition.
  • Click Other Conditions.
  • Click Triggered By.
  • Select Approaching.
  • Click Add Building Block.
  • Select Or.
  • We want to check if the nearest direction of travel is “Towards” in case we are entering the 5-kilometer zone. Or we want to check if the nearest direction of travel is “Arrived” in case we’ve arrived home.
  • Click Add Condition.
  • Click Entity.
  • Click State.
  • In the entity field, search for Nearest direction of travel.
  • In the state field, select Towards.
  • Click Add Condition again.
  • Click Entity.
  • Click State.
  • In the entity field, search for Nearest direction of travel.
  • In the state field, select Arrived.

We now created an And and Or condition that checks if someone entered the 5-kilometer radius, or entered his house, and that he is moving towards the house or Arrived home. As I said before, the last check is not really necessary, because he will always move toward the house when he enters the 5-kilometer zone or enters his house. But anyway, now you know how to use the And and Or condition as well.

Now, go to the actions section.

  • Click Add Action.
  • Select Climate.
  • Now you can select various options for your climate entity. I will choose Set target Temperature, but you can choose any action that you want to perform. I want the temperature of my living room set to 18 degrees Celsius as soon as the first person enters the 5-kilometer radius or arrives home.
  • Click Choose Entity and select your climate entity. In my case, that is the living room.
  • Enable the temperature checkbox and enter 18.

The first action is now ready. The temperature will be set to 18 degrees as soon as the first person enters my house or the 5-kilometer radius around my house. Now let’s configure the action that lowers the heating.

Creating the second action that lowers the heating
  • Click Add Option.
  • Click Add Condition.
  • Click Other Conditions.
  • Click Triggered By.
  • Select Leaving.
  • Click Add Action.
  • Select Climate.
  • Choose Set target Temperature. I want the temperature of my living room set to 15 degrees Celsius as soon as the last person leaves home.
  • Click Choose Entity and select your climate entity. In my case, that is the living room.
  • Enable the temperature checkbox and enter 15.

The second action is now ready. The temperature will be set to 15 degrees as soon as the last person leaves the house or leaves the 5-kilometer radius around my house.

Click Save and give your Automation a meaningful name.

Your automation is now set up, and your house will be heated automatically when someone approaches your house, with the heating lowered as soon as everybody leaves your house.

I have created a blueprint for this automation in case you prefer not to manually type the code from the screen. Using the blueprint will save you a lot of time and frustration, and you’ll also receive lifetime updates for this blueprint. You can download it for a small fee through the link provided in the video description. This not only helps me but also ensures that I can continue creating these tutorials.

Thank you for watching, and if my work saves you time, consider sponsoring me, just like these wonderful people do. Without your financial support, I cannot continue creating these tutorials. You can find links to Patreon, Ko-Fi, and how to become a channel member in the video description. Thank you, and don’t forget to give this video a thumbs up and subscribe to my channel if you haven’t already.

I will see you soon in my next video!

Bye Bye!


,

Back to all articles