There’s an example of using the baysian sensor here:
This is essentially what I do, but using Node-Red and MQTT to do it.
I have an MQTT switch, and a topic for each family member as home/not home state. Node-red handles all the automation of everything so basically, when both the owntracks (using zanzito’s owntracks method), and the wifi are ‘not home’, and the switch is ‘home’, then change switch to ‘not home’, and vice versa.
When someone comes home, it just has to match either condition to trigger home state, but in order for us to be counted as ‘not home’ both conditions must be met.
FWIW, I only use Life360. Two family members (including myself) have it on Android, and one has it on iOS. It works great and is not a battery drain. Although it’s not perfect (nothing seems to be), we find it very reliable. I’ve been using it for years, including with SmartThings before I recently switched to HA. (It’s even more reliable and prompt with HA than it was with ST.)
I do essentially the same thing as flamingm0e. I use GPSLogger, Unifi, and Bluetooth for trackers. Each person has their own group (group.tracker_name) which includes all 3 device trackers for their device. As stated, all 3 must be away for the group to be away. Any 1 of them as home will mark the group as home. This has been extremely reliable for me so far. I also use a master group (group.tracker_family) for some automations which includes all of the relevant device trackers (I could just use the individual groups to simplify it if I wanted)
I highly recommend that you do not combine trackers in the known devices file. Let each tracker type have its own entry.
Have not messed with the bayesian sensor. Seems like a lot of guess work, but others say its reliable.
Thanks everyone for all your valuable input!
@gregg098 eegg098 I believe I saw a post from you about the weight for each tracking device?
I would thing that this would be even better solution?
I only added the MAC address to the iPhones known_devices information so it wouldn’t create a second one from the Unfi tracker so ending up having multiple icons above for the same iphone/user.
(I like the user icon at the top stating: Away or Home)
But looking at your example it looks like you have two different ID’s “gregg_phone” and “greggphone” ID for the iPhone app and the other ID as the wifi host name correct? My naming is the same and that might cause more problems than helping?
I just enabled Ping and made sure each phone have a fixed local IP…hope that helps getting to many false positives.
Reading so many posts it seems that having an electronic door look with a unique code or providing special key chains that can unlock the door identifying the user is best option
I use the SNMP sensor to get the currently active MAC addresses off my wifi router, and couple that with owntracks, I get 99.95% accuracy from this method.
I have never used the Bayesian sensor so I don’t know what weights to use in each category. It is probably a good solution, once tuned, but maybe not the best route now until you understand what the variables do.
Not sure which examples you are looking at but chances are, I have tweaked it since then. To break my usecase down a little more, my group (group.tracker_gregg) would include:
- device_tracker.gregg_phone - This is from GPS Logger. No MAC address is included
- device_tracker.gregg_phone_BT - This is using the Bluetooth tracker (not BLE). It includes my BT MAC address as BT_XX:XX:…
- device_tracker.gregg_phone_wifi - This is from my Unifi controller and includes my phone’s WiFi MAC address
So what I think you are saying is that you combined two trackers by including the MAC address from one into another that didn’t need it. In my use case, I think you are saying, for example, I would have the wifi mac address in the GPS logger tracker which would combine them as one. So the problem with doing this is that Home Assistant will mark that tracker as home or away based on the last event it has seen, WiFi or GPS Logger. So lets say I’m in my backyard and fall out of WiFi range. Even though I’m still home, Home Assistant will see my WiFi presence as being marked away and now that entire tracker is away unless GPS Logger sends an update to say I’m home again. This usually doesn’t happen though as most GPS trackers have radius where it won’t report unless you move x distance from your last location. So if you keep 3 independent trackers, group them, and understand the group rules (1 home = group home, all away = group away), then you can work your automations around that basis and keep the incorrect reporting to a minimum.
Hopefully that makes sense.
That’s a very specific accuracy!
LOL exaggeration but close enough
I do the same as others here only I use a template sensor with my most likely (weighted) trackers at the top.
If my group of ble trackers say I’m home then that the likelyhood of me being home is very high and this condition triggers my home condition.
The sensor will remain in the home condition until Bluetooth group is not home and it will take the owntracks zones as next precedence and the likely hood that I’m home and in my zones is less likely being in 2 places at once (not impossible for me to leave phone at work however).
Lastly being away on all trackers is the close of the template condition loop.
You could essentially do the same with a Bayesian sensor adding weighting for the most likely scenarios aka
All trackers at home 1.0
2 of 3 trackers 0.9
Bluetooth home 0.9 as its unlikely that this says you’re home when you’re not
own tracks home only 0.6 as you may have turned off Bluetooth on your phone
etc etc
I find my template to be 100% accurate provided I don’t leave my phone anywhere so thats where a Bayesian can help by taking other factors into account aka workday sensor says its a workday its past 7pm but tracking says I’m still at work likelihood of this is 0.3 or likelihood I left my phone at work is 0.7 say I’m home.
To combat things like this I use a second tracker on my car keys the likelihood of me not having either of these things and being at home is very low.
How do you get a “device_tracker.gregg_phone_wifi” on your Unifi?
Have you created a alias name that Home Assistant sees? or have you named your phone this way in order to get a special wifi ID that you can stack against the other trackers?
Would you mind sharing your updated configuration?
Again thanks to all of you for sharing your valuable input so many options! so hard to get working! LOL
@firstof9 SNMP 99,5% I have to read up on that! would it work on Unifi - impact to network traffic?
SNMP is low priority QoS and uses trivial amounts of data, so almost no impact to traffic. I am not sure if Unifi has SNMP available, I use Tomato firmware on my router. I can post you my SNMP config for this tracking when I get home.
@firstof9
Thanks! - I found this on Unifi
Yes, you would use SNMP to query the APs themselves and not the controller.
You enable SNMP on the APs via the controller configuration just like any other AP setting.
I have 2 AP’s in the house and a third covering the garden and most of the street ()
So I am not sure if this would be doable, I would have to ask all 3 and not one controller
For decent tracking it’s not really an issue, the traffic generated is minimal.
You can directly edit the known_devices.yaml file and update the device tracker names for any tracker with a MAC address (since the MAC is what is being used to update that entity). In other cases, such as GPS Logger in my case (probably OwnTracks too), there is no MAC so the name comes directly from the app. I was able to modify the logging string that GPS Logger spits out to get this entry.
I dont have much of a configuration to really share. It really is as simple as having a group with 3 entities to cover each tracker for each person. Then use the group state to trigger automations.
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.
Hi All
Just a update to everyone @gregg098 @nickrout @firstof9 @jimpower @oakbrad my effort to combining all the trackers.
- Unifi setup
- Unifi ping (Enable ping on USG! link)
- NMAP
- Fixed IP’s on all iPhones
- Installed HA app and setup GPS
- 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:
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
That is based on
SO IS THIS PERFECT? NO! but it’s getting to a point where its better than anything I had before
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