Combining trackers?

Here’s my known_devices for my phone:

pi_firstof9:
  hide_if_away: false
  mac: DE:AD:BE:EF:00:00
  name: pi
  picture:
  track: true
  vendor:

This how owntracks tracks on the MQTT, then the SNMP uses this entry for the MAC address (replaced) for my phone once it auto connects to my wifi.

device tracker.yaml:

  - platform: owntracks
    max_gps_accuracy: 200

  - platform: snmp
    host: 192.168.1.1
    community: rocommunity
    baseoid: 1.3.6.1.2.1.4.22.1.2

This blog has details on implementing detection using bayesian filter, I hope someone finds it useful:

@gregg098 I am new to this, so anything you can share on how to set this up would be much appreciated.

So you are saying that I just create my own known_device with a MAC address and then that will be used by Unify. I then keep the one for the App that is already working without the MAC thereby getting two different known_devices for the same device to track on…I think?

First, let all of your device trackers create their own known_devices.yaml entries. The Unifi component will create an entry named after the associated device’s hostname and include the wifi MAC address in it. For these entries, you can rename it if you want to. For example (just randomly picked on):

harmony_downstairs:
  hide_if_away: false
  icon:
  mac: xxxxxxxx
  name: Harmony (Downstairs)
  picture:
  track: true
  vendor: Slim Devices, Inc.

To:

bigTV:
  hide_if_away: false
  icon:
  mac: xxxxxxxxxx
  name: Harmony (Downstairs)
  picture:
  track: true
  vendor: Slim Devices, Inc.

Now, instead of device_tracker.harmony_downstairs I can use device_tracker.bigtv, if that matters to you.

This works because the MAC address is the identifier. Same goes for the Bluetooth tracker.

Other device tracker components, such as GPS Logger, will make entries that do not have a MAC address. The actual device tracker name is linked to the app so you have to figure out how this is specified in that particular app. Renaming it will break it and Home Assistant will just create a new default entry based on the app input.

GPS Logger entry example:

gregg_phone:
  hide_if_away: false
  icon:
  mac:
  name: gregg_phone
  picture:
  track: true
  vendor:

Note, the “name:” field is only the friendly name. It does not affect the device_tracker.xxxx name. I set the GPS Logger app to make the http request with the name of “gregg_phone.”

If you want to group a bunch of trackers, create something like this in your groups.yaml

  tracker_gregg:
    name: Gregg
    view: no
    entities:
      - device_tracker.gregg_phone
      - device_tracker.gregg_phone_wifi
      - device_tracker.gregg_phone_BT

Now, the state of group.tracker_gregg is based on the state of all of the trackers. My automations are very simple and just look to see if the state is “home” or not. I have never tried to mess with other zones (e.g. work, school, etc.). The group method may not work if this matters to you.

Hope this is what you are asking for.

3 Likes

Hi All

Just a update to everyone @gregg098 @nickrout @firstof9 @jimpower @oakbrad my effort to combining all the trackers.

  1. Unifi setup
  2. Unifi ping (Enable ping on USG! link)
  3. NMAP
  4. Fixed IP’s on all iPhones
  5. Installed HA app and setup GPS
  6. Install Bluetooth on Rasp3 and enable this (Reboot, disable wifi on phones and search on BT)

After some much testing I setup my first bayesin sensor

binary_sensor:
  - platform: bayesian
    prior: 0.5
    name: 'Victoria Presence'
    probability_threshold: 0.9
    observations:
      - entity_id: 'device_tracker.victoriasiphone_ping'
        prob_given_true: 0.9
        prob_given_false: 0.1
        platform: 'state'
        to_state: 'home'
      - entity_id: 'device_tracker.victoria_iphone'
        prob_given_true: 0.9
        prob_given_false: 0.4
        platform: 'state'
        to_state: 'home'
      - entity_id: 'device_tracker.victoriasiphone_2'
        prob_given_true: 0.8
        prob_given_false: 0.4
        platform: 'state'
        to_state: 'home'

This gave me a on/off for presence like this:
precense

But I wanted a device_tracker so I found this great Node Red string from https://diyfuturism.com/
I then created this:

You dont have to create this by hand, just paste below code and change your own HA settings/names
(Again thanks to https://diyfuturism.com/ unfortunately the DB is down on this page so I am pasting the code below)

[{“id”:“763070f9.0c571”,“type”:“switch”,“z”:“4056fc4f.0baa64”,“name”:"",“property”:“payload”,“propertyType”:“msg”,“rules”:[{“t”:“eq”,“v”:“on”,“vt”:“str”},{“t”:“eq”,“v”:“off”,“vt”:“str”}],“checkall”:“true”,“outputs”:2,“x”:1316.9999771118164,“y”:301.00000381469727,“wires”:[[“57b903a4.bd2f6c”],[“a080246.03d5ed8”]]},{“id”:“57b903a4.bd2f6c”,“type”:“api-call-service”,“z”:“4056fc4f.0baa64”,“name”:“Set Presence Home”,“server”:“8ac3cd7f.58d3e”,“service_domain”:“device_tracker”,“service”:“see”,“data”:"{“dev_id”:“brad_bayesian”,“location_name”:“home”}",“x”:1510.3333740234375,“y”:272.6667175292969,“wires”:[]},{“id”:“a080246.03d5ed8”,“type”:“api-call-service”,“z”:“4056fc4f.0baa64”,“name”:“Set Presence Not Home”,“server”:“8ac3cd7f.58d3e”,“service_domain”:“device_tracker”,“service”:“see”,“data”:"{“dev_id”:“brad_bayesian”,“location_name”:“not_home”}",“x”:1520.3333282470703,“y”:335.99999380111694,“wires”:[]},{“id”:“afb02bc5.351e68”,“type”:“comment”,“z”:“4056fc4f.0baa64”,“name”:“Convert Bayesian Sensor into Device Tracker”,“info”:"",“x”:1015.0000381469727,“y”:252.00008296966553,“wires”:[]},{“id”:“a86ac3f0.00c67”,“type”:“inject”,“z”:“4056fc4f.0baa64”,“name”:"",“topic”:"",“payload”:"",“payloadType”:“date”,“repeat”:“10”,“crontab”:"",“once”:false,“x”:942.3333129882812,“y”:300.6665403842926,“wires”:[[“d43007ca.720b78”]]},{“id”:“d43007ca.720b78”,“type”:“api-current-state”,“z”:“4056fc4f.0baa64”,“name”:“Bayesian Presence”,“server”:“8ac3cd7f.58d3e”,“halt_if”:"",“entity_id”:“binary_sensor.bayesian_presence”,“x”:1142.3333892822266,“y”:300.66639733314514,“wires”:[[“763070f9.0c571”]]},{“id”:“8ac3cd7f.58d3e”,“type”:“server”,“z”:"",“name”:“Home Assistant”,“url”:“http://HASSIP:8123”,“pass”:“XXX”}]

Then I finally get my normal icon but its based on all my sensors from my bayesin setup
victoria
That is based on
victoria_2

SO IS THIS PERFECT? NO! but it’s getting to a point where its better than anything I had before :slight_smile:

UPDATE: I got the Home detection to be within seconds and no false positives!
The leaving home is now taking 7 min before registering but its stable, so I think I have to live with that

Cheers
Casperse

4 Likes