Why didn't the security alarm switch turn on when bernard and karen left home?

I thought this would work but when my wife and I left home at the same time, the security alarm switch did not turn on. Can anyone tell me why that did not occur?

-Thanks

alias: NFC - Geolocation
description: ""
triggers:
  - entity_id:
      - person.bernard
      - person.karen
    trigger: state
actions:
  - choose:
      - conditions:
          - condition: state
            entity_id: person.bernard
            state: not_home
          - condition: state
            entity_id: person.karen
            state: not_home
        sequence:
          - target:
              entity_id: input_boolean.security_alarm_switch
            action: input_boolean.turn_on
      - conditions:
          - condition: or
            conditions:
              - condition: state
                entity_id: person.bernard
                state: home
              - condition: state
                entity_id: person.karen
                state: home
        sequence:
          - target:
              entity_id: input_boolean.security_alarm_switch
            action: input_boolean.turn_off

Have a look at the automation Traces.

There is no such thing as "at the same time", but if the state change events happen close enough in time (and the mode is set to the default single) then the first person's state would trigger the automation, but the condition would fail because the second person hasn't yet been marked as not_home. Set the mode to queued so that the second person's state change doesn't get dropped.

Another common cause for this type of thing is misunderstanding the state of "not_home". A person entity will have that state when they are not in any active Zone. If you have zones that are contiguous with or overlap "home", your person entity may not be not_home. A better condition would be:

      - conditions:
          - not:
              - condition: state
                entity_id: person.karen 
                state: home
              - condition: state
                entity_id: person.bernard 
                state: home
        sequence:
1 Like

To expand on this: if this happened, there will be a warning in the logs. I cannot remember now whether one would see the second trigger with a trace that's aborted or no trace at all, but the logs will definitely tell you.

Yea, I looked at the traces, they indicate what happened, but not why it happened.

-Thanks

Thanks, I changed the mode to "Queued" with a queue length of 4. Now I just either have to kidnap my wife or at least her phone, to test. :slightly_smiling_face:

Thanks I'll have to check the logs the next time, if there is a next time. Didgeridrew's recommendation to change the automation mode to queued sounds like the solution. Now, to get my wife's cell phone for testing. Wish me luck! :slight_smile:

I suggest to use a proximity sensor.

I have mine and my spouse’s grouped, and if the distance is more than 200 mtr for more than 5 minutes, turn on the alarm :wink:

Why are we not using the numeric state of zone home? It eliminates all this if someone then someone but if.

When it hits 0 if your person ents are setup correctly 0== vacant. >0 == home. ...Done.

Its waaaaay easier. And then you eliminate all this queued parallel or whatev nonsense.

3 Likes

Thanks I'll take a look at that. That does seem easier "by the numbers". But I just discovered that I have two Pixel 8 phones, there should only be one. The Pixel 8 was my phone and I got a Pixel 10 Pro and gave the 8 to my wife. It got installed again somehow.

This solves the problem Bernie. You assign device trackers to a person then the system resolves the rest. You can stop worrying about each tracker and just care about the zone. 0== vacant every time.

The zone home count works every time. Testing the state of a person is tricky, because the state of that person can also be the name of a zone. So you'd have to account for states other than home and not_home too.

I believe this is what you are referring to. As you said much simpler!

-Thanks

alias: NFC - Geolocation
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - zone.home
    attribute: persons
    below: 1
    id: below 1
  - trigger: numeric_state
    entity_id:
      - zone.home
    attribute: persons
    above: 1
    id: above 1
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - below 1
        sequence:
          - target:
              entity_id: input_boolean.security_alarm_switch
            action: input_boolean.turn_on
      - conditions:
          - condition: trigger
            id:
              - above 1
        sequence:
          - target:
              entity_id: input_boolean.security_alarm_switch
            action: input_boolean.turn_off
mode: queued
max: 4
conditions: []

-Thanks

1 Like