HAConfig-as-PyCode is an event-driven, programmatic Home Assistant configuration project leveraging Python for enhanced reusability, encapsulation, and modular expandability. This project provides an alternative automation approach, focusing on developers compared to Home Assistant's default YAML-based configuration.
HAConfig-as-PyCode is built on an event-driven architecture, integrating Python via PyScript and Home Assistant's built-in automation capabilities. It combines declarative data structures for desired state configuration with imperative logic to process these data structures in an event-driven manner, leveraging an MQTT broker.
auto_control.py: Manages control behavior for entities based on state triggers, utilizing theENTITIES_CONTROLdata structure with multi-condition handling.auto_entities.py: Automates entity state management, including default states and timeout handling, using theENTITIES_AUTOdata structure with fallback mechanisms.auto_motion.py: Implements motion sensor-based automations, mapping motion sensors to actions through theENTITIES_MOTIONdata structure with adaptive lighting.auto_notify.py: Manages external communication via notifications, leveraging theDATA_DEVICESstructure fromdata.pyfor mobile push notifications and automation shortcuts.auto_presence.py: Handles presence detection and actions based on weighted indicators and exclusions in theENTITIES_PRESENCEdata structure.
ha_helper.py: Provides comprehensive helper functions for interacting with Home Assistant resources like system logging and generic utility operations.ha_system.py: Manages system-related setup, configuration tasks, and environmental settings, handling runtime initialization and integration routines.ha_utils.py: Includes utility functions for mobile notifications and event shortcuts, using theDATA_DEVICESstructure for managing notification targets.ha_off.py: Implements functionality to turn off various entities.
air_control.py: Controls air-based functionality.scrape_housing.py: Scrapes housing offers from various Berlin housing providers, processes data, and sends notifications using theDATA_SCRAPE_HOUSING_PROVIDERSstructure. Integrates withauto_notify.pyfor push notifications and mobile shortcuts viaha_utils.py.subprocesses.py: Manages and executes scheduled subprocesses and commands fromdata.py:- File Backup: Scheduled backups of Home Assistant configuration files.
- Git Sync: Automatic synchronization of the configuration to the Git repository.
- Compile: Compiles project files, listing the structure and contents at specified times using
time_trigger.
constants.py: Centralizes configuration settings, entity definitions, expressions, mappings, and settings by importing them from sub-modules:config.py: General configuration settings and structure.data.py: Specific input data for automations.entities.py: Default state for entities and conditions for behavior.expressions.py: Expressions for various automation scenarios.mappings.py: Naming and mappings.settings.py: Specific configuration values for independent service logic.
generic.py: Generic classes like various enumerations and custom exceptions for error handling.utils.py: Central functions for project-wide logging, log rotation, expression generation, and diagnostics.

