$ show jseidl/magic-areas
Magic Areas is a Home Assistant custom integration that turns HA's area registry into an occupancy-aware automation layer. In production it listens to entity states across configured areas, computes presence from motion sensors, device trackers, and occupancy binary sensors, manages clear timers and secondary states (dark, sleep, extended), and publishes derived entities: area presence binary sensors, smart light/fan/cover/media groups, aggregate sensors, and feature-override switches. It is event-driven and tightly coupled to Home Assistant internals: the area/entity registries, dispatcher, event bus, async timers, and group entities.
The LLM identified 5 files worth highlighting for reuse:
Implements a single-active async timer with token-based callback validation, preventing stale timer callbacks from corrupting state when a timer is restarted. This is a self-contained concurrency pattern reusable in any async Python project.
MagicEntity provides a standardized Home Assistant entity base: generated unique IDs, device info, translation keys, and state-restoration behavior. It demonstrates a clean, reusable entity foundation for HA custom components.
Implements the Wasp-in-a-Box occupancy heuristic, combining motion and door sensors to avoid premature area clearing. The logic is isolated and adaptable to any presence-detection system that needs a false-vacancy guard.
Base classes for feature-control switches that remember and restore prior states and support automatic timeout-based reset. This is a reusable pattern for home-automation override toggles.
ConfigBase provides reusable selector builders and a generic do_feature_config step handler, allowing each feature's configuration step to be declared with schemas, selectors, and validators while minimizing duplicated flow logic. It demonstrates an extensible HA options-flow pattern.