154
@null_pointer_ok ·

Arrival automation fires twice when two of us get home within a minute Automation

The automation turns on the hall light and disarms the alarm when someone gets home. If my partner and I arrive together, both phones cross the zone boundary within about 40 seconds and the whole thing runs twice, which means the announcement plays twice and the light gets a second command. I have a condition that checks nobody was home, but it clearly evaluates before the first run has finished. What is the correct pattern here?

8 answers Share
Report

Answering anonymously — a moderator will review it first.

  • @cache_invalidator · 7mo ago · 3 replies

    Two fixes, and you want both.

    First, trigger on the group rather than the people. Make a group of the two person entities and trigger on the group changing from not_home to home. A group like that only changes state once, when the first person arrives, so the second arrival produces no trigger at all. This is the actual fix.

    Second, set the automation mode to single and leave max_exceeded logging on so you can see when it happens. Single means a second trigger while the first run is still going gets discarded rather than queued. Your condition problem is a race, and mode single removes the race even if you keep the current triggers.

    The thing not to do is add a delay at the top hoping the second trigger arrives late enough to be filtered. That kind of fix works for a month then fails on the day someone parks slowly.

    231
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @yaml_yeoman · 7mo ago

      Group trigger is the right answer. Worth knowing that a person group goes to home if any member is home, so it does exactly what a human means by the house being occupied.

      78
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
    • @logfile_lena · 7mo ago

      And put the announcement in its own script called from the automation. Then if you ever do want the light logic to run per person, you can, without the voice going twice.

      30
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @crashloop_cara · 7mo ago · 2 replies

    The state trigger detail people miss: trigger on from not_home to home explicitly, not just to home. Without the from clause, any attribute update while already home can re-trigger, which produces the same duplicate behaviour with only one person involved and is much harder to spot.

    96
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @refresh_rhea · 7mo ago

      This bit me for months with a phone that updated its battery level attribute constantly. Every update looked like an arrival to a sloppy trigger.

      34
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @reverse_proxy_ro · 7mo ago

    If you want belt and braces, add a latch: an input_boolean set when the automation runs and cleared 5 minutes later, with a condition that it must be off. It is slightly ugly but it also protects you from GPS jitter, where a phone bounces out of the zone and back at the edge of the geofence and fires an arrival for someone who never left.

    62
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @bill_and_hold · 7mo ago

    Related tip: make the zone bigger than you think. A 100 metre geofence produces far more bouncing than a 250 metre one, and half the duplicate arrival complaints I have seen were really jitter on a tight radius rather than two people arriving.

    28
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @leaky_bucket_ed · 7mo ago

    For the light specifically, making the action idempotent solves half the pain. Turning a light on that is already on costs nothing. It is the announcement and the alarm state change that need protecting, so it is worth separating them.

    12
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report