Skip to content

Event-driven programmatic Home Assistant configuration based on Python, leveraging declarative data structures.

Notifications You must be signed in to change notification settings

stevius10/HAConfig-as-PyCode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

378 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HAConfig-as-PyCode

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.

Desktop


Implementation

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.

Main Home Automation

  • auto_control.py: Manages control behavior for entities based on state triggers, utilizing the ENTITIES_CONTROL data structure with multi-condition handling.
  • auto_entities.py: Automates entity state management, including default states and timeout handling, using the ENTITIES_AUTO data structure with fallback mechanisms.
  • auto_motion.py: Implements motion sensor-based automations, mapping motion sensors to actions through the ENTITIES_MOTION data structure with adaptive lighting.
  • auto_notify.py: Manages external communication via notifications, leveraging the DATA_DEVICES structure from data.py for mobile push notifications and automation shortcuts.
  • auto_presence.py: Handles presence detection and actions based on weighted indicators and exclusions in the ENTITIES_PRESENCE data structure.

Home Automation Capabilities

  • 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 the DATA_DEVICES structure for managing notification targets.
  • ha_off.py: Implements functionality to turn off various entities.

Services

  • air_control.py: Controls air-based functionality.
  • scrape_housing.py: Scrapes housing offers from various Berlin housing providers, processes data, and sends notifications using the DATA_SCRAPE_HOUSING_PROVIDERS structure. Integrates with auto_notify.py for push notifications and mobile shortcuts via ha_utils.py.
  • subprocesses.py: Manages and executes scheduled subprocesses and commands from data.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.

Modules

  • 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.

Mobile

About

Event-driven programmatic Home Assistant configuration based on Python, leveraging declarative data structures.

Topics

Resources

Stars

Watchers

Forks

Languages