5 second Presence Detection (Bluetooth or Wifi)

Hi,

I need very response and solid / reliable presence detection on WIFI (within 5 seconds of joining or leaving WIFI network) update state of two devices to home or not_home to trigger automation with google home TTS.

I have tried NMAP with Device tracker component and specified 2 hosts (to speed up scan) but it frequently triggers the automation incorrectly. Example after 5 seconds the icon status for the two mobiles are set to ‘not_home’ and then quickly flicks to ‘home’ but this triggers google home to say ‘Hi’ and then not long after ‘Bye’ this goes around in a loop.

Can anyone help to point out why this is happening, is it a limitation and is there a better solution?

Example configuration.yaml:

device_tracker:
  - platform: nmap_tracker
    hosts:
    - 192.168.1.1
    - 192.168.1.2
    track_new_devices: no
    interval_seconds: 5
    consider_home: 7
    
automation:
  - alias: 'Home' 
    trigger:
      platform: state  
      entity_id: device_tracker.mac
      from: not_home
      to: home
    action:
      - service: media_player.volume_set
        entity_id: media_player.kitchen_speaker
        data_template:
          volume_level: 0.7   
      - service: tts.google_say
        entity_id: media_player.a_speaker
        data_template:
          message: "hi!"
  - alias: 'Not Home'
    trigger:
      platform: state  
      entity_id: device_tracker.mac
      from: home
      to: not_home
    action:
      - service: media_player.volume_set
        entity_id: media_player.a_speaker
        data_template:
          volume_level: 0.7   
      - service: tts.google_say
        entity_id: media_player.kitchen_speaker
        data_template:
          message: "bye!"

I have changed presence detection to blueooth but the same problem keeps flicking back to not_home.

I noticed when it does this it sets assumed_state=False is this the culprit? how do I get around this?

Nov 05 23:30:50 UbuntuOS docker[3315]: 2017-11-05 23:30:50 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=group.all_devices, old_state=<state group.all_devices=home; entity_id=('device_tracker.galaxy_note5',), order=1, auto=True, friendly_name=all devices, hidden=True, assumed_state=False @ 2017-11-05T23:30:39.923014+10:00>, new_state=<state group.all_devices=not_home; entity_id=('device_tracker.galaxy_note5',), order=1, auto=True, friendly_name=all devices, hidden=True, assumed_state=False @ 2017-11-05T23:30:50.773267+10:00>>

Use multiple methods for presence detection and create a group with them. Then trigger you automation based on group state

Hi

That sounds like a good idea. Have you got an example code?

Bluetooth and wifi?

I don’t use because my detection is very reliable. Search the Community, there are several examples of presence detection grouping.

Hi…what setup have you got for prescence detection and how is it reliable? Do you have phones that dont experience doze or power save false positives with state home or away?

I have three phones being monitored by Zanzito. It is very accurate but depends on how often the phones send the location. In my case they report every 3 minutes, that means that at most my home lights turn off 3 minutes after I leave home. Do you need any additional info?

I use the Xiaomi Router Mini that cost less than 35€ (28€ on the 11.11) and is an awesome router.
Home-Assistant get the list of connected device from it and it has always been accurate.

There is a dedicated tracker component for it:

It usually detect my presence before me being home, since the phone connect to my wifi when I park/walk back home.

I have direct router detection with the Asus Vodafone unit but I don’t use it for presence detection

Thanks I might look into that router, I have a modem / router on NBN so dont really want any more equpiment. I have been using bluetooth for a week or so and it picks up signal approx 10m away and is fairly reliable but what I really want to do is:

Have a variable on the front-end or something that gets updated with my state Home / Not Home / Work from the following:

Owntracks + Mosquitto - GPS (Home / Not Home / Work)
Bluetooth (From device bluetooth - Home or Not Home)
Wifi namp (From home router - Home or Not Home)

Any idea of how to get the above setup to update a variable or something on front-end?

That’s possible but you would have to define some priority first.
Which one would win if wifi say you are not_home, bluetooth say you are and owntracks say you are at work (battery died while being at work or smth like that)?

There is many post on this topic:
https://community.home-assistant.io/t/using-multiple-trackers-in-groups-to-detect-presence
https://community.home-assistant.io/t/presence-detection-with-multiple-devices-multiple-trackers/

I have read a few posts but I am confused with the most accurate / right way to do things.

My thoughts on current state presence detection for ‘My Location:’ for automation, I am a noob so think in psudeo code can you help with translating this to HA presence detection code to cover the scenarios:

Scenario A1: If current state of presence is ‘Not Home’ arrival by car walk up driveway enter house with phone battery okay:

  1. In car within Home Zone 10 / 20 meters radius OwnTracks/ Mosquitto set presence state ‘Within Home Zone’
  2. Optional - if face detection via camera for smart lock then set presence state to ‘At Home (Camera)’ - definitely arrived home.
  3. Bluetooth (10 sec polling) if phone or other bluetooth device owned by me e.g. Gear S3 enters range set presence state to ‘At Home (BT)’ - appears to be most accurate less power drain
  4. Wifi nmap (30 sec polling but 180 sec appear at home for the deep sleep thing) if presence state is currently ‘At Home (BT)’ set presence state to ‘At Home (BT/WIFI)’ else set presence state to ‘At Home (WIFI)’

Scenario A2: If current state of presence is ‘Not Home’ arrival by car walk up driveway enter house phone battery dead:

  1. Bluetooth (10 sec polling) if phone or other bluetooth device owned by me say Gear S3 enter range set presence state to ‘At Home (BT)’ - appears to be most accurate less power drain
  2. If no device use voice to tell Google Home ‘ is at home’ to set presence state to ‘At Home (ByVoice)’ - Most accurate but point in time

Scenario B1: If presence state set to ‘At Home (xxx)’ and still at home within range of bluetooth and wifi and GPS (but indoors so might not work) with phone battery okay

  1. Bluetooth (10 sec polling) if phone or other bluetooth device owned by me Gear S3 enters range set presence state to ‘At Home (BT)’ - appears to be most accurate less power drain
  2. Wifi nmap (30 sec polling but 180 sec appear at home for the deep sleep thing) if presence state is currently ‘At Home (BT)’ set presence state to ‘At Home (BT/WIFI)’ else set presence state to ‘At Home (WIFI)’
  3. If within Home Zone 10 / 20 meters radius OwnTracks/ Mosquitto working and current presence state contains ‘At Home (xxx)’ do nothing

Scenario B2: If presence state is ‘At Home (xxx)’ and phone battery dead

  1. Bluetooth (10 sec polling) if phone or other bluetooth device owned by me say Gear S3 enter range set presence state to ‘At Home (BT)’ - appears to be most accurate less power drain

Scenario C1: Current presence state set to ‘At Home (xxx)’ and leaving home with phone battery okay

  1. Bluetooth (10 sec polling) if phone or other bluetooth device owned by me say Gear S3 enter range set presence state to ‘At Home (BT)’ - appears to be most accurate less power drain

Scenario C2: Current presence state set to ‘At Home (xxx)’ and leaving home with dead phone battery

  1. If no device use voice to tell Google Home ‘ is leaving in 5 minutes’ to set presence state to ‘Not Home’ in 5 mins