A trigger / conditions for last person leaving a Unifi AP

Hi All, newbie here, just starting out…

I would like to send google assistant command when last of multiple people’s iphones leave a particular Unifi Wifi AP, however the entities seem to be boolean OR? Is there any way I can make the below snippet work as an AND in respect to leaving to AP? Hope that made sense and would be thankful for any suggestions

alias: Flat AP > 60s iPhone's turning Spa Deck Lights OFF
description: conditional after sunset
trigger:
  - platform: state
    entity_id:
      - device_tracker.person1_iphone
      - device_tracker.person2_iphone
      - device_tracker.person3_iphone
    attribute: ap_mac
    for:
      hours: 0
      minutes: 1
      seconds: 0
    from: 70:a7:81:d7:f1:23
condition:
  - condition: sun
    after: sunset
    before: sunrise
action:
  - action: google_assistant_sdk.send_text_command
    metadata: {}
    data:
      command: " Spa Deck Lights OFF"
mode: single

Will this be the right way below to split out the triggers and make them AND

alias: Flat AP < 10m iPhone turning Spa Deck Lights OFF
description: conditional after sunset
trigger:
  - platform: state
    entity_id:
      - device_tracker.person1_iphone
    attribute: ap_mac
    for:
      hours: 0
      minutes: 10
      seconds: 0
    from: 70:a7:41:d7:f1:88
  - platform: state
    entity_id:
      - device_tracker.person2_iphone
    attribute: ap_mac
    for:
      hours: 0
      minutes: 10
      seconds: 0
    from: 70:a7:41:d7:f1:88
  - platform: state
    entity_id:
      - device_tracker.person3_iphone
    attribute: ap_mac
    for:
      hours: 0
      minutes: 10
      seconds: 0
    from: 70:a7:41:d7:f1:88
condition:
  - condition: sun
    after: sunset
    before: sunrise
action:
  - action: google_assistant_sdk.send_text_command
    metadata: {}
    data:
      command: Spa Deck Lights OFF
mode: single

Triggers are an instantaneous event: “just left the AP” as opposed to “not connected to the AP”. There’s no such thing as an “AND” trigger.

You need to trigger off all of them as in your first code, then check that none of them is connected in the condition block. This is a little tricker than normal as you’re checking for a “not” condition, so we put a check that any of them match in a not block:

trigger:
  - platform: state
    entity_id:
      - device_tracker.person1_iphone
      - device_tracker.person2_iphone
      - device_tracker.person3_iphone
    attribute: ap_mac
    for:
      hours: 0
      minutes: 1
      seconds: 0
    from: 70:a7:81:d7:f1:23
condition:
  - not:
    - condition: state
      entity_id:
        - device_tracker.person1_iphone
        - device_tracker.person2_iphone
        - device_tracker.person3_iphone
      attribute: ap_mac
      match: any
      state: 70:a7:81:d7:f1:23
  - condition: sun
    after: sunset
    before: sunrise

Triggers when any phone drops off the AP, continues to the action only if no phones are connected and it’s nighttime.

1 Like

thanks for taking the time to reply and explain! I will test this out, cheers Troon

Please beware that it is not guaranteed that a device is connected to the closest AP in a network with multiple APs.

yep i certainly see that, all works nicely when phones cutover to the AP in question. i might de power the nearest one to make the cutover more sure. cheers

Devices will mostly try to stay on one AP until the signal is considered unacceptable.
When that limit is depends on the internal workings of the device, but cutting the power will certainly make it unacceptable for the devices connected to that AP.
The question is if the other APs are so far from each other that they will make. A jump too.
Usually the APs overlap to make sure there is always adequate coverage, which is what you need not to be true in order for your setup to work.

1 Like