Bayesian sensor doesn’t appear to collect triggers as expected.
I’d post the Bayesian sensor Yaml if I could figure out how to, in the app with file editor or studio code server. Copy and paste in there is lost to me in the app on Android.
Not sure what you mean. It looks as if you’re trying to detect whether somebody is probably home. Here’s mine if it’s any help. (Post code as preformatted text (</> in the cogwheel menu).
binary_sensor:
# ==============================================================================
# Bayesian ---------------------------------------------------------------------
# ==============================================================================
# ------------------------------------------------------------------------------
# Probably occupied
# ------------------------------------------------------------------------------
# Calculates the probability that the house is occupied, based on guide at
# https://community.home-assistant.io/t/how-bayes-sensors-work-from-a-statistics-professor-with-working-google-sheets/143177
- platform: "bayesian"
name: "Probably occupied"
# Allows name, icon and area to be customized via the UI
# ID generated on https://www.uuidgenerator.net/
unique_id: "75b1232e-5269-4451-88cb-4bbf1d8b1442"
# Estimate of probability before learning about any event
# Normally occupied for 20 hours a day (averaged over week)
prior: 0.83
# 90% threshold to account for forgetting phone etc.
probability_threshold: 0.90
# Observations =================================================================
# The probability of the observation (the sensor state in question)
# given the event (the assumed state of the Bayesian binary_sensor).
observations:
# TV on ------------------------------------------------------------------------
# Binary sensor from template
- platform: "state"
entity_id: "binary_sensor.tv_on"
to_state: "on"
# TV only on when house is occupied - 5 hours a day
prob_given_true: 0.2
prob_given_false: 0.5
# Xbox on ------------------------------------------------------------------------
- platform: "state"
entity_id: "binary_sensor.xbox_on"
to_state: "on"
# Xbox sometimes on when house is unoccupied - but av 1 hour a day when occupied
prob_given_true: 0.05
prob_given_false: 0.075
# Speakers on ------------------------------------------------------------------
- platform: "state"
entity_id: "binary_sensor.speakers_on"
to_state: "on"
# Speakers only on when house is occupied - 2 hours a day
prob_given_true: 0.1
prob_given_false: 0.001
# Movement in house (sensor stays on for 5 min) -------------------------------
# Binary sensor from template
- platform: "state"
entity_id: "binary_sensor.movement"
to_state: "on"
# No movement when house is occupied 6 hours a day (asleep)
prob_given_true: 0.7
prob_given_false: 0.125
# Probably in bed --------------------------------------------------------------
# Binary sensor from template
- platform: "state"
entity_id: "binary_sensor.in_bed"
to_state: "on"
# Sleep elsewhere 2% of time
prob_given_true: 0.4
prob_given_false: 0.01
# Phone is charging ------------------------------------------------------------
- platform: "state"
entity_id: binary_sensor.nokia_g21_is_charging
to_state: "on"
# Phone usually charged overnight when home - for 8 hours a day
prob_given_true: 0.4
prob_given_false: 0.0625
# Phone is on wi-fi ------------------------------------------------------------
- platform: "state"
entity_id: sensor.nokia_g21_wifi_connection
to_state: "Malachi_5"
# Phone on wi-fi most of day
prob_given_true: 0.95
prob_given_false: 0.01
# Alarm is armed ---------------------------------------------------------------
- platform: "state"
entity_id: alarm_control_panel.alarmo
to_state: "armed_away"
# Alarm usually set when out (4 hours a day)
prob_given_true: 0.01
prob_given_false: 0.99
# Keys home (Bluetooth LE) -----------------------------------------------------
- platform: "state"
entity_id: device_tracker.bermuda_de_1d_c9_73_61_d3_bermuda_tracker
to_state: "home"
# 100% of time when home, never when out
prob_given_true: 0.99
prob_given_false: 0.01
# Phone home (Bluetooth LE) ----------------------------------------------------
- platform: "state"
entity_id: device_tracker.419c3768b97d446c9a2c233b2712a79e_100_40004_bermuda_tracker
to_state: "home"
# 100% of time when home, never when out, but sometimes forget phone
prob_given_true: 0.95
prob_given_false: 0.01
# Watch home (Bluetooth LE) ----------------------------------------------------
- platform: "state"
entity_id: device_tracker.1b47a85da46d47e5b9ae9ddf4fa74072_100_40004_bermuda_tracker
to_state: "home"
# Watch home/away less accurate than keys/phone
prob_given_true: 0.87
prob_given_false: 0.01
# Watch on wi-fi ---------------------------------------------------------------
- platform: "state"
entity_id: sensor.ticwatch_e2_0520_wifi_connection
to_state: "Malachi_5"
# Watch rarely on wi-fi
prob_given_true: 0.19
prob_given_false: 0.01
# Watch charging ---------------------------------------------------------------
- platform: "state"
entity_id: binary_sensor.ticwatch_e2_0520_is_charging
to_state: "on"
# Watch charges two hours a day
prob_given_true: 0.10
prob_given_false: 0.01
yaml below for sensor in packages folder. nothing happens, Bayesian sensor doesn’t trigger. all motion sensor do trigger and door sensors. lost and perplexed.
Well regardless of the documentation, with lower numbers in the sensors, meaning prob true similar to some of yours, I’m getting triggers now, just have to massage.
I can’t tell you how much I appreciate your response, it helped a lot.
Understanding the numbers was the most frustrating. Both Chatgpt and Grok got me started with configuration, but Ai spits out too much information and speculates quite a bit.
I wanted to share what I did and seems to work for my scenario since you helped me. The way the motion sensors seem to work for me is if some one is home, high threshold, if I trip one it may Set Is Someone Home. Logs show it definitely sets on two and stays on a few minutes. Now I’ll work on doors summer and winter usage. (Grok helped lol)Preformatted text
binary_sensor:
- platform: bayesian
name: "Is Someone Home"
prior: 0.9
probability_threshold: 0.91
observations:
- platform: template
value_template: >-
{{ is_state('binary_sensor.aqara_back_door_opening', 'on') or
(states('binary_sensor.aqara_back_door_opening') != 'unavailable' and
states('binary_sensor.aqara_back_door_opening') != 'unknown' and
states.binary_sensor.aqara_back_door_opening.last_changed is not none and
as_timestamp(now()) - as_timestamp(states.binary_sensor.aqara_back_door_opening.last_changed) < 60) }}
prob_given_true: 0.6
prob_given_false: 0.05
- platform: template
value_template: >-
{{ is_state('binary_sensor.aqara_front_door_opening', 'on') or
(states('binary_sensor.aqara_front_door_opening') != 'unavailable' and
states('binary_sensor.aqara_front_door_opening') != 'unknown' and
states.binary_sensor.aqara_front_door_opening.last_changed is not none and
as_timestamp(now()) - as_timestamp(states.binary_sensor.aqara_front_door_opening.last_changed) < 60) }}
prob_given_true: 0.5
prob_given_false: 0.05
- platform: template
value_template: >-
{{ is_state('binary_sensor.aqara_basement_inner_door_opening', 'on') or
(states('binary_sensor.aqara_basement_inner_door_opening') != 'unavailable' and
states('binary_sensor.aqara_basement_inner_door_opening') != 'unknown' and
states.binary_sensor.aqara_basement_inner_door_opening.last_changed is not none and
as_timestamp(now()) - as_timestamp(states.binary_sensor.aqara_basement_inner_door_opening.last_changed) < 60) }}
prob_given_true: 0.3
prob_given_false: 0.05
- platform: template
value_template: >-
{{ is_state('binary_sensor.aqara_inner_garage_door_opening', 'on') or
(states('binary_sensor.aqara_inner_garage_door_opening') != 'unavailable' and
states('binary_sensor.aqara_inner_garage_door_opening') != 'unknown' and
states.binary_sensor.aqara_inner_garage_door_opening.last_changed is not none and
as_timestamp(now()) - as_timestamp(states.binary_sensor.aqara_inner_garage_door_opening.last_changed) < 60) }}
prob_given_true: 0.8
prob_given_false: 0.05
- platform: template
value_template: >-
{{ is_state('binary_sensor.aqara_basement_outer_door_opening', 'on') or
(states('binary_sensor.aqara_basement_outer_door_opening') != 'unavailable' and
states('binary_sensor.aqara_basement_outer_door_opening') != 'unknown' and
states.binary_sensor.aqara_basement_outer_door_opening.last_changed is not none and
as_timestamp(now()) - as_timestamp(states.binary_sensor.aqara_basement_outer_door_opening.last_changed) < 60) }}
prob_given_true: 0.3
prob_given_false: 0.05
- platform: template
value_template: >-
{{ is_state('binary_sensor.aqara_outer_garage_door_opening', 'on') or
(states('binary_sensor.aqara_outer_garage_door_opening') != 'unavailable' and
states('binary_sensor.aqara_outer_garage_door_opening') != 'unknown' and
states.binary_sensor.aqara_outer_garage_door_opening.last_changed is not none and
as_timestamp(now()) - as_timestamp(states.binary_sensor.aqara_outer_garage_door_opening.last_changed) < 60) }}
prob_given_true: 0.2
prob_given_false: 0.05
- platform: template
value_template: >-
{{ is_state('binary_sensor.aqara_hallway_motion_motion', 'on') or
(states('binary_sensor.aqara_hallway_motion_motion') != 'unavailable' and
states('binary_sensor.aqara_hallway_motion_motion') != 'unknown' and
states.binary_sensor.aqara_hallway_motion_motion.last_changed is not none and
as_timestamp(now()) - as_timestamp(states.binary_sensor.aqara_hallway_motion_motion.last_changed) < 60) }}
prob_given_true: 0.8
prob_given_false: 0.05
- platform: template
value_template: >-
{{ is_state('binary_sensor.aqara_basement_motion_motion', 'on') or
(states('binary_sensor.aqara_basement_motion_motion') != 'unavailable' and
states('binary_sensor.aqara_basement_motion_motion') != 'unknown' and
states.binary_sensor.aqara_basement_motion_motion.last_changed is not none and
as_timestamp(now()) - as_timestamp(states.binary_sensor.aqara_basement_motion_motion.last_changed) < 30) }}
prob_given_true: 0.3
prob_given_false: 0.05
- platform: template
value_template: >-
{{ is_state('binary_sensor.bedroom_motion_sensor_motion', 'on') or
(states('binary_sensor.bedroom_motion_sensor_motion') != 'unavailable' and
states('binary_sensor.bedroom_motion_sensor_motion') != 'unknown' and
states.binary_sensor.bedroom_motion_sensor_motion.last_changed is not none and
as_timestamp(now()) - as_timestamp(states.binary_sensor.bedroom_motion_sensor_motion.last_changed) < 60) }}
prob_given_true: 0.8
prob_given_false: 0.05
- platform: template
value_template: >-
{{ is_state('binary_sensor.aqara_motion_computer_room_motion', 'on') or
(states('binary_sensor.aqara_motion_computer_room_motion') != 'unavailable' and
states('binary_sensor.aqara_motion_computer_room_motion') != 'unknown' and
states.binary_sensor.aqara_motion_computer_room_motion.last_changed is not none and
as_timestamp(now()) - as_timestamp(states.binary_sensor.aqara_motion_computer_room_motion.last_changed) < 60) }}
prob_given_true: 0.8
prob_given_false: 0.05
- platform: template
value_template: >-
{{ is_state('binary_sensor.aqara_kitchen_motion_motion', 'on') or
(states('binary_sensor.aqara_kitchen_motion_motion') != 'unavailable' and
states('binary_sensor.aqara_kitchen_motion_motion') != 'unknown' and
states.binary_sensor.aqara_kitchen_motion_motion.last_changed is not none and
as_timestamp(now()) - as_timestamp(states.binary_sensor.aqara_kitchen_motion_motion.last_changed) < 60) }}
prob_given_true: 0.8
prob_given_false: 0.05
- platform: template
value_template: >-
{{ is_state('binary_sensor.aqara_laundry_room_motion_motion', 'on') or
(states('binary_sensor.aqara_laundry_room_motion_motion') != 'unavailable' and
states('binary_sensor.aqara_laundry_room_motion_motion') != 'unknown' and
states.binary_sensor.aqara_laundry_room_motion_motion.last_changed is not none and
as_timestamp(now()) - as_timestamp(states.binary_sensor.aqara_laundry_room_motion_motion.last_changed) < 60) }}
prob_given_true: 0.8
prob_given_false: 0.05
- platform: template
value_template: >-
{{ is_state('binary_sensor.aqara_oil_room_motion_motion', 'on') or
(states('binary_sensor.aqara_oil_room_motion_motion') != 'unavailable' and
states('binary_sensor.aqara_oil_room_motion_motion') != 'unknown' and
states.binary_sensor.aqara_oil_room_motion_motion.last_changed is not none and
as_timestamp(now()) - as_timestamp(states.binary_sensor.aqara_oil_room_motion_motion.last_changed) < 30) }}
prob_given_true: 0.3
prob_given_false: 0.05
- platform: template
value_template: >-
{{ is_state('binary_sensor.aqara_living_room_motion_motion', 'on') or
(states('binary_sensor.aqara_living_room_motion_motion') != 'unavailable' and
states('binary_sensor.aqara_living_room_motion_motion') != 'unknown' and
states.binary_sensor.aqara_living_room_motion_motion.last_changed is not none and
as_timestamp(now()) - as_timestamp(states.binary_sensor.aqara_living_room_motion_motion.last_changed) < 60) }}
prob_given_true: 0.8
prob_given_false: 0.05
Well, the above doesn’t work. Simplifying adding one sensor at a time as in the yaml below, seems odd. Prob true ended up being like .00000000001 or something, one sensor, probability of .9 or .99 add a 2nd sensor probability drops to .47, worked for days and I’ve had it. Either they don’t work and two Ai don’t understand them, because I sure don’t.
Probability 0.9 means “almost certainly” and 0.00000000001 means “absolutely not going to happen”. I think you’re guessing!
I worked out mine by saying:
In a 24-hour period, for how many hours is the house occupied?
Out of the x hours when the house is occupied, how often is movement true?
Out of the x hours when the house is empty, how often is movement true?
You can get actual numbers from your HA history, but for me prob_given_true was 0.7 and prob_given_false was 0.125. (I’m retired and I sometimes go out leaving the dog behind.)
Have a look at the post I linked to - the google sheet he has created really works.