Bayesian binary sensor does not seem to work

I was super excited to see the Bayesian binary sensor by @jlmcgehee21 and implemented it right away for presence detection. Here’s the config:

  - platform: 'bayesian'
    prior: 0.25
    name: 'Rashmi Home'
    probability_threshold: 0.95
    observations:
      - entity_id: 'device_tracker.pi_rashmiphone'
        prob_given_true: 0.8
        prob_given_false: 0.6
        platform: 'state'
        to_state: 'home'
      - entity_id: 'device_tracker.rashmiappiphone'
        prob_given_true: 0.99
        prob_given_false: 0.99
        platform: 'state'
        to_state: 'home'
      - entity_id: 'device_tracker.rashmisiphone'
        prob_given_true: 0.9
        prob_given_false: 0.6
        platform: 'state'
        to_state: 'home'
      - entity_id: 'device_tracker.sonu_sonu'
        prob_given_true: 0.99
        prob_given_false: 0.99
        platform: 'state'
        to_state: 'home'

However, despite all the trackers being home, I am not seeing the right value for binary_sensor.rashmi_home. The probability is only 0.4

image

Not sure what am I missing.

Posted a response here: https://github.com/home-assistant/home-assistant/issues/9347

2 Likes

Just to complete the loop, here is the updated sensor

  - platform: 'bayesian'
    prior: 0.75
    name: 'Rashmi Home'
    probability_threshold: 0.95
    observations:
      - entity_id: 'device_tracker.pi_rashmiphone'
        prob_given_true: 0.8
        prob_given_false: 0.2
        platform: 'state'
        to_state: 'home'
      - entity_id: 'device_tracker.rashmiappiphone'
        prob_given_true: 0.99
        prob_given_false: 0.10
        platform: 'state'
        to_state: 'home'
      - entity_id: 'device_tracker.rashmisiphone'
        prob_given_true: 0.95
        prob_given_false: 0.4
        platform: 'state'
        to_state: 'home'
      - entity_id: 'device_tracker.sonu_sonu'
        prob_given_true: 0.99
        prob_given_false: 0.1
        platform: 'state'
        to_state: 'home'
2 Likes

It works also here, thank you for your contribution.