HomeKit as a Presence Sensor

FYI - you can also add:

device_class: presence

to the bayesian sensors to set them for presence; that way you don’t need the template sensors doing the same thing.

This does not go true unless I have two other sensors as true. I dont remember the exact probability percentage, but HomeKit OR ASUS being true while the others were false gave me a probability less than .9 so the state was false

Good deal. Makes sense. I did have it as a presence sensor for a while. You’re right about not needing the template though. I guess I just need one of the other. I actually don’t really use the template either. For Automations I just use to ON, or to Off. Having the Bayesian as a presence, really did nothing special for me. Either from Home to Not_home or On to Off both worked the same.

You just don’t have to set the icon to the house; it is by default :wink:

Odd, I have exact same and if any one of the 3 on the overall bayesian goes on…

If two out of three are not true, but one is, and it’s true value is .9, but the others have a false value of X. The combined probability should be less than .9, so false. is your prior and your probabilty threshold the same? I used this notebook viewer

to plug in various numbers and examples to figure it out. Not sure I could figure it out again, haha. Was pretty complex to get set up, at least it was the 1st time I did it

I am identical to you except the input names! I believe the prob_given_false is also added so if one sensor is true; it is 0.9 and then the two false is 0.2+0.4 so you get a 1.0 probability (can’t be over 1).

This is what I see with testing; often a 1.0 probability with only one input on.

- platform: bayesian
  prior: 0.6
  name: 'Johns Presence'
  device_class: presence
  probability_threshold: 0.9
  observations:
   - entity_id: 'input_boolean.john_home'
     prob_given_true: 0.9
     prob_given_false: 0.2
     platform: 'state'
     to_state: 'on'
   - entity_id: 'device_tracker.johns_iphone'
     prob_given_true: 0.9
     prob_given_false: 0.4
     platform: 'state'
     to_state: 'home'
   - entity_id: 'device_tracker.johns_wifi'
     prob_given_true: 0.9
     prob_given_false: 0.2
     platform: 'state'
     to_state: 'home'

- platform: bayesian
  prior: 0.6
  name: 'Kims Presence'
  device_class: presence
  probability_threshold: 0.9
  observations:
   - entity_id: 'input_boolean.kim_home'
     prob_given_true: 0.9
     prob_given_false: 0.2
     platform: 'state'
     to_state: 'on'
   - entity_id: 'device_tracker.kims_iphone'
     prob_given_true: 0.9
     prob_given_false: 0.4
     platform: 'state'
     to_state: 'home'
   - entity_id: 'device_tracker.kims_wifi'
     prob_given_true: 0.9
     prob_given_false: 0.2
     platform: 'state'
     to_state: 'home'

Here’s a couple screen shots of how mine acts

The top presence is HA, then router, then HK, then lastly is the Bayesian Sensor
.

Could you send a screen shot of the bayesian card for each so I can see the probabilities listed? I get very different behavior then you; so that may help debug.

I only have one Bayesian card. It is set up exactly as listed above. Not sure what you’re asking me to send.

If you click on the bayesian sensor on the screenshot you posted above does it pop open a card that shows the probabilities?

Thanks - perfect! Can you do the same for 2 off, 1 on combination? That probability field is what I’m interested in for this combination. Or just post the # it reports; screen shot not required.

In my case it’s still 0.99

This is just with the HomeKit Switch On which uses these probabilities

   - entity_id: 'input_boolean.me_present'  #HK switch
     prob_given_true: 0.9
     prob_given_false: 0.2
     platform: 'state'
     to_state: 'on'

If you take the time to go into the Jupyter Notebook Viewer for the senor that was posted in the link I posted above (after a bit of playing around to figure out how that works), I was able to plug in probabilities for my sensors and tweak until I got it to work. I did not and probably still dont 100% understand the sensor, but its not just True - false - false, etc. If you have one true and two false items it cannot be more than the one true.

As in it’s not possible mathematically to have a .99 with only one true. Again, I’ll say I’m definitely not the expert on this. So maybe its possible if the false values are 0 for the other sensors??

Thanks. Will play around some more.

My assumption is the prob_given_false contributions are whats pushing it to 0.99 – which is the max.

Yeah, thats how I used to think it works as well, but its not. It’s actually a quite complex (at least to me) statitical math formula. Why don’t you post your Bayesian yaml? If both are configured exactly the same, we should get the same results.

I will say that I spent a few hours using the notebook, plugging in numbers to try to grasp how it is really working behind the scenes, and Mine is working as I expected it to work based on the math.

Is it possible to use homekit as presence detection with iphones and raspeberry pi (home assistant installed on it) i don’t have any apple tv (i have got an iPad instead)

You can use an ipad as well. Of course have to make sure it’s always charged. The process should be exactly the same.

Using it for 2 days, works very well, thanks!