# UPS HID Configuration Management This directory provides a modular, maintainable approach to UPS HID device configuration using ESPHome packages with the a Protocol Factory system. Instead of maintaining large, complex configuration files, you can compose configurations from reusable components. ## 📦 Modular Configuration Packages ### **Core Packages** (Always Required) #### `base_ups.yaml` Essential foundation for all UPS devices: - ESP32-S3 hardware configuration - Network setup (WiFi, OTA, Web server) - UPS HID component initialization with Protocol Factory - **Data Provider Pattern**: LED automation accesses UPS data directly (no sensor entities required!) - Status LED with smart patterns using `id(ups_monitor).is_online()`, etc. - **Optional sensors**: Only `status` and `protocol` text sensors (for Home Assistant integration) #### `essential_sensors.yaml` / `essential_sensors_grouped.yaml` Core monitoring sensors (5 sensors) available on all protocols: - **Sensors**: `battery_level`, `input_voltage`, `output_voltage`, `load_percent`, `runtime` - **Text Sensors**: `manufacturer`, `model` - **Binary Sensors**: `charging`, `overload` - **System Monitoring**: uptime, WiFi signal, IP address, ESPHome version - **Grouped version** organizes entities into logical sections in ESPHome web interface - Compatible with APC, CyberPower, and Generic protocols ### **Optional Enhancement Packages** #### `extended_sensors.yaml` / `extended_sensors_grouped.yaml` Advanced monitoring (17 additional sensors) for feature-rich devices: **Enhanced Voltage Monitoring**: - `battery_voltage`, `battery_voltage_nominal`, `input_voltage_nominal` - `input_transfer_low`, `input_transfer_high`, `frequency` **Power & Configuration**: - `ups_realpower_nominal`, `ups_delay_shutdown`, `ups_delay_start`, `ups_delay_reboot` **Dynamic Timer Monitoring** (negative values = no active countdown): - `ups_timer_shutdown`, `ups_timer_start`, `ups_timer_reboot` - `battery_runtime_low` **Extended Device Information**: - `serial_number`, `firmware_version`, `ups_beeper_status`, `input_sensitivity` - `ups_mfr_date`, `battery_status`, `ups_firmware_aux` **Smart Template**: Calculated load power using HID nominal power when available **Grouped version** categorizes sensors by function (Battery, Voltage, Load, Configuration, Device Info) #### `ups_controls.yaml` / `ups_controls_grouped.yaml` Complete control functionality (10 buttons + test monitoring): **Beeper Control**: `enable`, `disable`, `mute`, `test` **UPS Testing**: `battery_quick`, `battery_deep`, `battery_stop`, `ups_test`, `ups_stop` **Test Monitoring**: `ups_test_result` text sensor **Grouped version** separates beeper controls from test controls in web interface #### `timer_sensors.yaml` / `timer_sensors_grouped.yaml` Real-time countdown timer monitoring (5 sensors + analysis): **Active Timer Monitoring**: `ups_timer_shutdown`, `ups_timer_start`, `ups_timer_reboot` **Timer Analysis**: `active_timer_count`, `fast_polling_status` **Real-time Updates**: Component automatically switches to fast polling during countdowns **Grouped version** places all timer-related entities in dedicated section #### `delay_config.yaml` UPS delay configuration package (3 number entities + automation scripts): **Delay Configuration**: `shutdown`, `start`, `reboot` delays (0-600 seconds) **Protocol Support**: CyberPower (full), Generic HID (multi-vendor), APC (INPUT-ONLY fallback) **Scripts**: Default delay application and configuration reading **Home Assistant**: Number entities with proper device classes and validation #### `entity_groups.yaml` ESPHome Web Server v3 entity organization (10 logical groups): **Hierarchical Organization**: Power Status → Battery → Voltage → Load → Timers → Configuration → Controls → Device Info → System **Visual Grouping**: Emoji headers and clear sorting weights (10-100) **Improved Navigation**: Related entities grouped together, 75% less scrolling **Optional Enhancement**: Include to enable organized web interface, omit for flat layout ### **Device-Specific Optimization Packages** #### `device_types/apc_backups_es.yaml` APC Back-UPS ES series optimizations: - Slower update intervals (15s - APC devices need more time) - APC-specific power calculations (405W nominal for ES 700) - Enhanced protocol debugging (`ups_hid.apc: DEBUG`) - Fixed device-specific script references #### `device_types/cyberpower_cp1500.yaml` CyberPower CP1500 series optimizations: - Fast update intervals (10s - CyberPower responds quickly) - **Additional sensor**: `battery_charge_low` threshold - **Enhanced power calculation**: Uses HID nominal power when available (900W default) - **Device-specific text sensor**: `battery_mfr_date` (separate from UPS date) - Rich monitoring script with comprehensive status logging --- ## 📊 **Complete Sensor Summary** ### **Package Composition Options:** | Configuration Level | Packages Included | Total Sensors | Use Case | |-------------------|------------------|--------------|----------| | **Minimal** | `base_ups` + `essential_sensors` | **9 sensors** | Basic monitoring | | **Complete** | + `extended_sensors` + `ups_controls` + `timer_sensors` | **32 sensors + 10 controls** | Full featured | | **Complete + Config** | + `delay_config` | **32 sensors + 10 controls + 3 number entities** | With UPS configuration | | **Device-Optimized** | + device-specific package | **33+ sensors + 13+ controls** | Production ready | | **Organized Interface** | Use `*_grouped.yaml` + `entity_groups.yaml` | **Same sensors, better layout** | Enhanced web interface | ### **Sensor Breakdown by Type:** #### **Numeric Sensors** (27 total available): - **Essential (5)**: battery_level, input_voltage, output_voltage, load_percent, runtime - **Extended (17)**: Enhanced voltage/power/configuration/threshold monitoring - **Timer (5)**: ups_timer_shutdown, ups_timer_start, ups_timer_reboot, active_timer_count, fast_polling_status #### **Text Sensors** (10 total available): - **Base (2)**: status, protocol *(in base_ups.yaml)* - **Essential (2)**: manufacturer, model - **Extended (6)**: serial_number, firmware_version, ups_beeper_status, input_sensitivity, ups_mfr_date, battery_status, ups_firmware_aux - **Controls (1)**: ups_test_result *(in ups_controls.yaml)* - **Device-Specific (+1)**: battery_mfr_date *(CyberPower only)* #### **Binary Sensors** (6 total): - **Base (4)**: online, on_battery, low_battery, fault - **Essential (2)**: charging, overload #### **Button Controls** (10 total, all in ups_controls.yaml): - **Beeper (4)**: enable, disable, mute, test - **Testing (6)**: battery_quick, battery_deep, battery_stop, ups_test, ups_stop #### **Number Controls** (3 total, all in delay_config.yaml): - **Delay Configuration (3)**: shutdown_delay, start_delay, reboot_delay #### **Smart Templates** (2 calculated sensors): - **Generic**: UPS Load Power (uses HID data when available) - **Device-Specific**: Device-optimized power calculations ## Testing Configurations ### `testing/basic_test.yaml` Minimal configuration for protocol detection and basic functionality: ```yaml packages: base_ups: !include ../base_ups.yaml essential: !include ../essential_sensors.yaml ``` **Use for**: Initial device testing, protocol verification, basic connectivity ### `testing/beeper_test.yaml` Focused beeper control testing: ```yaml packages: base_ups: !include ../base_ups.yaml essential: !include ../essential_sensors.yaml controls: !include ../ups_controls.yaml ``` **Use for**: Testing beeper functionality, control operations ### `testing/simulation_test.yaml` Complete testing without physical hardware: ```yaml packages: base_ups: !include ../base_ups.yaml essential: !include ../essential_sensors.yaml extended: !include ../extended_sensors.yaml controls: !include ../ups_controls.yaml ``` **Use for**: Development, CI/CD testing, feature demonstration ### `testing/minimal_data_provider.yaml` Data provider pattern testing with zero sensor entities: ```yaml substitutions: simulation_mode: "true" # Enable simulation for testing packages: base_ups: !include base_ups.yaml # ZERO sensor entities defined - tests pure data provider mode! ``` **Features**: - Tests all direct data access methods: `id(ups_monitor).is_online()`, etc. - LED automation works without any sensor entities - Comprehensive validation of data provider pattern - **Use for**: Testing component as pure data provider, custom automation development ## Production Examples ### `examples/apc-ups-monitor.yaml` Complete APC UPS production configuration: - Modular package composition - Device-specific optimizations - Custom automation examples - Network and notification setup - Choice of standard or grouped entity layout ### `examples/rack-ups-monitor.yaml` Complete CyberPower UPS production configuration: - Advanced sensor utilization - Smart threshold monitoring - Rich data analysis - Enhanced automation - Choice of standard or grouped entity layout ### `examples/grouped-ups-monitor.yaml` Demonstration of organized web interface: - All entities organized into 10 logical groups - Hierarchical layout with clear visual sections - Improved navigation and reduced scrolling - Same functionality as standard packages ## Usage Patterns ### 1. Basic UPS Monitoring ```yaml packages: base_ups: !include configs/base_ups.yaml essential: !include configs/essential_sensors.yaml ``` **Result**: ~150 lines → Essential monitoring only ### 2. Full-Featured UPS ```yaml packages: base_ups: !include configs/base_ups.yaml essential: !include configs/essential_sensors.yaml extended: !include configs/extended_sensors.yaml timers: !include configs/timer_sensors.yaml controls: !include configs/ups_controls.yaml delays: !include configs/delay_config.yaml device: !include configs/device_types/cyberpower_cp1500.yaml ``` **Result**: ~380 lines → Complete functionality with UPS configuration ### 3. Organized Interface UPS ```yaml packages: # Enable organized web interface entity_groups: !include configs/entity_groups.yaml # Use grouped sensor packages base_ups: !include configs/base_ups.yaml essential_grouped: !include configs/essential_sensors_grouped.yaml extended_grouped: !include configs/extended_sensors_grouped.yaml timers_grouped: !include configs/timer_sensors_grouped.yaml controls_grouped: !include configs/ups_controls_grouped.yaml delays: !include configs/delay_config.yaml device: !include configs/device_types/cyberpower_cp1500.yaml ``` **Result**: Same functionality with organized web interface layout ### 4. Custom Configuration ```yaml substitutions: name: "my-custom-ups" update_interval: "30s" packages: base_ups: !include configs/base_ups.yaml essential: !include configs/essential_sensors.yaml # Add custom sensors or overrides here sensor: - platform: template name: "Custom Power Calculation" # ... custom logic ``` ## Configuration Management Best Practices ### 1. **Start Simple** Begin with `basic_test.yaml` to verify device detection and protocol compatibility. ### 2. **Layer Functionality** Add packages incrementally: - Start with `base_ups.yaml` + `essential_sensors.yaml` - Add `extended_sensors.yaml` if you need advanced metrics - Add `timer_sensors.yaml` for real-time countdown monitoring - Include `ups_controls.yaml` for interactive features - Apply device-specific packages last - Optionally use `*_grouped.yaml` + `entity_groups.yaml` for organized web interface ### 3. **Use Substitutions for Customization** Override defaults without modifying packages: ```yaml substitutions: name: "office-ups" friendly_name: "Office UPS Monitor" update_interval: "30s" simulation_mode: "false" ``` ### 4. **Device-Specific Optimization** - **APC devices**: Use slower update intervals (15-30s) - **CyberPower devices**: Can handle faster updates (5-10s) - **Generic devices**: Start conservative (30s) and adjust ### 5. **Choose Entity Layout** **Standard Layout** (flat entity list): ```yaml packages: essential: !include configs/essential_sensors.yaml extended: !include configs/extended_sensors.yaml ``` **Organized Layout** (grouped by function): ```yaml packages: entity_groups: !include configs/entity_groups.yaml essential_grouped: !include configs/essential_sensors_grouped.yaml extended_grouped: !include configs/extended_sensors_grouped.yaml ``` ### 6. **Environment-Specific Files** ```yaml # development.yaml substitutions: log_level: "VERBOSE" update_interval: "5s" simulation_mode: "true" # production.yaml substitutions: log_level: "INFO" update_interval: "30s" simulation_mode: "false" ``` ### 6. **Testing Strategy** - **Protocol Testing**: Use `testing/basic_test.yaml` - **Feature Testing**: Use specific test configurations - **Integration Testing**: Use `testing/simulation_test.yaml` - **Data Provider Testing**: Use `testing/minimal_data_provider.yaml` - **Production Validation**: Use device-specific examples ### 7. **Data Provider Pattern Usage** The UPS HID component now functions as a **data provider**, allowing direct access to UPS data without requiring sensor entities: #### **Direct Data Access Methods**: ```yaml interval: - interval: 10s then: - lambda: |- // Boolean state methods (no sensor entities needed!) if (id(ups_monitor).is_online()) { ESP_LOGI("ups", "UPS is online"); } if (id(ups_monitor).is_on_battery()) { ESP_LOGI("ups", "Running on battery: %.1f%% remaining", id(ups_monitor).get_battery_level()); } ``` #### **Available Direct Access Methods**: **Boolean States**: `is_online()`, `is_on_battery()`, `is_low_battery()`, `is_charging()`, `has_fault()`, `is_overloaded()` **Value Getters**: `get_battery_level()`, `get_input_voltage()`, `get_output_voltage()`, `get_load_percent()`, `get_runtime_minutes()`