Bayesian sleep sensor

I was setting up this bayesian sleep sensor based on what I had read in a couple forums and the sensor will trigger to on. But it is not turning off. Any ideas what I might be missing?

binary_sensor:
  - platform: bayesian
    prior: 0.5
    name: Sleeping
    probability_threshold: 0.85
    observations:
      - entity_id: 'device_tracker.pixel_5'
        prob_given_true: 0.99
        prob_given_false: 0.01
        platform: state
        to_state: 'Home'
      - entity_id: 'device_tracker.iphone'
        prob_given_true: 0.99
        prob_given_false: 0.01
        platform: state
        to_state: 'Home'
      - entity_id: 'sensor.sun'
        prob_given_true: 0.9
        prob_given_false: 0.2
        platform: state
        to_state: below_horizon
      - entity_id: light.master_bedroom_lights
        prob_given_true: 0.99
        prob_given_false: 0.01
        platform: state
        to_state: 'off'
      - entity_id: light.master_bathroom_lights
        prob_given_true: 0.99
        prob_given_false: 0.01
        platform: state
        to_state: 'off'
      - entity_id: media_player.master_bedroom_tv
        prob_given_true: 0.99
        prob_given_false: 0.4
        platform: state
        to_state: 'off'
      - entity_id: media_player.master_bedroom_speaker
        prob_given_true: 0.99
        prob_given_false: 0.4
        platform: state
        to_state: playing
      - entity_id: sensor.iphone_battery_state
        prob_given_true: 0.99
        prob_given_false: 0.4
        platform: state
        to_state: Charging
      - entity_id: binary_sensor.pixel_5_is_charging
        prob_given_true: 0.99
        prob_given_false: 0.4
        platform: state
        to_state: 'on'

I’m guessing it’s the obvious: the probability is never going below the threshold. Have you checked the current probability in Developer ToolsStates?

This is my first time hearing about this sensor, and I’m not gonna do the math on the probabilities, so this is just conjecture, but my guess is that your prob_given_* values are too confident. The examples in the docs are much less confident and the threshold is higher.

Just to chime in - I use bayesian for presence, just as an experiment and I do not have the probablilities set that high.

Seeing you owning iPhone - don’t you want to use focus modes? This is how I “declare” my status as “in bed” and base some automations on this. So far it was very accurate. Anytime I go to focus mode or out of focus mode it is properly reported by Home Assistant.