home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.56k stars 30.74k forks source link

Zone-based automation triggered by a false positive trigger: "person leaving a zone" never entered the zone in the first place #125229

Open dgtal1 opened 2 months ago

dgtal1 commented 2 months ago

The problem

I have one automation based on the zone trigger. When a person leaves the zone I should get a notification. The issue is that in most of the cases it's triggered incorrectly as the person didn't even enter the zone, so it couldn't leave it.

Trigger trace: Screenshot 2024-09-04 151502

Map view - person did not enter the zone highlited on blue: image

History for the person (device tracker)- never entered the zone, which triggered the automation: image

It seems it's triggered when the person status changes to 'not home' when leaving another zone, but this status has nothing to do with the zone defined and highlighted on blue above and the automation trigger.

It never worked correctly. Sometimes it triggers rightfully, but in 80% of cases I have no idea why it's triggered by checking the person state history and the map.

What version of Home Assistant Core has the issue?

core-2024.8.1

What was the last working version of Home Assistant Core?

never

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Automation

Link to integration documentation on our website

https://www.home-assistant.io/docs/automation/

Diagnostics information

No response

Example YAML snippet

id: '1714676744986'
alias: L wraca z Bio
description: ''
trigger:
  - platform: zone
    entity_id: device_tracker.google_maps_xxxxxxxxxxx
    zone: zone.bio
    event: leave
condition: []
action:
  - data:
      message: 'L wraca'
    action: notify.mobile_app_myphone
mode: single

Anything in the logs that might be useful for us?

Trace step config:
platform: zone
entity_id: device_tracker.google_maps_xxxxxxxxxxxxxxx
zone: zone.bio
event: leave

Trace variables:
this:
  entity_id: automation.l_wraca_z
  state: 'on'
  attributes:
    id: '1714676744986'
    last_triggered: '2024-09-04T12:43:56.471409+00:00'
    mode: single
    current: 0
    friendly_name: L wraca
  last_changed: '2024-08-12T08:45:14.891401+00:00'
  last_reported: '2024-09-04T12:43:57.088238+00:00'
  last_updated: '2024-09-04T12:43:57.088238+00:00'
  context:
    id: 01J6YH085PGBWN32P936TTGJMC
    parent_id: 01J6YH0850ZVYYZ15QMHNACZ6J
    user_id: null
trigger:
  id: '0'
  idx: '0'
  alias: null
  platform: zone
  entity_id: device_tracker.google_maps_xxxxxxxxxxxxxxx
  from_state:
    entity_id: device_tracker.google_maps_xxxxxxxxxxxxxxx
    state: Paczkomat 
    attributes:
      source_type: gps
      latitude: 50.9816893
      longitude: 17.0598609
      gps_accuracy: 1600
      address: ''
      full_name: L
      id: 'xxxxxxxxxxxxxxx'
      last_seen: '2024-09-04T13:03:08.910000+00:00'
      nickname: L
      battery_charging: false
      battery_level: 67
      entity_picture: >-
        https://lh6.googleusercontent.com/-V48hLFNpALE/AAAAAAAAAAI/AAAAAAAAAAA/xxxxxxxxxxxxxxx.jpg
      friendly_name: L
    last_changed: '2024-09-04T13:04:56.832683+00:00'
    last_reported: '2024-09-04T13:04:56.832683+00:00'
    last_updated: '2024-09-04T13:04:56.832683+00:00'
    context:
      id: 01J6YJ6Q00CCHS2NANZH78TD9S
      parent_id: null
      user_id: null
  to_state:
    entity_id: device_tracker.google_maps_xxxxxxxxxxxxxxx
    state: not_home
    attributes:
      source_type: gps
      latitude: 50.9780508
      longitude: 17.0466702
      gps_accuracy: 24
      address: aleja Niepodległości 6-8, 55-020 Żórawina, Poland
      full_name: L
      id: 'xxxxxxxxxxxxxx'
      last_seen: '2024-09-04T13:05:56.989000+00:00'
      nickname: L
      battery_charging: false
      battery_level: 67
      entity_picture: >-
        https://lh6.googleusercontent.com/-V48hLFNpALE/AAAAAAAAAAI/AAAAAAAAAAA/ACHi3reGciiPIdi0fCxEYeuH4aq4QxQL1Q/xxxxxxxxxxxxxxx.jpg
      friendly_name: L
    last_changed: '2024-09-04T13:06:57.250937+00:00'
    last_reported: '2024-09-04T13:06:57.250937+00:00'
    last_updated: '2024-09-04T13:06:57.250937+00:00'
    context:
      id: 01J6YJACK2SA98AFG9YEKZ6Z24
      parent_id: null
      user_id: null
  zone:
    entity_id: zone.bio
    state: '0'
    attributes:
      latitude: 50.98255637870848
      longitude: 17.036463618278507
      radius: 62.49672070971036
      passive: false
      persons: []
      editable: true
      icon: mdi:map-marker
      friendly_name: Bio
    last_changed: '2024-08-30T06:59:59.697982+00:00'
    last_reported: '2024-08-30T06:59:59.697982+00:00'
    last_updated: '2024-08-30T06:59:59.697982+00:00'
    context:
      id: 01J6H1AW2HBYNJWJQT7VEN9EHS
      parent_id: null
      user_id: null
  event: leave
  description: device_tracker.google_maps_xxxxxxxxxxxxxxx leaving Bio

Additional information

No response

home-assistant[bot] commented 2 months ago

Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (zone) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `zone` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign zone` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


zone documentation zone source (message by IssueLinks)

karwosts commented 2 months ago

Looks like (for better or worse?) the zone trigger uses the gps_accuracy in a way that I wouldn't have expected.

It takes your reported lat/long, draws a circle around with a radius of your gps_accuracy, and then if this circle intersects with the zone at all it considers that in the zone.

So that's why it's triggering, because you got a location report with a big value of gps_accuracy, and you're close enough to the zone that that amount of accuracy considers you possibly in the zone.

Not sure if that's intentional or not.

If nothing else you can minimize this by reducing your minimum accuracy in mobile app settings, 1600 seems pretty big to me.