Area Occupancy Probability Calculation Explained¶
This document gives a high level overview of how the area_occupancy
integration calculates occupancy probability and manages learned data.
Core Concepts¶
- Occupancy Probability: Final output value (0.0–1.0) indicating the likelihood that the area is currently occupied.
- Priors: Historical probabilities learned from the primary occupancy sensor and other configured entities.
- Likelihoods: For each entity, probabilities
P(Active | Occupied)
andP(Active | Not Occupied)
learned from history. - Weights: User-configured values (0.0–1.0) assigned per sensor type to influence their contribution.
- Decay: Exponential reduction in probability when no fresh evidence is present.
- Threshold: Probability level at which the binary occupancy sensor turns
on
.
Data Flow and Components¶
- AreaOccupancyCoordinator (
coordinator.py
): Central orchestrator that tracks entity states, schedules updates, handles decay and stores configuration. - EntityManager (
data/entity.py
): Creates and maintainsEntity
objects with evidence, likelihoods and decay data. - Prior (
data/prior.py
): Handles learning priors and likelihoods from historical recorder data and exposes time-based priors. - Bayesian Utilities (
utils.py
): Providesbayesian_probability
and helper functions for log-space probability calculations. - Database (
db.py
): Stores historical state intervals used for learning. - Services (
service.py
): Exposes services such asrun_analysis
andget_area_status
.
Processing Steps¶
- Initialization: Coordinator loads configuration, sets up entities and loads any stored priors from the database.
- State Updates: When a monitored entity changes state, the coordinator updates the corresponding
Entity
object and triggers a probability recalculation. - Probability Calculation:
bayesian_probability
combines entity evidence with the area and time priors in log space, applying the configured weights. - Decay Handling: If probability decreases, entity decay objects gradually reduce their influence until new evidence appears.
- Learning Priors: Periodically or via
run_analysis
, thePrior
class analyses recorder history to update priors and likelihoods which are stored in the database. - Outputs: The coordinator updates Home Assistant entities (probability, status, priors, evidence, decay, threshold) with the latest values.
This architecture allows the integration to react quickly to new sensor data while continuously refining its understanding of each entity's reliability over time.