Due to inaccuracy in GPS tracking need condition for being in zone for certain time period after entering or leaving it

TLDR: I was using ios companion app via GPS tracking to close and open my car gate based on entering or leaving two zones (one wider zone for arrival, one narrower zone for leaving the house). For 1,5 year I never had any single issue, not one unwanted gate opening. For an unkown reason GPS accuracy became terrible recently, and my phone is “jumping” between zones with 1 second differences, causing an automation nightmare, gate opening, stopping halfway, then closing, stopping, opening again, you can imagine, became completely unusable. I’d like to put a time based condition on the trigger, so when I enter the zone in which I’d like to close the gate, I have to be there/or let’s say, not leave it for 5 second, before firing the action, closing the gate. I need your help to achieve it, my current automation is at the end of this post.

Background:
I received so much help from this community and I have a great hope for the community to step in once more to help me solve my issue.

I have two location based automations to contol my car gate door. I have 2 extra zones set up for this purpose besides my home zone: a wider “neighbourhood” zone for opening the gate, covering several streets in the neighborhood, this way the gate has enough time to fully open, and I just slip through like Michael Douglas as Van Orton in The Game (don’t know why, but this scene as he pushes his 7er Bimmer through the gates stuck in my mind :slight_smile: ) ; and one narrower “leaving” zone for leaving the house: this ensures that the gate starts to close as soon as I’m a couple houses past my home.

This setup worked flawlessly for 1.5 years, not failing on me once, never had any unwanted gate event, and I freakin’ enjoyed the luxury high life HA granted me :slight_smile:

But all this went away, and now unwanted state changes occur constantly. Honestly I don’t know what happened or changed, any update or so, it just started to happen: leaving the house automation still works 100%, but arriving just became a nightmare, for the following reason: when I enter neighbourhood zone, gate starts to open, while I’m approaching my house GPS inaccuracy throws me into Home zone for a few seconds, and as I get closer during these seconds, then it puts me into the narrower “leaving” zone, thus immediately closes the gate just as I arrive to the gate. Sounds frustrating, uh? You can’t imagine, it kills me every time.

(To add a top layer 1st world misery on this cake: as I’m close to the house, my phone starts picking up and loosing my home wifi in a loop (signal is weak at the gate), and as I try to open the gate in Home app, I just get unresponsive devices because of the constant network changes :slight_smile: :slight_smile: So I’m stuck at the gate for a couple of minutes until I manage to finally open that freakin’ gate.)

Tried to search on the problem, but after reading a lot of similar GPS inaccuracy reports I’m surprised now how it was working for me at all super flawlessly for the past 1,5 years, so I thought about putting a time based condition on the leaving-close-gate automation, to avoid these accidental zone enter-exit changes.

So, I’d like to ask a little automation condition config help how to properly achieve this:

  • trigger: when zone “leaving” entered
  • condition: be in/or did not leave zone “leaving” for 5 seconds
  • action: ONLY THEN close the gate.

If anyone has any other smarter/simpler solution to the problem, please don’t hold it back, share with me!

My automation in it’s current form:

alias: Close the gates after I leave
description: ''
trigger:
  - platform: zone
    entity_id: device_tracker.iphone12pro
    zone: zone.leaving
    event: leave
condition: []
action:
  - device_id: c976348e0df011ebb15c356dbb4e5d0c
    domain: cover
    entity_id: cover.frontgate
    type: close
  - device_id: b05dceae0df011ebafa47188d05deb72
    domain: cover
    entity_id: cover.garage
    type: close
mode: single

Thanks in advance for anyone trying to help!

trigger:
  - platform: state
    entity_id: device_tracker.iphone12pro
    state: 'leaving'
    for:
      seconds: 5

You’d need to check the state of your device_tracker when in the “leaving” zone: might be 'Leaving' instead.

Why is it updating so frequently?

I have the same problem and found this ‘workaround’ elsewhere on the forum…
So trigger a script and add the delay there.
TBH I now use Node Red mainly, so just have similar delays set using different nodes but the principle is the same.

Finally, check ‘where’ your location is changing to - mine randomly jump to my old address a few miles away (suspect its based on wifi location database within Ios). I have created a new zone there called ‘ignore’ and then filter that out any time my phone decides it can teleport.

automation:
  - alias: Leaving ZONE NAME
    trigger:
      platform: state
      entity_id: device_tracker.XXX
      from: 'ZONE NAME'
    action:
      service: script.turn_on_10_min
  - alias: Entering ZONE NAME
      platform: state
      entity_id: device_tracker.XXX
      to: 'ZONE NAME'
    action:
      service: script.turn_off
      entity_id: script.turn_on_10_min
script:
  turn_on_10_min:
    sequence:
      - delay:
          minutes: 10
      - service: switch.turn_on
        entity_id: switch.YYY

Dear @Troon ,
I have absolutely no clue why this all started. It was rock solid as I mentioned, and this shit storm came on me.

Thanks for the suggestion, it is really this simple? :joy:

Dear @Dangermoose , several questions:

  • how do you filter out a location?
  • in my case the “jump” is not significant, couple of 10 meters or so, but since it jumps in and out (thus entering and exiting all the time within a few second time span) of triggering the same automations but with opposite effect multiple times, that gives me the headache. And madness. And burnout. And meltdown.
  • maybe I didn’t get it right what you suggest with the delay, but would I only prolong the problem with the delay? I mean, each zone enter exit event would still be recorded and these event would still fire my actions, just after a couple of seconds… Wouldn’t it? I need it as a condition, so I can prove to HA that I’m not teleporting all the time just for fun.

@Troon ,

Tried to apply your suggestion but I’m little confused how to apply it precisely: first, in automation GUI editor there’s no possibility to enter a For time condition to the trigger, and if I switch to yaml editor, then it a different trigger platform, zone, instead of state:

platform: zone
entity_id: device_tracker.iphone
zone: zone.leaving
event: leave

In your example how do I define which zone should HA consider for the exit event?

Filtering zones might not help if its just a small jump, as you’d have to create that zone next to your current one and that just sounds messy and likely to cause more issue - but for reference its using a not condition. i.e. don’t run if you enter the phantom zone.

 condition: not
  conditions:
    - condition: state
      entity_id: device_tracker.paulus
      state: "the phantom zone"

My suggestion would turn on the script as you ‘left’ but the first step in the script is to wait 10 minutes (this could be 30 seconds if your jumps are so quick). The second automation turns off the script as you enter.

So -
Phantom Leave - Turn on script
Script Wait x minutes/seconds
Phantom Return - Turn off script (stops running)

Genuine Leave - Turn on script
Script Wait x minutes/seconds
Script executes as you haven’t stopped it.

Any genuine returns would also trigger the script to turn off, but as it should already be ‘off’ then no action will actually occur.

Huh? I don’t use the UI editor, but I just tried it to check if my garage access point ever tries to run away:

1 Like

Yep yep, but I’m using zone template, not state, and I was a bit confused how to properly reference a given zone, but I assume simply it’s name without zone. prefix

Yes. Look at your device tracker state under Developer Tools / States.

1 Like

Thanks. Things improved thanks to your suggestion, now it only closes the gate on me after I pulled into the garage :slight_smile: which is still not ideal, but I hope I can fine tune it from here on.

This is what happens btw, take a look at the timestamps, jumps in and out… I’m not sure what’s the difference between the different location types, like geocoded location and the other? Maybe I should use one specific type in automations because that could be more precise by its nature?

I should state that my phone was not moving physically during this timeline and the zones are in the following order (larger radius first):

  • zone.neighbourhood
  • zone. leaving
  • zone.home

Perhaps you could detect if you’re connected to your home wifi instead of relying on the zones?

not, unfortunately, for two reasons:

  • it would defeat the purpose to start opening the gate a couple of hundred meters in advance, so it IS open until I pull up there
  • my phone connected to the car’s wifi because of wireless carplay until I shut the car down

I was thinking of iBeacons, does anyone have some experience on them?