Public Access
623 lines
17 KiB
YAML
623 lines
17 KiB
YAML
substitutions:
|
|
name: ups-hid-monitor-full-test
|
|
friendly_name: "UPS HID Monitor"
|
|
timezone: "America/New_York"
|
|
|
|
esphome:
|
|
name: "${name}"
|
|
friendly_name: "${friendly_name}"
|
|
comment: "Full test configuration for UPS HID Component with ESP32-S3"
|
|
|
|
esp32:
|
|
board: esp32-s3-devkitc-1
|
|
flash_size: 16MB
|
|
framework:
|
|
type: esp-idf
|
|
version: 5.3.2
|
|
|
|
# Enable logging with verbose output for debugging
|
|
logger:
|
|
level: VERBOSE
|
|
logs:
|
|
ups_hid: DEBUG
|
|
usb_host: VERBOSE
|
|
usb-host: VERBOSE
|
|
USB_HOST: VERBOSE
|
|
hcd: VERBOSE
|
|
HCD: VERBOSE
|
|
hub: VERBOSE
|
|
HUB: VERBOSE
|
|
usbh: VERBOSE
|
|
USBH: VERBOSE
|
|
baud_rate: 115200
|
|
hardware_uart: UART0
|
|
|
|
# Enable Home Assistant API
|
|
api:
|
|
encryption:
|
|
key: !secret api_encryption_key
|
|
|
|
# Enable OTA updates
|
|
ota:
|
|
- platform: esphome
|
|
password: !secret ota_password
|
|
|
|
# WiFi configuration
|
|
wifi:
|
|
ssid: !secret wifi_ssid
|
|
password: !secret wifi_password
|
|
ap:
|
|
ssid: "${friendly_name} Fallback"
|
|
password: !secret ap_password
|
|
|
|
# Captive portal for easy WiFi setup
|
|
captive_portal:
|
|
|
|
# Optional web server for local monitoring
|
|
web_server:
|
|
port: 80
|
|
|
|
# Time component for accurate timestamps
|
|
time:
|
|
- platform: sntp
|
|
id: sntp_time
|
|
timezone: "${timezone}"
|
|
|
|
# RGB LED for UPS status indication (GPIO38 on ESP32-S3-DevKitC-1)
|
|
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
|
|
effects:
|
|
# Critical conditions - Fast red strobe (unmistakable emergency pattern)
|
|
- strobe:
|
|
name: "Critical Alert"
|
|
colors:
|
|
- state: true
|
|
brightness: 100%
|
|
red: 100%
|
|
green: 0%
|
|
blue: 0%
|
|
duration: 150ms
|
|
- state: false
|
|
duration: 150ms
|
|
|
|
# Battery operation - Slow orange fade (amber warning pattern)
|
|
- pulse:
|
|
name: "Battery Warning"
|
|
transition_length: 1.5s
|
|
update_interval: 1.5s
|
|
min_brightness: 10%
|
|
max_brightness: 95%
|
|
|
|
# Charging status - Quick yellow double-blink (charging pattern)
|
|
- strobe:
|
|
name: "Charging Pattern"
|
|
colors:
|
|
- state: true
|
|
brightness: 80%
|
|
red: 100%
|
|
green: 100%
|
|
blue: 0%
|
|
duration: 200ms
|
|
- state: false
|
|
duration: 200ms
|
|
- state: true
|
|
brightness: 80%
|
|
red: 100%
|
|
green: 100%
|
|
blue: 0%
|
|
duration: 200ms
|
|
- state: false
|
|
duration: 1400ms
|
|
|
|
# Normal operation - Slow green breathing (peaceful pattern)
|
|
- pulse:
|
|
name: "Normal Status"
|
|
transition_length: 3s
|
|
update_interval: 3s
|
|
min_brightness: 20%
|
|
max_brightness: 60%
|
|
|
|
# Fault/offline - Blue fade (distinct from other states)
|
|
- pulse:
|
|
name: "System Offline"
|
|
transition_length: 2s
|
|
update_interval: 2s
|
|
min_brightness: 5%
|
|
max_brightness: 40%
|
|
|
|
# External components - using local path for development
|
|
external_components:
|
|
- source:
|
|
type: local
|
|
path: components
|
|
|
|
# Main UPS HID Component Configuration
|
|
ups_hid:
|
|
id: ups_monitor
|
|
update_interval: 10s
|
|
|
|
# Component now auto-detects all USB devices and protocols
|
|
# Manual USB IDs only needed for troubleshooting when auto-detection fails:
|
|
#usb_vendor_id: 0x051d # APC vendor ID (uncomment if auto-detection fails)
|
|
#usb_product_id: 0x0002 # APC Back-UPS ES series
|
|
#usb_vendor_id: 0x0764 # CyberPower (uncomment if auto-detection fails)
|
|
#usb_product_id: 0x0501 # CP1500 AVR UPS
|
|
|
|
# Protocol Configuration
|
|
auto_detect_protocol: true
|
|
protocol_timeout: 15s
|
|
|
|
# Development/Testing Configuration
|
|
simulation_mode: false # Set to false for production with real hardware
|
|
|
|
# Numeric Sensors
|
|
sensor:
|
|
# Essential UPS metrics
|
|
- 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
|
|
|
|
- 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
|
|
# Note: Input frequency is not available on CyberPower CP1500 model
|
|
|
|
# Additional CyberPower sensors (newly implemented)
|
|
# All sensors based on NUT debug data for CP1500EPFCLCD model
|
|
# Available sensor types: battery_voltage, battery_voltage_nominal,
|
|
# input_voltage_nominal, input_transfer_low, input_transfer_high,
|
|
# ups_realpower_nominal, ups_delay_shutdown, ups_delay_start
|
|
- 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
|
|
|
|
- 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: "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
|
|
|
|
# System sensors for monitoring ESP32 health
|
|
- platform: uptime
|
|
name: "Uptime"
|
|
id: uptime_sensor
|
|
update_interval: 60s
|
|
|
|
- platform: wifi_signal
|
|
name: "WiFi Signal"
|
|
id: wifi_signal_sensor
|
|
update_interval: 60s
|
|
|
|
# Internal ESP32 temperature sensor
|
|
- platform: internal_temperature
|
|
name: "ESP32 Temperature"
|
|
id: esp32_temp
|
|
update_interval: 30s
|
|
|
|
# Power calculations
|
|
- 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
|
|
|
|
// Try to use HID nominal power data (CyberPower)
|
|
if (!std::isnan(id(ups_realpower_nominal).state)) {
|
|
ups_max_power = id(ups_realpower_nominal).state;
|
|
}
|
|
// Otherwise, estimate based on detected protocol/manufacturer
|
|
else {
|
|
std::string manufacturer = id(ups_manufacturer).state;
|
|
std::string model = id(ups_model).state;
|
|
|
|
// CyberPower models
|
|
if (manufacturer == "CPS") {
|
|
if (model.find("CP1500") != std::string::npos) {
|
|
ups_max_power = 900.0; // CP1500EPFCLCD: 900W
|
|
} else if (model.find("CP1000") != std::string::npos) {
|
|
ups_max_power = 600.0; // CP1000 series: ~600W
|
|
} else if (model.find("CP750") != std::string::npos) {
|
|
ups_max_power = 450.0; // CP750 series: ~450W
|
|
}
|
|
}
|
|
// APC models
|
|
else if (manufacturer == "APC") {
|
|
if (model.find("ES 700") != std::string::npos || model.find("Back-UPS ES") != std::string::npos) {
|
|
ups_max_power = 405.0; // APC Back-UPS ES 700: 405W
|
|
} else if (model.find("ES 550") != std::string::npos) {
|
|
ups_max_power = 330.0; // APC Back-UPS ES 550: 330W
|
|
} else if (model.find("ES 750") != std::string::npos) {
|
|
ups_max_power = 450.0; // APC Back-UPS ES 750: 450W
|
|
}
|
|
}
|
|
}
|
|
|
|
float current_power = (ups_max_power * id(load_percentage).state) / 100.0;
|
|
return current_power;
|
|
}
|
|
return NAN;
|
|
update_interval: 30s
|
|
|
|
# Binary Sensors for UPS status
|
|
binary_sensor:
|
|
- platform: ups_hid
|
|
ups_hid_id: ups_monitor
|
|
name: "UPS Online"
|
|
id: ups_online
|
|
type: online
|
|
device_class: connectivity
|
|
on_press:
|
|
then:
|
|
- script.execute: power_restored
|
|
on_release:
|
|
then:
|
|
- logger.log:
|
|
format: "POWER OUTAGE: UPS switched to battery power"
|
|
level: WARN
|
|
|
|
- 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
|
|
on_press:
|
|
then:
|
|
- script.execute: ups_shutdown_warning
|
|
- script.execute: notify_critical
|
|
|
|
- platform: ups_hid
|
|
ups_hid_id: ups_monitor
|
|
name: "UPS Fault"
|
|
id: ups_fault
|
|
type: fault
|
|
device_class: problem
|
|
|
|
- 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
|
|
|
|
# Temperature warning
|
|
- platform: template
|
|
name: "High Temperature Warning"
|
|
id: high_temp_warning
|
|
device_class: heat
|
|
lambda: |-
|
|
if (!std::isnan(id(esp32_temp).state)) {
|
|
return id(esp32_temp).state > 70.0; // Warning at 70°C
|
|
}
|
|
return false;
|
|
|
|
# Text Sensors for UPS information
|
|
text_sensor:
|
|
- platform: ups_hid
|
|
ups_hid_id: ups_monitor
|
|
name: "UPS Model"
|
|
id: ups_model
|
|
type: model
|
|
|
|
- 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 Status"
|
|
id: ups_status_text
|
|
type: status
|
|
|
|
- platform: ups_hid
|
|
ups_hid_id: ups_monitor
|
|
name: "Detected Protocol"
|
|
id: ups_protocol
|
|
type: protocol
|
|
|
|
# Additional CyberPower text sensors (newly implemented)
|
|
# Available text sensor types: ups_beeper_status, input_sensitivity
|
|
- 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
|
|
|
|
# System text sensors
|
|
- platform: version
|
|
name: "ESPHome Version"
|
|
id: esphome_version
|
|
|
|
- platform: wifi_info
|
|
ip_address:
|
|
name: "IP Address"
|
|
id: ip_address
|
|
ssid:
|
|
name: "Connected SSID"
|
|
id: connected_ssid
|
|
|
|
# Last event timestamp
|
|
- platform: template
|
|
name: "Last UPS Event"
|
|
id: last_ups_event
|
|
lambda: |-
|
|
static std::string last_event = "System Started";
|
|
static bool last_online = true;
|
|
static bool last_low_battery = false;
|
|
|
|
if (id(ups_online).state != last_online) {
|
|
if (id(ups_online).state) {
|
|
last_event = "UPS Online";
|
|
} else {
|
|
last_event = "UPS Offline";
|
|
}
|
|
last_online = id(ups_online).state;
|
|
}
|
|
|
|
if (id(low_battery).state != last_low_battery) {
|
|
if (id(low_battery).state) {
|
|
last_event = "Low Battery Alert";
|
|
} else {
|
|
last_event = "Battery Level Normal";
|
|
}
|
|
last_low_battery = id(low_battery).state;
|
|
}
|
|
|
|
return last_event;
|
|
|
|
# Advanced LED Status Control with Priorities
|
|
interval:
|
|
- interval: 2s
|
|
then:
|
|
- lambda: |-
|
|
// Enhanced UPS status LED control with distinct visual patterns
|
|
// Each state now has a unique color and pattern combination
|
|
|
|
// CRITICAL CONDITIONS (Priority 1) - Fast red strobe
|
|
if (id(low_battery).state || id(ups_fault).state || id(overload_warning).state) {
|
|
auto call = id(ups_status_led).turn_on();
|
|
call.set_rgb(1.0, 0.0, 0.0); // Bright red
|
|
call.set_effect("Critical Alert");
|
|
call.perform();
|
|
}
|
|
// BATTERY OPERATION (Priority 2) - Orange slow fade
|
|
else if (id(on_battery).state && !id(low_battery).state) {
|
|
auto call = id(ups_status_led).turn_on();
|
|
call.set_rgb(1.0, 0.5, 0.0); // Orange amber
|
|
call.set_effect("Battery Warning");
|
|
call.perform();
|
|
}
|
|
// CHARGING STATUS (Priority 3) - Yellow double-blink pattern
|
|
else if (id(battery_charging).state && id(ups_online).state) {
|
|
auto call = id(ups_status_led).turn_on();
|
|
call.set_rgb(1.0, 1.0, 0.0); // Yellow
|
|
call.set_effect("Charging Pattern");
|
|
call.perform();
|
|
}
|
|
// NORMAL OPERATION (Priority 4) - Gentle green breathing
|
|
else if (id(ups_online).state && !id(on_battery).state) {
|
|
auto call = id(ups_status_led).turn_on();
|
|
call.set_rgb(0.0, 1.0, 0.0); // Green
|
|
call.set_effect("Normal Status");
|
|
call.perform();
|
|
}
|
|
// OFFLINE/UNKNOWN (Priority 5) - Dim blue fade
|
|
else {
|
|
auto call = id(ups_status_led).turn_on();
|
|
call.set_rgb(0.0, 0.3, 1.0); // Blue
|
|
call.set_effect("System Offline");
|
|
call.perform();
|
|
}
|
|
|
|
# Automated scripts for notifications and actions
|
|
script:
|
|
- id: notify_critical
|
|
then:
|
|
- logger.log:
|
|
format: "CRITICAL UPS EVENT: Battery=%.1f%%, Runtime=%.1f min, Status=%s"
|
|
args:
|
|
[
|
|
"id(battery_level).state",
|
|
"id(runtime_remaining).state",
|
|
"id(ups_status_text).state.c_str()",
|
|
]
|
|
level: ERROR
|
|
|
|
- id: ups_shutdown_warning
|
|
then:
|
|
- logger.log:
|
|
format: "UPS SHUTDOWN WARNING: Battery critically low, runtime remaining: %.1f minutes"
|
|
args: ["id(runtime_remaining).state"]
|
|
level: WARN
|
|
# Add your shutdown logic here if needed
|
|
|
|
- id: power_restored
|
|
then:
|
|
- logger.log:
|
|
format: "POWER RESTORED: UPS back online, battery at %.1f%%"
|
|
args: ["id(battery_level).state"]
|
|
level: INFO
|
|
|
|
# Home Assistant Dashboard Integration Helper
|
|
# Uncomment and customize for your Home Assistant setup
|
|
# homeassistant:
|
|
# service: notify.mobile_app_your_phone
|
|
# data:
|
|
# title: "UPS Alert"
|
|
# message: "UPS is running on battery power!"
|
|
# condition:
|
|
# - binary_sensor.is_on: on_battery
|
|
# - binary_sensor.is_off: low_battery
|
|
|
|
# Example automation for critical battery
|
|
# on_...:
|
|
# - platform: state
|
|
# entity_id: binary_sensor.low_battery
|
|
# to: "on"
|
|
# then:
|
|
# - script.execute: notify_critical
|
|
|
|
# Development/Debug helpers
|
|
debug:
|
|
update_interval: 30s
|
|
|
|
# Enable safe mode for recovery
|
|
safe_mode:
|
|
disabled: false
|
|
# Note: Additional automations can be added in Home Assistant
|