Presence detection with multiple devices & multiple trackers

I use 0.58.1

I have tried both not_home and away.

From the docs…

automation:
  trigger:
    platform: state
    entity_id: device_tracker.paulus, device_tracker.anne_therese
    # Optional
    from: 'not_home'
    # Optional
    to: 'home'

Note from: or to: not state:

This presence detection not working. i check with yamllint and automation create and edit in HA. Although all device trackers list in are shown as away. The input_boolean won’t change the status according to the automation I pasted here.

- id: away
  alias: Away
  hide_entity: false
  condition:
  - condition: state
    entity_id: input_boolean.sunhome
    state: 'on'
  trigger:
  - entity_id: device_tracker.sun_iphone
    for:
      minutes: 1
    from: home
    platform: state
    to: not_home
  - entity_id: device_tracker.me_sun_iphone
    for:
      minutes: 1
    from: home
    platform: state
    to: not_home
  - entity_id: device_tracker.diana_diana_iphone
    for:
      minutes: 1
    from: home
    platform: state
    to: not_home
  action:
  - data:
      entity_id: input_boolean.sunhome
    service: input_boolean.turn_off
- id: home
  alias: Home
  hide_entity: false
  condition:
  - condition: state
    entity_id: input_boolean.sunhome
    state: 'off'
  trigger:
  - entity_id: device_tracker.sun_iphone
    for:
      minutes: 1
    from: not_home
    platform: state
    to: home
  - entity_id: device_tracker.me_sun_iphone
    for:
      minutes: 1
    from: not_home
    platform: state
    to: home
  - entity_id: device_tracker.diana_diana_iphone
    for:
      minutes: 1
    from: not_home
    platform: state
    to: home
  action:
  - data:
      entity_id: input_boolean.sunhome
    service: input_boolean.turn_on
  - delay: 00:00:10
  - data:
      entity_id: automation.away
    service: automation.turn_on

Another automation which works fine if I manually turn on the input_boolean from the previous post.

- id: office_camera_motion_on
  alias: Office Camera Motion On
  hide_entity: false
  trigger:
  - entity_id: input_boolean.sunhome
    for:
      seconds: 5
    from: 'on'
    platform: state
    to: 'off'
  action:
  - data:
      entity_id: switch.office_camera_motion
    service: switch.turn_on
- id: office_camera_motion_off
  alias: Office Camera Motion Off
  hide_entity: false
  trigger:
  - entity_id: input_boolean.sunhome
    for:
      seconds: 5
    from: 'off'
    platform: state
    to: 'on'
  action:
  - data:
      entity_id: switch.office_camera_motion
    service: switch.turn_off
  - delay: 00:00:05
  - data:
      entity_id: automation.office_camera_motion_on
    service: automation.turn_on

Couple of things, what state is the input_boolean in before any of the phones changes state to ‘away’?

What exact state is the device tracker displaying in the states table for the phone that is ‘away’?

States should be in quotes. So, you need to use to: 'home' or to: 'not_home'

1 Like

thank you very much for you reply. I will try again this evening.

the “home” and “away” automation. I used automation ui from home assistant itself to recorrect however it doesn’t work.

I have this working perfectly with 4 out of five iPhones. I am using the iOS app and Bluetooth. On the 5th iPhone, I can’t get Bluetooth to work. It reports the initial state (home or not_home), is listed in my known devices, and seems to work perfectly until the state of the phone changes (from home to not_home or not_home to Home). Then the Bluetooth device tracker doesn’t change its status. Any ideas? It is a brand new iPhone 8. I am stumped and do not know what to try.

I didn’t reply anything back in this post earlier. However, I got them working and would like to share in packages. The input_boolean just to show the state whether I’m home or away. This will automatically turn on and off. The automation make the input_boolean to away or home. Default state is home.

## sunhome

##################################################
## input
################################################## 

input_boolean:
  sunhome:
    name: Away or Home
    initial: on
    icon: mdi:account-multiple-outline
    
##################################################
## automation
################################################## 

automation:
  - id: away
    alias: Away
    condition:
      condition: state
      entity_id: input_boolean.sunhome
      state: 'on'
    hide_entity: false
    trigger:
    - entity_id: device_tracker.me_suniphone
      from: 'Home 2'
      platform: state
      to: 'not_home'
      for:
        minutes: 1
#    - entity_id: device_tracker.diana_dianaiphone
#      from: 'Home 2'
#      platform: state
#      to: 'not_home'
#      for:
#        minutes: 1
    action:
    - service: homeassistant.turn_off
      data:
        entity_id: input_boolean.sunhome
    - service: notify.ios_sun_iphone
      data:
        message: Nobody Home    
  - id: home
    alias: Home
    condition:
      condition: state
      entity_id: input_boolean.sunhome
      state: 'off'
    hide_entity: false
    trigger:
    - entity_id: device_tracker.me_suniphone
      from: 'not_home'
      platform: state
      to: 'Home 2'
      for:
        minutes: 1
#    - entity_id: device_tracker.diana_dianaiphone
#      from: 'not_home'
#      platform: state
#      to: 'Home 2'
#      for:
#        minutes: 1
    action:
    - service: homeassistant.turn_on
      data:
        entity_id: input_boolean.sunhome
    - delay: 00:00:05
    - service: automation.turn_on
      data:
        entity_id: automation.away
    - service: notify.ios_sun_iphone
      data:
        message: Everybody Home

This is the second automation that link with the input_boolean aboved. When I away this will turn on camera motion. and auto turn off camera motion when I back home.

automation:
  - id: office_camera_motion_on
    alias: Office Camera Motion On
    hide_entity: false
    trigger:
    - entity_id: input_boolean.sunhome
      for:
        seconds: 5
      from: 'on'
      platform: state
      to: 'off'
    action:
    - service: switch.turn_on
      data:
        entity_id: switch.office_camera_motion
    - service: notify.ios_sun_iphone
      data:
        message: 'Office Cam Motion ON!'
      
  - id: office_camera_motion_off
    alias: Office Camera Motion Off
    hide_entity: false
    trigger:
    - entity_id: input_boolean.sunhome
      for:
        seconds: 5
      from: 'off'
      platform: state
      to: 'on'
    action:
    - service: switch.turn_off
      data:
        entity_id: switch.office_camera_motion
    - delay: 00:00:05
    - service: automation.turn_on
      data:
        entity_id: automation.office_camera_motion_on
    - service: notify.ios_sun_iphone
      data:
        message: 'Office Cam Motion OFF!'
    - service: tts.google_say
      data:
        entity_id: "media_player.ha_speaker"
        message: "Office camera motion has turned off"

@arsaboo is this code broken? I have tried using and I keep getting errors… I am wondering if it got broken during one of the updates.

@Aussybob I was using it a week or so ago and did run into a couple problems, but I don’t know if that was my own fault (formatting and indentation or substituting my own values.

For the presence tracking, I use the following for myself and my wife. It works great and checks:

  • Owntracks (our devices report their GPS)
  • Phone bluetooth

The automation checks the presence and then alerts via Pushbullet notification plus changes the status to Away.

Here’s the setup for me, hopefully it can help:

CONFIGURATION.YAML

notify:
  - platform: pushbullet
    name: pushbullet
    api_key: your_api_key

# Create input boolean for Brandon presence tracking

input_boolean:
  brandon_status:
    name: Brandon Location Calculation
    initial: on
    icon: mdi:account-multiple-outline

AUTOMATION.YAML

# Check if Brandon is away
- id: brandon_away
  alias: Check if Brandon is Away
  condition:
      condition: state
      entity_id: input_boolean.brandon_status
      state: 'on'
  hide_entity: false
  trigger:
    - entity_id: device_tracker.brandon_phone_bluetooth
      from: 'home'
      platform: state
      to: 'not_home'
      for:
        minutes: 3
    - entity_id: device_tracker.brandon_owntracks
      from: 'home'
      platform: state
      to: 'not_home'
      for:
        minutes: 2
  action:
    - service: homeassistant.turn_off
      data:
        entity_id: input_boolean.brandon_status
    - service: notify.pushbullet
      data_template:
        title: "Home Assistant"
        message: "ALERT: Brandon just left home."

# Check if Brandon is home
- id: brandon_home
  alias: Check if Brandon is Home
  condition:
      condition: state
      entity_id: input_boolean.brandon_status
      state: 'off'
  hide_entity: false
  trigger:
    - entity_id: device_tracker.brandon_phone_bluetooth
      from: 'not_home'
      platform: state
      to: 'home'
      for:
        minutes: 3
    - entity_id: device_tracker.brandon_owntracks
      from: 'not_home'
      platform: state
      to: 'home'
      for:
        minutes: 2
  action:
    - service: homeassistant.turn_on
      data:
        entity_id: input_boolean.brandon_status
    - delay: 00:00:05
    - service: notify.pushbullet
      data_template:
        title: "Home Assistant"
        message: "ALERT: Brandon just arrived home."

hey @Nitroedge,
What are you using to track your phone’s bluetooth at your home?

Thanks,
-Tim

@timwood Hey Tim, I’m just using the Raspberry Pi that I run Hass.io on:

# Configure Blutooth tracking
  - platform: bluetooth_tracker 

I just did a Bluetooth scan with Samsung Galaxy 7 and then in my known_devices.yaml file I have the entry (notice the BT_ prefix in the mac address):

brandon_phone_bluetooth:
  hide_if_away: false
  icon: mdi:bluetooth
  mac: BT_1C:E2:56:B9:A1:5C
  name: Brandon Phone Bluetooth
  picture:
  track: true
  vendor: Samsung Electronics Co.,Ltd

Hope this helps!

Cool! Thanks. I run Home Assistant on a native Linux box (an old Dell desktop). I’m unsure whether it has bluetooth capability, so I’ll have to look into that.

Any errors?

Can you show me an example on how to use input_boolean in presence-based automations? I am really new to HASS so i am trying to understand all about this…
Thanks in advance…

Thank you for your idea. I have implemented this for my wife and me. Now I want to make an automation to turn something off when both of us leave the home not when anyone of us leaves! How can I do this “AND”

- alias: 'Kaffee aus niemand daheim'
  trigger:
    platform: state
    entity_id: input_boolean.lukas_home, input_boolean.kerstin_home
      from: 'on'
      to: 'off'
  action:
    service: homeassistant.turn_off
    entity_id: light.kaffeeschalter

If this the right way?

Create a group, and add both input Booleans to that group. Then use the group for your automation.