Presence Automation with 2 Persons leaving home

I have set up an automation that should run when both I and my wife leave home.
I want the automation to run if both of us leave home. If just I leave home and the wife is at home, the automation does not run.

It worked once, then stopped working.

It seems to think my wife (Delores) is home, even though we have both left.

The code is:

alias: Dave & Delores Leave Home
description: Turn off Kitchen Lights
trigger:
  - platform: device
    device_id: 6dc0eb59eaf6c2244bf1b463608d6e94
    domain: device_tracker
    entity_id: device_tracker.daves_phone
    type: leaves
    zone: zone.home
condition:
  - condition: device
    device_id: 4a7ed292f4ed372ae07de6fbecab92f1
    domain: device_tracker
    entity_id: device_tracker.delores_phone_sm_g998u
    type: is_not_home
action:
  - type: turn_off
    device_id: 757ebd28a127f82617cb8ed1e618fdb2
    entity_id: switch.kitchen_light_sw
    domain: switch
  - type: turn_off
    device_id: 989afae12f3360e3cfb7c2b58e520463
    entity_id: light.dinning_room_light_sw
    domain: light
  - device_id: c8b551e4e414bc680752e91ad5c86a2d
    domain: vacuum
    entity_id: vacuum.irobot2
    type: clean
mode: single

Any and all help would be appreciated. Thanks in advance.

You could if it’s just the two of you remove the condition and replace your trigger with the following:

trigger:
  - platform: numeric_state
    entity_id: zone.home
    below: 1
1 Like

Just add both devices as triggers and conditions.

It depends on a lot of configurations. Home location, GPS, nmap, apps used to send current location of each device, … more details are needed.
It may take some minutes to update, like 10 minutes or so.

@rossk I read up on the numeric state entity, but I do not understand the “below: 1”.

If we both leave home, the automation will run in full? How does HA know we both left?

If I leave but the wife stays, how does HA know I vs my wife left? And vice versa?

Clearly, I do not understand the “below: 1” concept.

Your help with this newbie pls.

Are you sure that “is_not_home” is an actual state for that device tracker? I would try using “away” instead. Another option is to create a Group named “Anyone” and add both person.david and person.delores to that group. Then check to see if “Anyone” is home.

@w35l3y Just add both…? So it would read as follows?

alias: dave 1 leaves home
description: Turn off Kitchen Lights
trigger:
  - platform: device
    device_id: 6dc0eb59eaf6c2244bf1b463608d6e94
    domain: device_tracker
    entity_id: device_tracker.daves_phone
    type: leaves
    zone: zone.home
  - platform: device
    device_id: 4a7ed292f4ed372ae07de6fbecab92f1
    domain: device_tracker
    entity_id: device_tracker.delores_phone_sm_g998u
    type: leaves
    zone: zone.home
condition:
  - condition: device
    device_id: 6dc0eb59eaf6c2244bf1b463608d6e94
    domain: device_tracker
    entity_id: device_tracker.daves_phone
    type: is_home
  - condition: device
    device_id: 4a7ed292f4ed372ae07de6fbecab92f1
    domain: device_tracker
    entity_id: device_tracker.delores_phone_sm_g998u
    type: is_not_home
action:
  - type: turn_off
    device_id: 757ebd28a127f82617cb8ed1e618fdb2
    entity_id: switch.kitchen_light_sw
    domain: switch
  - type: turn_off
    device_id: 989afae12f3360e3cfb7c2b58e520463
    entity_id: light.dinning_room_light_sw
    domain: light
  - device_id: c8b551e4e414bc680752e91ad5c86a2d
    domain: vacuum
    entity_id: vacuum.irobot2
    type: clean
mode: single

What additional data is needed?

And what is the 10 minutes to update? For HA to realize one or both of us have left?

This newbie is confused.

Each Zone has a state attribute that contains the number of persons currently in that zone. Go to Developer Tools - States and type in “Home” and you’ll see the State attribute as well as the persons currently in the zone.

@mightybosstone Yup - it is a selection choice - “is_not_home”. I am building this via the visual editor.

There is no “away”.

In creating a group - this would be a binary sensor group or a sensor group or?

My bad - I forgot you still could not create a person Group in the Helpers. You need to do it in yaml code

    name: Anyone
    entities:
      - person.david
      - person.delores

Correct.

FYI - You should remove any personal data (GPS coordinates) from code you post here.

@mightybosstone ah - ok. I see the code, but “how do I create” this in the actual yaml files: The configuration file?

I am not comfortable doing the coding outside the visual editor - I can, but right now I need some very specific direction on how to enter / format the code.

@mightybosstone Done! Thanks !

@mightybosstone Would I enter the code like:

group:
  name: Anyone
  entities:
    - person.david
    - person.delores

Does this go at the bottom of my current configuration.yaml file? Like this:

  # Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

sensor:
  - platform: systemmonitor
    resources:
      - type: processor_use
      - type: processor_temperature
      - type: memory_free
      - type: memory_use
      - type: memory_use_percent
      - type: throughput_network_in
        arg: eth0
      - type: throughput_network_out
        arg: eth0
      - type: disk_use_percent
        arg: /
      - type: disk_use
# Text to speech
tts:
  - platform: google_translate

######### YAML File Locations #########################
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
#template: !include templates.yaml

group:
  name: Anyone
  entities:
    - person.david
    - person.delores

Yes?

This is how I have it set up:

In configuration.yaml add the following:

group: !include groups.yaml

Then create a new file named groups.yaml and add the following:

 anyone:
    name: Anyone
    entities:
      - person.david
      - person.delores

It does appear that the developers have no intention of migrating the person group functionality over to the new Helpers method, and the old .yaml method is supposed to be retired at some point. So you might be safer to just use the zone count method that rossk suggested.

@mightybosstone ok! Have the code entered ! check configuration - all good, restarted HA.

Now, the trigger is I leave home.
The condition is - my wife is at home - do nothing
Wife is not home, then turn off lights, etc.

From the visual editor, I do not see how to check the Group Anyone…??

break, break…
I understand your comment on following @rossk, I need to complete one path before I just to another…

Technically, your code will only trigger when you leave home, if your wife is already not at home. If she leaves home and you’re not currently home it won’t trigger. If you both leave at the same time your phone could flip to not home before hers. You would need a second trigger from her leaving when you’re not home for that to work. I’m not much help with the actual automation code as I use Node Red for 99% of my automations.

@mightybosstone All good help. yes to

Blockquote
Technically, your code will only trigger when you leave home, if your wife is already not at home. If she leaves home and you’re not currently home it won’t trigger. If you both leave at the same time your phone could flip to not home before hers.

Blockquote

I am not sure how to do the second trigger concept other than to just add the additional trigger in the same automation:

Dave leave home
Delores leave home

but as I understand, the triggers are an “or” function. At any rate, until I get smart enough on Node Red, which seems to be a good skill to have, I work through the visual editor and “simple yaml code”.

Now having said that I will follow your advice and work the suggestion from @rossk .

Many many thanks !

@rossk As @mightybosstone suggested (many thanks !!), I am trying your suggestion.

I have configured the trigger as you described:

trigger:
  - platform: numeric_state
    entity_id: zone.home
    below: 1

I will be testing it tomorrow and see how it works.

Keeping my fingers crossed !!

While I am testing this - how do I make it determine “who” has left - me or my wife?

You can test it without leaving home by changing the state of the device tracker in Developer Tools - States!

If you need both be away, then it should be is_not_home for both.

For the app to report HA that the device left home area.
It won’t happen at the same time, even if you are side by side with your wife.

It will execute once for each trigger.
If your device triggers the automation first (like 8 minutes after you left home area), then it will detect as your wife is still home and won’t do anything.
Then your wife’s device triggers later (like 14 minutes later she left home area), and then it will execute the automation because both conditions were satisfied this time.