feat(ups-hid): setting up testing infrastructure

Signed-off-by: bullshit <coding@ow-software.pl>
This commit is contained in:
bullshit committed 2025-08-22 12:49:43 +02:00
1 parent ecf606593d
commit bdbf617917
22 files changed
+1657 -1243

No files matched your search

+187
View File
@@ -0,0 +1,187 @@
# UPS HID Configuration Management
This directory provides a modular, maintainable approach to UPS HID device configuration using ESPHome packages. Instead of maintaining large, complex configuration files, you can compose configurations from reusable components.
## Modular Configuration Packages
### Core Packages
#### `base_ups.yaml`
Essential foundation for all UPS devices:
- ESP32-S3 hardware configuration
- Network setup (WiFi, OTA, Web server)
- UPS HID component initialization
- Status LED with basic patterns
- Essential binary sensors for LED automation
#### `essential_sensors.yaml`
Core monitoring sensors available on all UPS protocols:
- Battery level, input/output voltage, load percentage
- Runtime remaining, basic device information
- System monitoring (uptime, WiFi signal)
- Compatible with APC, CyberPower, and Generic protocols
#### `extended_sensors.yaml`
Advanced sensors for feature-rich devices:
- Battery voltage (actual and nominal)
- Input transfer limits and frequency
- UPS configuration parameters
- Power calculations and analysis
- Optimized for CyberPower devices
#### `ups_controls.yaml`
Interactive control functionality:
- Beeper control (enable/disable/mute/test)
- Battery testing (quick/deep/stop)
- Panel testing (start/stop)
- Test result monitoring
### Device-Specific Packages
#### `device_types/apc_backups_es.yaml`
APC Back-UPS ES series optimizations:
- Slower update intervals (APC devices need more time)
- APC-specific power calculations (405W nominal)
- Enhanced protocol debugging
- Device-specific status monitoring
#### `device_types/cyberpower_cp1500.yaml`
CyberPower CP1500 series optimizations:
- Fast update intervals (CyberPower responds quickly)
- Advanced threshold monitoring
- Extended device information
- Rich sensor data utilization
## 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
## 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
### `examples/rack-ups-monitor.yaml`
Complete CyberPower UPS production configuration:
- Advanced sensor utilization
- Smart threshold monitoring
- Rich data analysis
- Enhanced automation
## 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
controls: !include configs/ups_controls.yaml
device: !include configs/device_types/cyberpower_cp1500.yaml
```
**Result**: ~300 lines → Complete functionality
### 3. 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
- Include `ups_controls.yaml` for interactive features
- Apply device-specific packages last
### 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. **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 `basic_test.yaml`
- **Feature Testing**: Use specific test configurations
- **Integration Testing**: Use `simulation_test.yaml`
- **Production Validation**: Use device-specific examples
+169
View File
@@ -0,0 +1,169 @@
# Base UPS Configuration Package
# Common settings for all UPS HID devices
# Use with: packages: !include configs/base_ups.yaml
# Substitutions with sensible defaults
substitutions:
# Device identification
friendly_name: "${name}"
device_description: "UPS Monitor with ESP32-S3"
# UPS configuration
update_interval: "10s"
protocol_timeout: "15s"
simulation_mode: "false"
# LED status pin (default for ESP32-S3-DevKitC-1)
led_pin: "GPIO48"
# Logging level
log_level: "DEBUG"
# Core ESP32 configuration
esp32:
board: esp32-s3-devkitc-1
framework:
type: esp-idf
# Logging configuration
logger:
level: ${log_level}
baud_rate: 115200
hardware_uart: UART0
logs:
ups_hid: DEBUG
# Network configuration
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
domain: !secret wifi_dns_domain
ap:
ssid: "${friendly_name} Fallback"
password: !secret ap_password
captive_portal:
# OTA updates
ota:
- platform: esphome
password: !secret ota_password
# Web server for diagnostics
web_server:
port: 80
# External components
external_components:
- source:
type: local
path: ../components
# Main UPS HID Component
ups_hid:
id: ups_monitor
update_interval: ${update_interval}
protocol_timeout: ${protocol_timeout}
auto_detect_protocol: true
simulation_mode: ${simulation_mode}
# Status LED configuration
light:
- platform: esp32_rmt_led_strip
chipset: WS2812
pin: ${led_pin}
num_leds: 1
rgb_order: GRB
name: "UPS Status LED"
id: ups_status_led
restore_mode: ALWAYS_OFF
effects:
- strobe:
name: "Critical Alert"
colors:
- state: true
brightness: 100%
red: 100%
green: 0%
blue: 0%
duration: 200ms
- state: false
duration: 200ms
- pulse:
name: "Battery Warning"
transition_length: 1.5s
min_brightness: 10%
max_brightness: 90%
- pulse:
name: "Normal Status"
transition_length: 3s
min_brightness: 20%
max_brightness: 60%
# LED control automation
interval:
- interval: 2s
then:
- lambda: |-
if (id(low_battery).state || id(ups_fault).state) {
auto call = id(ups_status_led).turn_on();
call.set_rgb(1.0, 0.0, 0.0);
call.set_effect("Critical Alert");
call.perform();
} else if (id(on_battery).state) {
auto call = id(ups_status_led).turn_on();
call.set_rgb(1.0, 0.5, 0.0);
call.set_effect("Battery Warning");
call.perform();
} else if (id(ups_online).state) {
auto call = id(ups_status_led).turn_on();
call.set_rgb(0.0, 1.0, 0.0);
call.set_effect("Normal Status");
call.perform();
} else {
id(ups_status_led).turn_off().perform();
}
# Essential binary sensors (required for LED automation)
binary_sensor:
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Online"
id: ups_online
type: online
device_class: connectivity
- platform: ups_hid
ups_hid_id: ups_monitor
name: "On Battery Power"
id: on_battery
type: on_battery
device_class: battery
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Low Battery Warning"
id: low_battery
type: low_battery
device_class: battery
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Fault"
id: ups_fault
type: fault
device_class: problem
# Essential text sensors
text_sensor:
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Status"
id: ups_status_text
type: status
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Detected Protocol"
id: ups_protocol
type: protocol
+67
View File
@@ -0,0 +1,67 @@
# APC Back-UPS ES Series Configuration
# Optimized for APC Back-UPS ES 700 (VID: 0x051D, PID: 0x0002)
# Use with: packages: !include configs/device_types/apc_backups_es.yaml
substitutions:
# Device-specific overrides
device_description: "APC Back-UPS ES 700 Monitor"
log_level: "DEBUG"
# APC-specific settings
update_interval: "15s" # APC devices can be slower to respond
protocol_timeout: "20s"
# Override UPS component with APC-specific settings
ups_hid:
id: ups_monitor
update_interval: ${update_interval}
protocol_timeout: ${protocol_timeout}
auto_detect_protocol: true
simulation_mode: ${simulation_mode}
# Uncomment if auto-detection fails:
# usb_vendor_id: 0x051D
# usb_product_id: 0x0002
# Enhanced logging for APC protocol debugging
logger:
level: ${log_level}
logs:
ups_hid: DEBUG
ups_hid.apc: DEBUG
ups_hid.apc_hid: DEBUG
# APC-specific power calculations
sensor:
- platform: template
name: "UPS Load Power (APC)"
id: ups_load_power_apc
unit_of_measurement: "W"
device_class: power
state_class: measurement
accuracy_decimals: 1
lambda: |-
if (!std::isnan(id(load_percentage).state)) {
// APC Back-UPS ES 700: 405W nominal power
float apc_max_power = 405.0;
return (apc_max_power * id(load_percentage).state) / 100.0;
}
return NAN;
update_interval: 30s
# APC-specific monitoring scripts
script:
- id: apc_status_check
then:
- logger.log:
format: "APC Status: Battery=%.1f%%, Load=%.1fw, Status=%s"
args:
- "id(battery_level).state"
- "id(ups_load_power_apc).state"
- "id(ups_status_text).state.c_str()"
level: INFO
# APC device monitoring
interval:
- interval: 60s
then:
- script.execute: apc_status_check
+133
View File
@@ -0,0 +1,133 @@
# CyberPower CP1500 Series Configuration
# Optimized for CyberPower CP1500EPFCLCD (VID: 0x0764, PID: 0x0501)
# Use with: packages: !include configs/device_types/cyberpower_cp1500.yaml
substitutions:
# Device-specific overrides
device_description: "CyberPower CP1500EPFCLCD Monitor"
log_level: "DEBUG"
# CyberPower-specific settings
update_interval: "10s" # CyberPower devices respond quickly
protocol_timeout: "15s"
# Override UPS component with CyberPower-specific settings
ups_hid:
id: ups_monitor
update_interval: ${update_interval}
protocol_timeout: ${protocol_timeout}
auto_detect_protocol: true
simulation_mode: ${simulation_mode}
# Uncomment if auto-detection fails:
# usb_vendor_id: 0x0764
# usb_product_id: 0x0501
# Enhanced logging for CyberPower protocol debugging
logger:
level: ${log_level}
logs:
ups_hid: DEBUG
ups_hid.cyberpower: DEBUG
# CyberPower-specific threshold sensors
sensor:
# Battery threshold monitoring (available on CyberPower)
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Battery Charge Low Threshold"
id: battery_charge_low
type: battery_charge_low
unit_of_measurement: "%"
device_class: battery
state_class: measurement
accuracy_decimals: 0
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Battery Runtime Low Threshold"
id: battery_runtime_low
type: battery_runtime_low
unit_of_measurement: "min"
device_class: duration
state_class: measurement
accuracy_decimals: 0
# CyberPower-specific timer values
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Timer Reboot"
id: ups_timer_reboot
type: ups_timer_reboot
unit_of_measurement: "s"
device_class: duration
state_class: measurement
accuracy_decimals: 0
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Timer Shutdown"
id: ups_timer_shutdown
type: ups_timer_shutdown
unit_of_measurement: "s"
device_class: duration
state_class: measurement
accuracy_decimals: 0
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Timer Start"
id: ups_timer_start
type: ups_timer_start
unit_of_measurement: "s"
device_class: duration
state_class: measurement
accuracy_decimals: 0
# CyberPower-specific enhanced device info
text_sensor:
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Battery Status"
id: battery_status
type: battery_status
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Battery Type"
id: battery_type
type: battery_type
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Battery Manufacture Date"
id: battery_mfr_date
type: battery_mfr_date
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Manufacture Date"
id: ups_mfr_date
type: ups_mfr_date
# CyberPower-specific monitoring scripts
script:
- id: cyberpower_detailed_status
then:
- logger.log:
format: "CyberPower Status: Battery=%.1f%% (%.1fV/%.0fV), Load=%.1f%% (%.0fW/%.0fW), Input=%.1fV, Runtime=%.1fmin"
args:
- "id(battery_level).state"
- "id(battery_voltage).state"
- "id(battery_voltage_nominal).state"
- "id(load_percentage).state"
- "id(ups_load_power).state"
- "id(ups_realpower_nominal).state"
- "id(input_voltage).state"
- "id(runtime_remaining).state"
level: INFO
# Enhanced monitoring for CyberPower features
interval:
- interval: 120s
then:
- script.execute: cyberpower_detailed_status
+105
View File
@@ -0,0 +1,105 @@
# Essential UPS Sensors Package
# Core monitoring sensors for all UPS devices
# Use with: packages: !include configs/essential_sensors.yaml
sensor:
# Core UPS metrics - available on all protocols
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Battery Level"
id: battery_level
type: battery_level
unit_of_measurement: "%"
device_class: battery
state_class: measurement
accuracy_decimals: 0
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Input Voltage"
id: input_voltage
type: input_voltage
unit_of_measurement: "V"
device_class: voltage
state_class: measurement
accuracy_decimals: 1
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Output Voltage"
id: output_voltage
type: output_voltage
unit_of_measurement: "V"
device_class: voltage
state_class: measurement
accuracy_decimals: 1
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Load Percentage"
id: load_percentage
type: load_percent
unit_of_measurement: "%"
device_class: power_factor
state_class: measurement
accuracy_decimals: 0
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Runtime Remaining"
id: runtime_remaining
type: runtime
unit_of_measurement: "min"
device_class: duration
state_class: measurement
accuracy_decimals: 0
# System monitoring
- platform: uptime
name: "Uptime"
id: uptime_sensor
update_interval: 60s
- platform: wifi_signal
name: "WiFi Signal"
id: wifi_signal_sensor
update_interval: 60s
text_sensor:
# Device identification
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Manufacturer"
id: ups_manufacturer
type: manufacturer
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Model"
id: ups_model
type: model
- platform: wifi_info
ip_address:
name: "IP Address"
id: ip_address
- platform: version
name: "ESPHome Version"
id: esphome_version
binary_sensor:
# Additional status sensors
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Battery Charging"
id: battery_charging
type: charging
device_class: battery
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Overload Warning"
id: overload_warning
type: overload
device_class: power
+66
View File
@@ -0,0 +1,66 @@
# Example: APC Back-UPS ES 700 Configuration
# Complete production configuration for APC UPS
# Copy and customize this file for your APC device
substitutions:
name: "apc-ups-monitor"
friendly_name: "Office APC UPS"
# Device customization
timezone: "America/Vienna" # Replace with your timezone
# Testing/production mode
simulation_mode: "false" # Set to "true" for testing without hardware
esphome:
name: "${name}"
friendly_name: "${friendly_name}"
comment: "APC Back-UPS ES 700 Monitor"
# Use modular configuration packages
packages:
# Core functionality
base_ups: !include ../base_ups.yaml
essential: !include ../essential_sensors.yaml
# Extended monitoring (optional - comment out if not needed)
extended: !include ../extended_sensors.yaml
# Control buttons (optional - comment out if not needed)
controls: !include ../ups_controls.yaml
# APC-specific optimizations
apc_device: !include ../device_types/apc_backups_es.yaml
# Time component for accurate timestamps
time:
- platform: sntp
id: sntp_time
timezone: "${timezone}"
# Optional: Home Assistant API (uncomment to enable)
# api:
# encryption:
# key: "your_32_character_encryption_key_here=="
# Optional: Notification automation examples
script:
- id: power_outage_alert
then:
- logger.log:
format: "POWER OUTAGE DETECTED - Battery at %.1f%%, Runtime: %.1f minutes"
args:
- "id(battery_level).state"
- "id(runtime_remaining).state"
level: WARN
# Add your notification logic here (e.g., Home Assistant service call)
- id: power_restored_alert
then:
- logger.log:
format: "POWER RESTORED - UPS back online"
level: INFO
# Add your notification logic here
# Custom automations would be handled in Home Assistant
# The base sensors from base_ups.yaml and essential_sensors.yaml provide all the data needed
+91
View File
@@ -0,0 +1,91 @@
# Example: CyberPower CP1500EPFCLCD Configuration
# Complete production configuration for CyberPower UPS
# Copy and customize this file for your CyberPower device
substitutions:
name: "rack-ups-monitor"
friendly_name: "Rack CyberPower UPS"
# Device customization
timezone: "America/Vienna" # Replace with your timezone
# Testing/production mode
simulation_mode: "false" # Set to "true" for testing without hardware
esphome:
name: "${name}"
friendly_name: "${friendly_name}"
comment: "CyberPower CP1500EPFCLCD Monitor"
# Use modular configuration packages
packages:
# Core functionality
base_ups: !include ../base_ups.yaml
essential: !include ../essential_sensors.yaml
# Extended monitoring (recommended for CyberPower - rich sensor data)
extended: !include ../extended_sensors.yaml
# Control buttons (recommended - CyberPower has excellent beeper support)
controls: !include ../ups_controls.yaml
# CyberPower-specific optimizations
cyberpower_device: !include ../device_types/cyberpower_cp1500.yaml
# Time component for accurate timestamps
time:
- platform: sntp
id: sntp_time
timezone: "${timezone}"
# Optional: Home Assistant API (uncomment to enable)
# api:
# encryption:
# key: "your_32_character_encryption_key_here=="
# CyberPower-specific automation examples
script:
- id: battery_threshold_alert
then:
- logger.log:
format: "BATTERY THRESHOLD ALERT - Current: %.1f%%, Low Threshold: %.1f%%, Runtime Low: %.1f min"
args:
- "id(battery_level).state"
- "id(battery_charge_low).state"
- "id(battery_runtime_low).state"
level: WARN
- id: advanced_power_analysis
then:
- logger.log:
format: "POWER ANALYSIS - Load: %.1f%% (%.0fW/%.0fW), Input: %.1fV (%.0fV nominal), Battery: %.1fV/%.0fV"
args:
- "id(load_percentage).state"
- "id(ups_load_power).state"
- "id(ups_realpower_nominal).state"
- "id(input_voltage).state"
- "id(input_voltage_nominal).state"
- "id(battery_voltage).state"
- "id(battery_voltage_nominal).state"
level: INFO
# Enhanced monitoring with CyberPower's rich data
interval:
- interval: 300s # Every 5 minutes
then:
- script.execute: advanced_power_analysis
# Smart threshold monitoring
binary_sensor:
- platform: template
name: "Battery Below Custom Threshold"
id: battery_custom_threshold
lambda: |-
// Trigger alert when battery drops below configured low threshold
if (!std::isnan(id(battery_level).state) && !std::isnan(id(battery_charge_low).state)) {
return id(battery_level).state <= id(battery_charge_low).state;
}
return false;
on_press:
then:
- script.execute: battery_threshold_alert
+144
View File
@@ -0,0 +1,144 @@
# Extended UPS Sensors Package
# Additional sensors for advanced monitoring (CyberPower optimized)
# Use with: packages: !include configs/extended_sensors.yaml
sensor:
# Advanced battery metrics
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Battery Voltage"
id: battery_voltage
type: battery_voltage
unit_of_measurement: "V"
device_class: voltage
state_class: measurement
accuracy_decimals: 1
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Battery Voltage Nominal"
id: battery_voltage_nominal
type: battery_voltage_nominal
unit_of_measurement: "V"
device_class: voltage
state_class: measurement
accuracy_decimals: 0
# Input power analysis
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Input Voltage Nominal"
id: input_voltage_nominal
type: input_voltage_nominal
unit_of_measurement: "V"
device_class: voltage
state_class: measurement
accuracy_decimals: 0
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Input Transfer Low"
id: input_transfer_low
type: input_transfer_low
unit_of_measurement: "V"
device_class: voltage
state_class: measurement
accuracy_decimals: 0
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Input Transfer High"
id: input_transfer_high
type: input_transfer_high
unit_of_measurement: "V"
device_class: voltage
state_class: measurement
accuracy_decimals: 0
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Input Frequency"
id: input_frequency
type: frequency
unit_of_measurement: "Hz"
state_class: measurement
accuracy_decimals: 1
# UPS configuration metrics
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Real Power Nominal"
id: ups_realpower_nominal
type: ups_realpower_nominal
unit_of_measurement: "W"
device_class: power
state_class: measurement
accuracy_decimals: 0
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Delay Shutdown"
id: ups_delay_shutdown
type: ups_delay_shutdown
unit_of_measurement: "s"
device_class: duration
state_class: measurement
accuracy_decimals: 0
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Delay Start"
id: ups_delay_start
type: ups_delay_start
unit_of_measurement: "s"
device_class: duration
state_class: measurement
accuracy_decimals: 0
# Calculated power consumption
- platform: template
name: "UPS Load Power"
id: ups_load_power
unit_of_measurement: "W"
device_class: power
state_class: measurement
accuracy_decimals: 1
lambda: |-
if (!std::isnan(id(load_percentage).state)) {
float ups_max_power = 700.0; // Default fallback
// Use HID nominal power if available
if (!std::isnan(id(ups_realpower_nominal).state)) {
ups_max_power = id(ups_realpower_nominal).state;
}
return (ups_max_power * id(load_percentage).state) / 100.0;
}
return NAN;
update_interval: 30s
text_sensor:
# Extended device information
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Serial Number"
id: ups_serial_number
type: serial_number
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Firmware Version"
id: ups_firmware_version
type: firmware_version
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Beeper Status"
id: ups_beeper_status
type: ups_beeper_status
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Input Sensitivity"
id: input_sensitivity
type: input_sensitivity
+5
View File
@@ -0,0 +1,5 @@
# Gitignore settings for ESPHome
# This is an example and may include too much for your use-case.
# You can modify this file to suit your needs.
/.esphome/
/secrets.yaml
+58
View File
@@ -0,0 +1,58 @@
# Basic UPS Testing Configuration
# Minimal setup for protocol detection and basic functionality testing
# Use: esphome compile configs/testing/basic_test.yaml
substitutions:
name: "ups-basic-test"
friendly_name: "UPS Basic Test"
simulation_mode: "false"
log_level: "DEBUG"
esphome:
name: "${name}"
friendly_name: "${friendly_name}"
comment: "Basic UPS HID functionality test"
# Include secrets from root directory
<<: !include ../../secrets.yaml
# Use base configuration package
packages:
base_ups: !include ../base_ups.yaml
essential: !include ../essential_sensors.yaml
# Override for testing - faster updates, more verbose logging
ups_hid:
id: ups_monitor
update_interval: 5s
protocol_timeout: 10s
auto_detect_protocol: true
simulation_mode: ${simulation_mode}
# Enhanced logging for testing
logger:
level: VERBOSE
logs:
ups_hid: DEBUG
ups_hid.apc: DEBUG
ups_hid.cyberpower: DEBUG
ups_hid.generic: DEBUG
usb_host: DEBUG
# Simple test validation script
script:
- id: test_validation
then:
- logger.log:
format: "TEST RESULTS - Protocol: %s, Battery: %.1f%%, Status: %s"
args:
- "id(ups_protocol).state.c_str()"
- "id(battery_level).state"
- "id(ups_status_text).state.c_str()"
level: INFO
# Run validation every 30 seconds during testing
interval:
- interval: 30s
then:
- script.execute: test_validation
+163
View File
@@ -0,0 +1,163 @@
# Basic UPS Testing Configuration (Standalone)
# Self-contained version that doesn't depend on external files for CI/CD
# Use: esphome compile configs/testing/basic_test_standalone.yaml
substitutions:
name: "ups-basic-test"
friendly_name: "UPS Basic Test"
simulation_mode: "false"
log_level: "DEBUG"
esphome:
name: "${name}"
friendly_name: "${friendly_name}"
comment: "Basic UPS HID functionality test"
# Core ESP32 configuration
esp32:
board: esp32-s3-devkitc-1
framework:
type: esp-idf
# Logging configuration
logger:
level: VERBOSE
baud_rate: 115200
hardware_uart: UART0
logs:
ups_hid: DEBUG
ups_hid.apc: DEBUG
ups_hid.cyberpower: DEBUG
ups_hid.generic: DEBUG
usb_host: DEBUG
# Network configuration (minimal for testing)
wifi:
ssid: "TestNetwork"
password: "TestPassword"
ap:
ssid: "${friendly_name} Fallback"
password: "TestAPPassword"
captive_portal:
# OTA updates
ota:
- platform: esphome
password: "TestOTAPassword"
# Web server for diagnostics
web_server:
port: 80
# External components
external_components:
- source:
type: local
path: ../../components
# Main UPS HID Component
ups_hid:
id: ups_monitor
update_interval: 5s
protocol_timeout: 10s
auto_detect_protocol: true
simulation_mode: ${simulation_mode}
# Status LED configuration
light:
- platform: esp32_rmt_led_strip
chipset: WS2812
pin: GPIO48
num_leds: 1
rgb_order: GRB
name: "UPS Status LED"
id: ups_status_led
restore_mode: ALWAYS_OFF
# Required platform components (fix compilation errors)
button:
# Essential binary sensors
binary_sensor:
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Online"
id: ups_online
type: online
device_class: connectivity
- platform: ups_hid
ups_hid_id: ups_monitor
name: "On Battery Power"
id: on_battery
type: on_battery
device_class: battery
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Low Battery Warning"
id: low_battery
type: low_battery
device_class: battery
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Fault"
id: ups_fault
type: fault
device_class: problem
# Essential text sensors
text_sensor:
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Status"
id: ups_status_text
type: status
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Detected Protocol"
id: ups_protocol
type: protocol
# Core UPS metrics
sensor:
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Battery Level"
id: battery_level
type: battery_level
unit_of_measurement: "%"
device_class: battery
state_class: measurement
accuracy_decimals: 0
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Runtime Remaining"
id: runtime_remaining
type: runtime
unit_of_measurement: "min"
device_class: duration
state_class: measurement
accuracy_decimals: 0
# Simple test validation script
script:
- id: test_validation
then:
- logger.log:
format: "TEST RESULTS - Protocol: %s, Battery: %.1f%%, Status: %s"
args:
- "id(ups_protocol).state.c_str()"
- "id(battery_level).state"
- "id(ups_status_text).state.c_str()"
level: INFO
# Run validation every 30 seconds during testing
interval:
- interval: 30s
then:
- script.execute: test_validation
+57
View File
@@ -0,0 +1,57 @@
# UPS Beeper Control Testing Configuration
# Focused testing for beeper functionality
# Use: esphome compile configs/testing/beeper_test.yaml
substitutions:
name: "ups-beeper-test"
friendly_name: "UPS Beeper Test"
simulation_mode: "false"
log_level: "DEBUG"
esphome:
name: "${name}"
friendly_name: "${friendly_name}"
comment: "UPS beeper control functionality test"
# Include secrets from root directory
<<: !include ../../secrets.yaml
# Use base configuration and controls package
packages:
base_ups: !include ../base_ups.yaml
essential: !include ../essential_sensors.yaml
controls: !include ../ups_controls.yaml
# Override for testing - faster response
ups_hid:
id: ups_monitor
update_interval: 5s
protocol_timeout: 10s
auto_detect_protocol: true
simulation_mode: ${simulation_mode}
# Beeper-focused logging
logger:
level: DEBUG
logs:
ups_hid: DEBUG
ups_hid.apc: DEBUG
ups_hid.cyberpower: DEBUG
button: DEBUG
# Beeper status monitoring
script:
- id: beeper_status_check
then:
- logger.log:
format: "BEEPER STATUS: %s (Protocol: %s)"
args:
- "id(ups_beeper_status).state.c_str()"
- "id(ups_protocol).state.c_str()"
level: INFO
# Monitor beeper status changes
interval:
- interval: 15s
then:
- script.execute: beeper_status_check
+33
View File
@@ -0,0 +1,33 @@
# Auto-generated test config for ESPHome matrix testing
substitutions:
device_name: "ups-matrix-test"
friendly_name: "UPS Matrix Test"
esphome:
name: ${device_name}
friendly_name: ${friendly_name}
esp32:
board: esp32-s3-devkitc-1
framework:
type: esp-idf
version: 5.3.0
logger:
level: INFO
external_components:
- source: components/
components: [ ups_hid ]
ups_hid:
id: ups_monitor
update_interval: 30s
simulation_mode: true
auto_detect_protocol: true
sensor:
- platform: ups_hid
ups_hid_id: ups_monitor
type: battery_level
name: "Battery Level"
+61
View File
@@ -0,0 +1,61 @@
# Minimal UPS Simulation Configuration
# Simplest possible config for testing core functionality
# Use: esphome compile configs/testing/minimal_simulation.yaml
substitutions:
name: "ups-minimal-sim"
friendly_name: "UPS Minimal Simulation"
esphome:
name: "${name}"
friendly_name: "${friendly_name}"
comment: "Minimal UPS simulation test"
# Core ESP32 configuration
esp32:
board: esp32-s3-devkitc-1
framework:
type: esp-idf
# Minimal logging
logger:
level: INFO
baud_rate: 115200
# Minimal network
wifi:
ssid: "TestNetwork"
password: "TestPassword"
# External components
external_components:
- source:
type: local
path: ../../components
# UPS component only
ups_hid:
id: ups_monitor
update_interval: 10s
protocol_timeout: 5s
auto_detect_protocol: true
simulation_mode: true
# Required platform components (fix compilation errors)
button:
binary_sensor:
# Single sensor test
sensor:
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Battery Level"
type: battery_level
unit_of_measurement: "%"
# Single text sensor test
text_sensor:
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Status"
type: status
+57
View File
@@ -0,0 +1,57 @@
# UPS Simulation Testing Configuration
# Testing without physical hardware using simulation mode
# Use: esphome compile configs/testing/simulation_test.yaml
substitutions:
name: "ups-simulation-test"
friendly_name: "UPS Simulation Test"
simulation_mode: "true" # Enable simulation mode
log_level: "INFO"
esphome:
name: "${name}"
friendly_name: "${friendly_name}"
comment: "UPS simulation mode test (no hardware required)"
# Include secrets from root directory
<<: !include ../../secrets.yaml
# Use base configuration packages
packages:
base_ups: !include ../base_ups.yaml
essential: !include ../essential_sensors.yaml
extended: !include ../extended_sensors.yaml
controls: !include ../ups_controls.yaml
# Override for simulation testing
ups_hid:
id: ups_monitor
update_interval: 5s # Fast updates for demo
protocol_timeout: 5s
auto_detect_protocol: true
simulation_mode: ${simulation_mode}
# Reduced logging for simulation
logger:
level: ${log_level}
logs:
ups_hid: INFO
# Simulation validation script
script:
- id: simulation_demo
then:
- logger.log:
format: "SIMULATION DATA - Battery: %.1f%%, Load: %.1f%%, Input: %.1fV, Output: %.1fV"
args:
- "id(battery_level).state"
- "id(load_percentage).state"
- "id(input_voltage).state"
- "id(output_voltage).state"
level: INFO
# Demo data updates every 10 seconds
interval:
- interval: 10s
then:
- script.execute: simulation_demo
@@ -0,0 +1,190 @@
# UPS Simulation Testing Configuration (Standalone)
# Testing without physical hardware using simulation mode
# Use: esphome compile configs/testing/simulation_test_standalone.yaml
substitutions:
name: "ups-simulation-test"
friendly_name: "UPS Simulation Test"
simulation_mode: "true" # Enable simulation mode
log_level: "INFO"
esphome:
name: "${name}"
friendly_name: "${friendly_name}"
comment: "UPS simulation mode test (no hardware required)"
# Core ESP32 configuration
esp32:
board: esp32-s3-devkitc-1
framework:
type: esp-idf
# Reduced logging for simulation
logger:
level: ${log_level}
baud_rate: 115200
hardware_uart: UART0
logs:
ups_hid: INFO
# Network configuration (minimal for testing)
wifi:
ssid: "TestNetwork"
password: "TestPassword"
ap:
ssid: "${friendly_name} Fallback"
password: "TestAPPassword"
captive_portal:
# OTA updates
ota:
- platform: esphome
password: "TestOTAPassword"
# Web server for diagnostics
web_server:
port: 80
# External components
external_components:
- source:
type: local
path: ../../components
# Required platform components (fix compilation errors)
button:
# Override for simulation testing
ups_hid:
id: ups_monitor
update_interval: 5s # Fast updates for demo
protocol_timeout: 5s
auto_detect_protocol: true
simulation_mode: ${simulation_mode}
# Status LED configuration
light:
- platform: esp32_rmt_led_strip
chipset: WS2812
pin: GPIO48
num_leds: 1
rgb_order: GRB
name: "UPS Status LED"
id: ups_status_led
restore_mode: ALWAYS_OFF
# Essential binary sensors
binary_sensor:
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Online"
id: ups_online
type: online
device_class: connectivity
- platform: ups_hid
ups_hid_id: ups_monitor
name: "On Battery Power"
id: on_battery
type: on_battery
device_class: battery
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Low Battery Warning"
id: low_battery
type: low_battery
device_class: battery
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Fault"
id: ups_fault
type: fault
device_class: problem
# Essential text sensors
text_sensor:
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Status"
id: ups_status_text
type: status
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Detected Protocol"
id: ups_protocol
type: protocol
# Core UPS metrics - available on all protocols
sensor:
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Battery Level"
id: battery_level
type: battery_level
unit_of_measurement: "%"
device_class: battery
state_class: measurement
accuracy_decimals: 0
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Input Voltage"
id: input_voltage
type: input_voltage
unit_of_measurement: "V"
device_class: voltage
state_class: measurement
accuracy_decimals: 1
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Output Voltage"
id: output_voltage
type: output_voltage
unit_of_measurement: "V"
device_class: voltage
state_class: measurement
accuracy_decimals: 1
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Load Percentage"
id: load_percentage
type: load_percent
unit_of_measurement: "%"
device_class: power_factor
state_class: measurement
accuracy_decimals: 0
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Runtime Remaining"
id: runtime_remaining
type: runtime
unit_of_measurement: "min"
device_class: duration
state_class: measurement
accuracy_decimals: 0
# Simulation validation script
script:
- id: simulation_demo
then:
- logger.log:
format: "SIMULATION DATA - Battery: %.1f%%, Load: %.1f%%, Input: %.1fV, Output: %.1fV"
args:
- "id(battery_level).state"
- "id(load_percentage).state"
- "id(input_voltage).state"
- "id(output_voltage).state"
level: INFO
# Demo data updates every 10 seconds
interval:
- interval: 10s
then:
- script.execute: simulation_demo
+70
View File
@@ -0,0 +1,70 @@
# UPS Control Buttons Package
# Beeper control and UPS testing functionality
# Use with: packages: !include configs/ups_controls.yaml
button:
# Beeper control buttons
- platform: ups_hid
ups_hid_id: ups_monitor
beeper_action: enable
name: "UPS Beeper Enable"
icon: "mdi:volume-high"
- platform: ups_hid
ups_hid_id: ups_monitor
beeper_action: disable
name: "UPS Beeper Disable"
icon: "mdi:volume-off"
- platform: ups_hid
ups_hid_id: ups_monitor
beeper_action: mute
name: "UPS Beeper Mute"
icon: "mdi:volume-mute"
# Note: Only effective during active alarms
- platform: ups_hid
ups_hid_id: ups_monitor
beeper_action: test
name: "UPS Beeper Test"
icon: "mdi:bell-ring"
# UPS testing buttons
- platform: ups_hid
ups_hid_id: ups_monitor
test_action: battery_quick
name: "UPS Quick Battery Test"
icon: "mdi:battery-check"
- platform: ups_hid
ups_hid_id: ups_monitor
test_action: battery_deep
name: "UPS Deep Battery Test"
icon: "mdi:battery-plus"
- platform: ups_hid
ups_hid_id: ups_monitor
test_action: battery_stop
name: "UPS Stop Battery Test"
icon: "mdi:battery-remove"
- platform: ups_hid
ups_hid_id: ups_monitor
test_action: ups_test
name: "UPS Panel Test"
icon: "mdi:test-tube"
- platform: ups_hid
ups_hid_id: ups_monitor
test_action: ups_stop
name: "UPS Stop Panel Test"
icon: "mdi:stop"
# Test result monitoring
text_sensor:
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Test Result"
id: ups_test_result
type: ups_test_result
icon: "mdi:test-tube"