Geofencing automation

Hello all

I am trying to develop a geofencing automation.

By following youtube forums and reddit. I am lost and confused

some say that i need to use my phone some say i need life360 some say i need device tracker or geofency (which i read is only for IOS)

I currently have HA supervised on a laptop running debian 11 and i have android phones.

my objective is for HA to be aware when i leave my zone home (say a radius of 150 m) and it turns off device, closes gate.
when i enter zone 2 (say 500 meters) I want it to turn on devices and open gate

which is the simplest and most pragmatic way to build this

Thank you for taking the time to respond and for your help

Install the HA companion app.
It will give you a device tracker you can trigger on

Hello @Hellis81 sorry for the delay in responding to you.

I tottaly foubarred my systems and i had to rebuiltem from scratch. I also bought a samsung s10
my s10 is the device i’m want to track.

The s10 has onwtracks installed and correctly configured with the nabucase URL.( so i beleive)

If i run the automation manually it works and i get a notification from that automation.
In owntrack i insured that the device name, the home location and the radius parameters are identical to the one in home assistant.

However when i phisically leave or enter ther zone (called home) the automation does not start

The automation is quite simple

the device S10 leaves a zone home
turn off device 1
turn off device 2
send notification to S10

the only issue i can see is the following;

in developper tools under states and search for person.me
i see that: source: device_tracker.sm_g973f

and not the S10 (by the way the s10 is a model smg973f)

why will this not work?

thatn you for your patience and help

I don’t know what the issue is since you haven’t posted any automation.

Since you use Android I suggest you download the HA app and use this device tracker instead. The app has a lot of other sensors you will find useful.

Thank you for your very prompt reply.

I do have ther HA app on my android phone (S10)

My issue (sorr for not being clear) is what i am travelling away fro home in my car and go beyond the perimiter of 300 meters (that i set in both HA and owntracks) the automation is not triggered. Nor is it trigger when i enter the zone.

Here is the yaml of the automation when i arrive

alias: happy to be home
description: turn home on when i arrive
trigger:

  • platform: device
    device_id: 132e15da8df6fbaeeeae830d7448327b
    domain: device_tracker
    entity_id: device_tracker.sm_g973f
    type: enters
    zone: zone.home
    condition: []
    action:
  • type: turn_on
    device_id: f8a5c46fe803898508d12927a5352808
    entity_id: switch.shelly_shplg_s_efbdbd
    domain: switch
  • service: automation.trigger
    data:
    skip_condition: false
    target:
    entity_id: automation.heat_on
  • service: notify.mobile_app_s10
    data: {}
    mode: single

Once again thank you for your help

You need to format your code so that it’s readable.

I generally don’t use device automations, they seem to be less reliable than normal entity automations.
This could be an issue.

Also for an automation to trigger the device/entity needs to switch state to something, it will not trigger if it already is.

Thank you for your reponse

I changed the triggers from device to entity and it works.

as a newbie with limited knowledge, I would suggest that HA could simplify automations and or better document when to use device or entity in an automation

I do understand that a device can have multiple entities excellent .

However if one uses the device in the automation then in the automation can use all the entities of the device (such as time of day, day, presence humidity etc.) in that automation.

In my case using the S!0 device tracker as a trigger did not work however using the device tracker entity of that device the automation worked.

FYI: My next step is:

  1. to trigger an other automation withIn this automation (this will be fun) This will help managing event based on during time of day, temperature control via the HVAC
  2. if succesful, i will the try to combine the home and away automations into one automation

Once again thank you…be well

Could it be that this device you triggered on is not created from the mobile app?
I know my router creates a few entities, perhaps devices, I don’t know.
Either way, I can see our washing machine is home. And that is great to know. But I also have little hope on it triggering any geofencing automations.
See if you can find what created this device you tried to trigger on.

Thank you so much for your reply

In the past I had a Samsung s8 with the HA app. I started this adventure by installing life360.

Then I read many opinions and post saying that this solution was not secure.

I migrated to owntracks. All was working fine with no issues whatsoever.

In my automation at this time the trigger for the geofencing automation was the device called S8

Then my servers (because of my stupidity) crashed and I rebuilt them and still all was OK with the automation. and was working fine…

MY S8 died, so I bought an S10 last january

On this device I installed the HA app and owntracks and configured the apps opn the S10 as it were on the S8. The only difference was the device ID which went from S8 to S10 in both owntracks and HA.

Since then, the geofencing solution never worked. Now it works thanks to your help.

My router has not changed from the time of the S8 to now. My asus also generated many entities in HA.

BTW my S10 is identified in my router as S10 as it is in HA and in owntracks.

IMHO, i do not now how to identify the issue, because the only item that changed in my environment is the phone.

BTW the S8 is still a device in HA

I did look in HA at the entities for each phone and compared them. For the most part the entities are the same with the exception of the phone ID. (S8 S10)

I would say that the entities relating to presence detection are identical .

Following your suggestion my geofencing now works wounderfully even triggering an other automation within it.

I have no clue what is casing the device S10 not acting as a triger for the automation

Thank you again for you assistance