Presence detection - either return home

I’m trying to understand the best way to write this automation:

When both people leave home turn lights off - that works fine.

But when one person returns it checks for the other not being home and then does other actions. This works fine too.

What I’m seeing is when we both go out, and both come back the automation doesn’t run. I’ve made two versions of this with one person coming home checking for the other and for the copy it’s visa versa. I assumed one person would check in first and the other had not yet so it would run.

Is there a smarter single automation to achieve this?

If you’d shared the code we could possibly have helped more :wink:

Typically here I’d put the device trackers (or person entities) in a group and use the state of the group. That will be home if either of you are home, and not_home when both of you are away (not_home).

Sorry, the mobile app for Android won’t copy the automation. I’ll to it when I get back to a PC.

Both devices are allocated to people, is there syntax for all people away etc? Or are we back to specific groups?

The simplest one is to use a group :wink:

The other option is to list them all in the condition.

condition:
- condition: state
  entity_id:
  - person.one
  - person.two
  state: 'not_home'

This is what I have at the moment.

description: ''
trigger:
  - platform: device
    device_id: -
    domain: device_tracker
    entity_id: device_tracker.simon_s_phone
    type: enters
    zone: zone.home
condition:
  - condition: time
    after: '19:00'
    before: '23:59'
  - condition: device
    device_id: -
    domain: device_tracker
    entity_id: device_tracker.jo_s_phone
    type: is_not_home
action:
  - service: light.turn_on
    data: {}
    entity_id: light.carport_light
  - service: light.turn_on
    data: {}
    entity_id: light.driveway_light
  - service: light.turn_on
    data: {}
    entity_id: light.dining_room_lights
  - service: light.turn_on
    data: {}
    entity_id: light.laundry_lights
  - service: light.turn_on
    data: {}
    entity_id: light.kitchen_lights
  - delay: '''00:01:30'''
  - service: light.turn_off
    data: {}
    entity_id: light.driveway_light
  - delay: '''00:05:30'''
  - service: light.turn_off
    data: {}
    entity_id: light.carport_light
mode: single

Good news, you can massively simplify that :wink:

group:
  my_people:
    name: 'My people'
    entities:
    - device_tracker.simon_s_phone
    - device_tracker.jo_s_phone

Then your automation becomes:

description: ''
trigger:
  - platform: state
    entity_id: group.my_people
    to: 'home'
condition:
  - condition: time
    after: '19:00'
    before: '23:59'
action:
  - service: light.turn_on
    data: 
      entity_id: 
      - light.carport_light
      - light.driveway_light
      - light.dining_room_lights
      - light.laundry_lights
      - light.kitchen_lights
  - delay: '00:01:30'
  - service: light.turn_off
    data: {}
    entity_id: light.driveway_light
  - delay: '00:05:30'
  - service: light.turn_off
    data: {}
    entity_id: light.carport_light
mode: single

The result is that when the first person comes home, or both of you arrive together, the automation will run.

But I don’t want it to work when one person is home.

Also I found it interesting that the timers aren’t turning off the devices. I think I have the delays right there?

The automation will only run if nobody is home, and then somebody comes home. It won’t run if somebody is already home. That’s what you said you wanted.

Seems to work well thanks. I’ve only tested it in developer mode so far.

Does the rest of the automation look right? The lights turn on but the lights I have set to turn off after a delay aren’t doing so.

Set logger's default to info and then after the automation runs check the log file. You’ll see information about it triggering, the conditions, and any errors from the actions.

Cheers, I had '00:01:30' and not 00:01:30

What is weird is including the quotations seems to be ok on the time conditions - I don’t like how the use is mixed.