feat(ups-hid): timer delay commands

Signed-off-by: bullshit <coding@ow-software.pl>
This commit is contained in:
bullshit committed 2025-08-26 09:27:32 +02:00
1 parent 58e5cc71f7
commit ae6cf92f27
19 files changed
+1008 -40

No files matched your search

+84
View File
@@ -0,0 +1,84 @@
# UPS Delay Configuration Package
# Provides configurable delay settings for shutdown, start, and reboot operations
# Use with: packages: delay_config: !include configs/delay_config.yaml
number:
# Shutdown delay configuration (0-600 seconds)
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Shutdown Delay"
id: ups_shutdown_delay_config
delay_type: shutdown
min_value: 0
max_value: 600
step: 10
unit_of_measurement: "s"
device_class: duration
entity_category: config
icon: "mdi:timer-settings"
mode: box
# Start/power-on delay configuration (0-600 seconds)
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Start Delay"
id: ups_start_delay_config
delay_type: start
min_value: 0
max_value: 600
step: 10
unit_of_measurement: "s"
device_class: duration
entity_category: config
icon: "mdi:timer-settings"
mode: box
# Reboot delay configuration (0-600 seconds)
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Reboot Delay"
id: ups_reboot_delay_config
delay_type: reboot
min_value: 0
max_value: 600
step: 10
unit_of_measurement: "s"
device_class: duration
entity_category: config
icon: "mdi:timer-settings"
mode: box
# Script to read current delay values from UPS
script:
- id: read_delay_configuration
then:
- logger.log:
format: "Current delay configuration - Shutdown: %.0fs, Start: %.0fs, Reboot: %.0fs"
args:
- "id(ups_shutdown_delay_config).state"
- "id(ups_start_delay_config).state"
- "id(ups_reboot_delay_config).state"
level: INFO
# Note: These show the configuration values, not the actual UPS timer values
- id: apply_default_delays
then:
# Apply common delay settings for your environment
- number.set:
id: ups_shutdown_delay_config
value: 60.0
- number.set:
id: ups_start_delay_config
value: 120.0
- number.set:
id: ups_reboot_delay_config
value: 60.0
- logger.log: "Applied default delay configuration"
# Expected Behavior:
# CyberPower: Full bidirectional support - read and write delays
# Generic HID: Attempts common report IDs - may work with many devices
# APC: Limited support - INPUT-ONLY devices cannot write delays
#
# Configuration changes are sent immediately to the UPS via USB HID SET_REPORT
# The UPS will store these values in non-volatile memory
+65 -1
View File
@@ -24,9 +24,15 @@ packages:
# Extended monitoring (optional - comment out if not needed)
extended: !include ../extended_sensors.yaml
# Timer countdown sensors (Real-time shutdown/startup monitoring)
timers: !include ../timer_sensors.yaml
# Control buttons (optional - comment out if not needed)
controls: !include ../ups_controls.yaml
# Delay configuration (Shutdown/Start/Reboot timers)
delay_config: !include ../delay_config.yaml
# APC-specific optimizations
apc_device: !include ../device_types/apc_backups_es.yaml
@@ -54,5 +60,63 @@ script:
level: INFO
# Add your notification logic here
- id: timer_countdown_alert
then:
- logger.log:
format: "TIMER COUNTDOWN - Shutdown: %.0fs, Start: %.0fs, Reboot: %.0fs (Active: %.0f, Fast Poll: %.0f)"
args:
- "id(ups_timer_shutdown).state"
- "id(ups_timer_start).state"
- "id(ups_timer_reboot).state"
- "id(active_timer_count).state"
- "id(fast_polling_status).state"
level: INFO
# Add critical countdown automation here (e.g., server shutdown at 30s)
- id: shutdown_warning_alert
then:
- if:
condition:
# Timer is actively counting down and less than 60 seconds
lambda: |-
float timer = id(ups_timer_shutdown).state;
return (!std::isnan(timer) && timer > 0 && timer < 60);
then:
- logger.log:
format: "CRITICAL: APC UPS SHUTTING DOWN IN %.0f SECONDS!"
args:
- "id(ups_timer_shutdown).state"
level: ERROR
# Add emergency server shutdown logic here
# Enhanced monitoring for APC timer functionality
interval:
# Monitor timer status every 15 seconds (component handles fast polling automatically)
- interval: 15s
then:
- script.execute: timer_countdown_alert
- script.execute: shutdown_warning_alert
# Expected Timer Behavior:
# Normal Operation:
# - ups_timer_shutdown: -1 (APC default inactive state)
# - ups_timer_start: -1 (APC reboot timer inactive)
# - ups_timer_reboot: -1 (same as shutdown)
# - active_timer_count: 0
# - fast_polling_status: 0
# - Component polls every 15 seconds (from device config)
# During UPS Shutdown:
# - ups_timer_shutdown: 20→19→18→17... (LIVE COUNTDOWN!)
# - Component automatically switches to 2-second polling
# - active_timer_count: 1
# - fast_polling_status: 1
# - Critical alerts trigger for emergency server shutdown
# During UPS Startup:
# - ups_timer_start: similar countdown behavior
# - Component uses 2-second fast polling
# - Coordination for sequential server startup
# Custom automations would be handled in Home Assistant
# The base sensors from base_ups.yaml and essential_sensors.yaml provide all the data needed
# The timer sensors enable sophisticated countdown-based automation
+6
View File
@@ -27,9 +27,15 @@ packages:
# Extended monitoring (recommended for CyberPower - rich sensor data)
extended: !include ../extended_sensors.yaml
# Timer countdown sensors (Real-time shutdown/startup monitoring)
timers: !include ../timer_sensors.yaml
# Control buttons (recommended - CyberPower has excellent beeper support)
controls: !include ../ups_controls.yaml
# Delay configuration (Shutdown/Start/Reboot timers)
delay_config: !include ../delay_config.yaml
# CyberPower-specific optimizations
cyberpower_device: !include ../device_types/cyberpower_cp1500.yaml
-34
View File
@@ -105,40 +105,6 @@ sensor:
state_class: measurement
accuracy_decimals: 0
# Enhanced dynamic timer sensors (countdown when active)
- 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
# Negative values indicate no active countdown
- 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
# Negative values indicate no active countdown
- 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
# Negative values indicate no active countdown
# Enhanced battery threshold monitoring
- platform: ups_hid
ups_hid_id: ups_monitor
+5 -1
View File
@@ -33,6 +33,10 @@ external_components:
type: local
path: ../../components
# Timer functionality package
packages:
timers: !include ../timer_sensors.yaml
# UPS component only
ups_hid:
id: ups_monitor
@@ -45,7 +49,7 @@ ups_hid:
button:
binary_sensor:
# Single sensor test
# Additional sensors for testing
sensor:
- platform: ups_hid
ups_hid_id: ups_monitor
+1
View File
@@ -19,6 +19,7 @@ packages:
base_ups: !include ../base_ups.yaml
essential: !include ../essential_sensors.yaml
extended: !include ../extended_sensors.yaml
timers: !include ../timer_sensors.yaml
controls: !include ../ups_controls.yaml
# Override for simulation testing
+105
View File
@@ -0,0 +1,105 @@
# Timer Sensors Package
# Real-time countdown timer sensors for UPS shutdown/startup sequences
# Use with: packages: timer_sensors: !include configs/timer_sensors.yaml
sensor:
# ==================== TIMER COUNTDOWN SENSORS ====================
# These sensors show REAL-TIME countdowns during UPS operations
# Normal operation: Negative values (e.g., -60, -120)
# Active countdown: Positive values (e.g., 60, 59, 58, 57...)
# Fast polling: Automatically switches to 2-second intervals during countdown
- 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
icon: "mdi:timer-outline"
# Shows countdown during UPS shutdown sequence (e.g., 60→59→58...)
# Negative during normal operation (e.g., -60)
- 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
icon: "mdi:timer-outline"
# Shows countdown during UPS startup sequence (e.g., 120→119→118...)
# Negative during normal operation (e.g., -120)
- 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
icon: "mdi:timer-outline"
# Shows countdown during UPS reboot sequence
# Negative during normal operation
# ==================== TIMER ANALYSIS SENSORS ====================
# Template sensors to analyze timer behavior and fast polling state
- platform: template
name: "Active Timer Count"
id: active_timer_count
icon: "mdi:timer-alert-outline"
lambda: |-
// Count how many timers are actively counting down (positive values)
int active_count = 0;
float shutdown_timer = id(ups_timer_shutdown).state;
float start_timer = id(ups_timer_start).state;
float reboot_timer = id(ups_timer_reboot).state;
if (!std::isnan(shutdown_timer) && shutdown_timer > 0) active_count++;
if (!std::isnan(start_timer) && start_timer > 0) active_count++;
if (!std::isnan(reboot_timer) && reboot_timer > 0) active_count++;
return (float)active_count;
update_interval: 2s
# 0 = No active countdowns, >0 = Timers are counting down
- platform: template
name: "Fast Polling Status"
id: fast_polling_status
icon: "mdi:speedometer"
lambda: |-
// Indicates when fast polling should be active
float active_timers = id(active_timer_count).state;
return (!std::isnan(active_timers) && active_timers > 0) ? 1.0 : 0.0;
update_interval: 2s
# 1 = Fast polling active (2s intervals), 0 = Normal polling (30s intervals)
# ==================== EXPECTED BEHAVIOR ====================
# Normal Operation (Simulation/No UPS Activity):
# - ups_timer_shutdown: -60 (APC: -20, CyberPower: -60)
# - ups_timer_start: -120 (CyberPower), -60 (APC reboot timer)
# - ups_timer_reboot: -60 (varies by protocol)
# - ups_delay_shutdown: 60 (static config)
# - ups_delay_start: 120 (static config)
# - active_timer_count: 0
# - fast_polling_status: 0
# During UPS Shutdown Sequence (Real Hardware):
# - ups_timer_shutdown: 60→59→58→57... (live countdown!)
# - Component switches to 2-second polling automatically
# - active_timer_count: 1
# - fast_polling_status: 1
# - Home Assistant sees real-time countdown updates
# During UPS Startup Sequence (Real Hardware):
# - ups_timer_start: 120→119→118→117... (live countdown!)
# - Component uses fast polling (2-second intervals)
# - active_timer_count: 1
# - fast_polling_status: 1