Actually having another think about it the ideal implementation wouldn’t require the history stats at all.
Instead have a config option for the entity you wish to base you probability on. Then the integration would invoke the history stats code to get the probability, saves a lot of manually creating a bunch of history stats sensors and adding to the database. So it would be more like:
- platform: bayesian
name: Area - Test Occupied
prior: 0.8 #<- Optional config if you wanted to configure it manually and prevent breaking changes
prior_entity: binary_sensor.test_occupied #<- the entity provided here will have its stats calculated from the database on scan interval and automatically provide the prior value (no template actually needed)
scan_interval: 7 #<- In day perhaps? how often to update the prior
- platform: "state"
prob_given_true: 0.4 #<- Optional manual config remains to prevent breaking changes
prob_given_true_entity: "group.area_test_motion" #<- Works similar to the sensor prior providing a calculated probability given history of the sensor state based on history_days
history_days: 30 #<- Number of days in the past to now over which the total % of time that the "to_state" was met
I hope this makes sense. All the logic is in my head, so happy to figure out the implementation with people.
My goal with this is there is little to no maintenance once it’s set up. Home Assistant just knows, and always does. Massively simplifies automations, don’t need a million conditions, just “Is someone there?”