I have a pretty in-depth bayesian setup, I also use the history_stats platform to calculate the probabilities of things actually happening based on the numerous sensors i have around the house.
This would be calculated upon started up and perhaps have a service call to re-calculate as I understand that there may be a performance impact with constant recalculation of a lot of these definitions
thx man … Im going to grab interested parts to my setup =) … Just recently finished my my hardware setup (wall panel and HA server) … but I still need improve automations and UI parts
Hey, I came to the forum to post this suggestion but you’ve already written it out better than I would have. Nice idea about using it to dynamically track priors BTW.
I don’t think this would need to be triggered as a one off: looking through the current Bayesian sensor code (core/binary_sensor.py at 8bf6aba1cf44ee841de063755c935ea78040f399 · home-assistant/core · GitHub) I think the additional templates could be registered just like the current templates are. It won’t slot straight in, but I might be able to give it a try if there’s interest in this change.
Hey Charles, if you have the know how to implement I would be appricative. I haven’t found the time to figure it out myself yet. Naturally happy to help in anyway testing etc
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
device_class: occupancy
probability_threshold: 0.8
observations:
- platform: "state"
entity_id: "group.area_test_motion"
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
to_state: "on"
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?”
I have managed to achieve this to an extent by generating the yaml in appdaemon periodically and setting the value for prior based on the last 7 days activity weighted to consider the same day last week to be a more pertinent number for prior
Currently I use altering an input number (for threshold) as a trigger to tell appdaemon to regenerate
It’s improved Bayes accuracy, however, as the Bayes sensor has recently had some love from the developers, I would love to see that little extra push to have both prior and threshold be fed from another sensor/input
Is there a feature request to add templates for to hard coded variables in Bayesian config. I would vote for this if it’s already been suggest or can submit it if it has not yet been requested. Having the ability to build a test platform and modify values would greatly demystify a really useful tool. A while back there was a post that had an Excel spreadsheet where you could plug in variables and test against T/F conditions to see how the sensor would react, but that spreadsheet currently does not report correctly. Not sure if something changed in the Bayes Sensor or via ongoing updates. That was my motivation to build a test page and dynamically modify true/false/prior values to see updated outcomes. FWIW I can get those attribute values via code and put them into an input_number or variable, but have not been able to UPDATE those values back into the Bayes sensor.
Interestingly, one can also modify the attributes of a Bayes sensor in the Developer Tools States tab. However, the updated values are not applied to the calculation. The only way I have found is to update the YAML code and refresh the Bayesian Sensor, but this is way less efficient.
Has there been any progress in adding templating to Bayesian sensors. This would make tweaking a Bayes sensor much easier for situations where the item of interest may change often, such as Is it raining/windy/cold or for testing purposes.
Yes, I know there is a spreadsheet available, however I’ve noticed that when configured EXACTLY the same, the spreadsheet and the HA sensor give different answers, so for me, the spreadsheet is not a viable solution for testing.
Lastly, I also noticed that the PRIOR value is not obtainable for use in a template or automation. All other values are, except for PRIOR.