Presence Automation with 2 Persons leaving home

@mightybosstone well, something went wrong. I went to developer, states, located phone, changed state to " is not home", set the state…and nothing happened.

What did I do wrong?

@w35l3y So the phones will detect leaving (or entering) a zone on their own accord - that makes sense.
Then the automation will run separately/independently based on each phone’s action or detected action by HA. Hence the automation will run twice. If I have left, and my phone happens to run first, the automation runs but stops execution because HA thinks the wife is still home. Then, as you say, the wife’s phone causes they automation to run, but this time HA “sees” I am not home and the automation completes its execution.
And vice versa if the wife’s phone triggers the automation.

Ok - got that understanding.

So need to change the one condition to “is_not_home” as you say.

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: 4a7ed292f4ed372ae07de6fbecab92f1
    domain: device_tracker
    entity_id: device_tracker.delores_phone_sm_g998u
    type: is_not_home
  - condition: device
    device_id: 6dc0eb59eaf6c2244bf1b463608d6e94
    domain: device_tracker
    entity_id: device_tracker.daves_phone
    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

I also understand from your comments, my belief the location change which causes the triggers is not real instant but could take several minutes.

Right?

You can simplify your automation.

Make a group in group.yaml

family:
  name: Family
  entities:
    - person.jason
    - person.kym

and then use that group for your automation;

- alias: Leaving Home
  initial_state: true
  trigger:
    platform: state
    entity_id: group.family
    from: "home"
    to: "not_home"
    for:
      minutes: 5

You don’t need any conditions, just jump straight to your action

@mightybosstone I confirmed I am changing the state of Home,zone from “2” to “1” when I change the state of Dave’s Phone from “home” to “not home”.

But the automation

alias: dave 1 leaves home
description: Turn off Kitchen Lights
trigger:
  - platform: numeric_state
    entity_id: zone.home
    attribute: persons
    below: 2
condition: []
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

Does not run.
help.

action:
  - service: homeassistant.turn_off
    entity_id: 
        - switch.kitchen_light_sw
        - light.dinning_room_light_sw

@kanga_who You could be right. @mightybosstone also suggested a very similar approach - using groups and many thanks to them for helping me get the group set up - in a manual fashion. Being very new to HA, I am very dependent on the Visual Editor - at least for now. I can do the coding, but need good oversight - else I’ll miss something.

Now - If I am following your coding, then if either of the two people leaves, the automation would run.
Correct?
I am hoping to get the automation to fully execute if both I and my wife are gone, but if either is home - not execute.

Also, how do you get entity_id from within the visual editor? I can get: Trigger: State, entity family, but then I can not locate group.family.

@kanga_who Wow - you lost me here. I thought by changing the state of my phone’s location as suggested by @mightybosstone (home / not home) would cause the automation to trigger - thus allowing me to test the automation without actually leaving home.

or ???

No, unless everyone in the group leaves, the automation will not run.

The easiest way to associate devices is to create a person entity and have all the devices associated with a person listed. This will account for someone with 2 phones for example.

@kanga_who oh? I thought in a “group”, if one device was true, then all were considered true. Like a group of motion sensors - if one sensor saw motion the system saw all motion sensors as having motion.

But not so with this type of group?

@kanga_who good to know!

It won’t trigger unless all members from the group have changed from home to not_home

@kanga_who Sorry - you said that before. Got my wires crossed here. Let me back up for a minute.

This is a two part comment:
1st Part

I have an automation:

alias: dave 1 leaves home
description: Turn off Kitchen Lights
trigger:
  - platform: numeric_state
    entity_id: zone.home
    attribute: persons
    below: 2
condition: []
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

If I change the state of dave’s phone from “home” to “not home”, this automation should execute - right? But it does not. Why not?

@kanga_who 2nd part of the post:

How do I test your method without leaving the house? Can I again just change the state of the phone entity?

@kanga_who using the visual editor, how do you get “group.family”

I see no chose for this option.

@kanga_who ok - maybe I got the coding correct via the visual editor in comparison to yours - pls verify:

description: ""
trigger:
  - platform: state
    entity_id:
      - group.family
    from: home
    to: not home
    for:
      hours: 0
      minutes: 5
      seconds: 0
condition: []
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
mode: single

So if the above is correct, I should be able to go into “Developer Tool”, “State”, change entity states of Dave’s Phone from home to not home and do the same with the wife’s phone and the automation should trigger - correct?

@mightybosstone @w35l3y @kanga_who So - I know I have three conversations going on - they are very helpful and I am trying all three - as I am learning a lot.

So please keep all the suggestions coming - very helpful!

If you make sure the group.family you should have created only has your phone listed (for testing purposes), then it should trigger.

@kanga_who In the group.family:

family:
  name: Family
  entities:
    - person.david
    - person.delores

Based on what you just said, it should be:

family:
  name: Family
  entities:
    - device.tracker_daves.phone
    - device.tracker_delores.phone

Yes?

@kanga_who Nope - using device.tracker…produced a bunch of errors: invalid entry, etc, etc