Presence detection with multiple devices & multiple trackers

Presence is one of the cornerstones of a good home automation system. HomeAssistant offers multiple methods of detecting presence. Unfortunately, however, any single method is far from reliable. Like most of you, I struggled a multiple presence detection methods to improve the wife acceptance factor. After lot of iterations, I (think) have the perfect system that detects presence very reliably and I thought of sharing the same with you.

Given that any one method is not entirely reliable, I use multiple presence detection methods. I am currently using three methods - the HA iOS app, Owntracks/MQTT, and Asuswrt. The basic premise (or hope) is that at least one of them is right and, not surprisingly, it is the one that was updated most recently. All, we need is to create rules/automations that utilize the most recently updated tracker.

I created an input_boolean that keeps track of whether I am home or not_home.

input_boolean:
  alokhome:
    name: Alok Home
    initial: on
    icon: mdi:cellphone-iphone

Next, I created automations that will update the input_boolean variable whenever any of the device_tracker updates. Hereā€™s an example of the automation (note the three entities are for the three trackers that I am using):

- alias: 'Mark Alok Away'
  condition:
    condition: state
    entity_id: input_boolean.alokhome
    state: 'on'
  trigger:
    - platform: state
      entity_id: device_tracker.myiphone
      state: 'not_home' 
      for:
        minutes: 10
    - platform: state
      entity_id: device_tracker.pi_alokphone
      state: 'not_home' 
    - platform: state
      entity_id: device_tracker.alokiosiphone
      state: 'not_home'       
  action:
    - service: homeassistant.turn_off
      entity_id: input_boolean.alokhome

- alias: 'Mark Alok Home'
  condition:
    condition: state
    entity_id: input_boolean.alokhome
    state: 'off'
  trigger:
    - platform: state
      entity_id: device_tracker.myiphone
      state: 'home' 
    - platform: state
      entity_id: device_tracker.pi_alokphone
      state: 'home' 
    - platform: state
      entity_id: device_tracker.alokiosiphone
      state: 'home'       
  action:
     service: homeassistant.turn_on
     entity_id: input_boolean.alokhome

These automations will ensure that input_boolean.alokhome will always have the most updated information about my status. You can add as many trackers as you want (more the merrier) and then use the input_boolean.alokhome for any subsequent presence-based automations.

This probably is nothing new to most of you, but it took me a while to figure out and hope this is useful for some of you. I have been using this system for a while and am very happy with it. Please let me know if you have any feedback.

65 Likes

Thank you.

This kind of worked as a tutorial for me. I now have my very first input boolean!

Very Helpful thank you!

Agreed, this is very helpful. Iā€™m going to look into implementing something like this, because Owntracks + MQTT has been terrible, and the HomeAssistant iOS app hasnā€™t been 100% either. Thank you for sharing.

thank you for this cool idea!

So first of all thanks for posting your project, they really help people who are getting started get ideas or have a cookbook to implement HA.

A bit unrelated but I didnā€™t realize an automation can have multiple triggers. Is this working for you? I assume any one of the triggers can start the automation?

Yesā€¦an automation can have multiple triggers and any of the triggers can turn on the automation.

3 Likes

Thanks, good to know!

So how does this work with displaying presence status? Using device tracker (the default way), I get a home / away icon at the top of my main page. Does this still feed that?

Yesā€¦you will now use the input_boolean for presence. You may have to customize your view to your liking.

Thank you for sharing it!

Let me add my two cent here from the Android phone sideā€¦

We only have android devices and very good wifi coverage around the house, because we use multiple TP-Link WiFI APs.
1 Main Router and a few WiFI AP (with dhcp and everything else disabled).

If I enable only ONE TP-Link tracker (for the main router), the presence detection works great as long as the phone is using the main router WiFi antenna.
If we are on the other side of the house, the phone connects to the strongest = different WiFi AP and the HASS TP-Link module stops seeing the phone on the router.

To solve this, I tried using multiple TP-Link trackers and HASS boots fine with them. No error msg or anything but the detection stops completely, even on the main router (that worked before).

In the logs, its just keepsā€¦

INFO (Thread-10) [homeassistant.components.device_tracker.tplink] Loading wireless clients...
INFO (Thread-11) [homeassistant.components.device_tracker.tplink] Loading wireless clients...

ā€¦every 25sec (thats my configured time).

Wonder if its a bug that can be fixed or Software/HW limitation.

- platform: tplink
   host: 192.168.0.1
   username: !secret tplink_username
   password: !secret tplink_pw
   consider_home: 60
   interval_seconds: 25
- platform: tplink
   host: 192.168.0.2
   username: !secret tplink2_username
   password: !secret tplink2_pw
1 Like

Nice thanks for sharing. I went down a different route and bought a ibeacon then linked it to OwnTracks. Iā€™m 2 months on and itā€™s let me down once otherwise itā€™s been working flawlessly for both me and the wife.

1 Like

You can also put all the related tracker entities in a group so that the state home/not_home (of the group) is determined by the fact that atleast one of the trackers report its state as home.

I currently use both nmap and owntracks and its working nicely. The biggest issues i have seen reported are caused by the fact that users are following the manual ( Using Owntracks with other device trackers ) and they combine the MAC-address of the device they want to track with their owntracks entity.

If you put the MAC-address you want to track on another entity your home/not_home status is determined by the last update send to HA instead of a combined state. So basically when your phone shortly looses wifi connection nmap will send an update you are not home while your owntracks status might still put you at home, but since the nmap status is the last your state will be not_home.

8 Likes

Thanks for that. Iā€™m splitting up the devices now and going to use a group to try and make it more stable. Did not even think of this as the cause for my state changing randomly.

note: when a device (mobile) goes to sleep ā€¦ nmap and owntracks do not work ā€¦ had many cases when multiple devices where physical ā€˜homeā€™ but all registered as ā€˜not homeā€™ā€¦ Iā€™m not taking the approach of using a presence detection as secondary measure. Ie before: turn lights on when someone was ā€˜HOMEā€™ , now turn Selected lights on 5 mins before sunset. Non critical operations will use presence detection.

Iā€™m currently investing a Home priority level ie , Level 1 - 100% chance someone will be home from 6pm to 7am ( ie mon - thur, on school days) , Level 2 , 75% chance everyone will be out friday and saturday night. ā€¦ Level 7 , Away for the weekend , level 10 - overseas, this will mean the alarm will be on !! etc ect This will be backup up with the following , is the TV on ? etc

Rather than fighting with Presence detection , turn it on its head !!

2 Likes

The only real issue i have with using just a phone for presence detection is the fact that you need to make sure you donā€™t run out of battery. I donā€™t have any issues with my phone locked, but that might be different with other devices.

Still thinking about adding a keychain beacon for presence detection.

I agree that presence detection is mostly for non-critical operations. Most of my light operations are based on sun-states and besides that i still use zwave wall-switches for manual operations.

1 Like

Iā€™ve thought about adding that into the mix as well. The problem there becomes what if someone decides to leave their keys/handbag at home? Then your house will think someone is home when everyone is out, and not shutdown/turn on the alarm.

1 Like

Hey @jamieb - how did you get the iBeacon working reliably? Mine regularly enters / leaves the location when in the exact same location. I have 2 setup on the same UUID (different minor values) and show a strong signal (Ā±80). Also whilst my logbook does not show me away, something location based keeps triggering my home / not-home automations! :frowning: At my wits end with it! Have 2 Avvel hybrid devices (30m range).

I have one iBeacon (Social Retail i9 which claims a range of up to 200feet/60m) this resides by my main entrance.

I have Zones set up in Home Assistant Lat/Long with a radius of 200 (Home, Work, Parents, Friends etc)

I then replicated with the exception of ā€œHomeā€ all these Zones exactly in the OwnTracks app ā€œRegionsā€ area.

Set up my iBeacon UUID, Major/Minor and gave it a name (Which matched my Zone name in Home Assistant ā€œHomeā€)

I then went on to add my final Region ā€œHomeā€ to the OwnTracks app adding Lat, Long, UUID, Major and Minor values. Gave it a Radius of 0 and turned Share on (Not sure from memory if Share is required).

I and the Wife run OwnTracks on iOS and keep the app open all the time, which cripples my swipe away ocd but battery impact seams minimal. This sends updates to a Mosquito instance at home.

Since my last post i have had 1 false ā€œNot Homeā€ trigger due to being falsely declared as ā€œawayā€ whilst updating Home Assistant configurations and restarting but apart from that exception its still running flawlessly ā€œTouches woodā€.

Hope this helps if you need to know anything else let me know.

2 Likes

I suspect that each of your routers are operating a separate subnet, or at least separated by firewalls using individual DHCP servers (as they come by default). You should try:

  • Configuring you routers in star mode (connect all routers to Router 1 via ethernet):
* Router1
 * Router2
 * Router3
 * RouterN
  • Keep Router1 as is, but disable Firewall and DHCP server on all other routers. Router1 protects you from external internet, but all your devices will share the same subnet determined by Router1.
  • Enable TP-Link tracker for Router1 only.