Public Access
feat(ups-status-led): ups led controller component
Signed-off-by: bullshit <coding@ow-software.pl>
This commit is contained in:
17 files changed
+1413
-243
No files matched your search
+95
-15
@@ -11,10 +11,18 @@ 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.
|
||||
- **Data Provider Pattern**: Components can access UPS data directly (no sensor entities required!)
|
||||
- **Optional sensors**: Only `status` and `protocol` text sensors (for Home Assistant integration)
|
||||
|
||||
#### `base_ups_with_led.yaml`
|
||||
Complete UPS monitoring with automatic LED status indication:
|
||||
- Includes all `base_ups.yaml` functionality
|
||||
- **Automatic LED Package**: Integrates `ups_status_led.yaml`
|
||||
- **Smart Status Display**: 7 priority-based LED patterns
|
||||
- **Night Mode**: Time-based dimming with Home Assistant control
|
||||
- **Zero Configuration**: Works immediately with substitution customization
|
||||
- **Hardware Flexible**: Compatible with any ESPHome light component
|
||||
|
||||
#### `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`
|
||||
@@ -26,6 +34,35 @@ Core monitoring sensors (5 sensors) available on all protocols:
|
||||
|
||||
### **Optional Enhancement Packages**
|
||||
|
||||
#### `ups_status_led.yaml`
|
||||
Automatic LED status indication using smart patterns:
|
||||
|
||||
**Hardware Integration**:
|
||||
- Works with any ESPHome light component (WS2812, FastLED, etc.)
|
||||
- Hardware abstraction layer for maximum compatibility
|
||||
|
||||
**Smart Pattern System** (priority-based, automatic selection with solid colors):
|
||||
- **🔴 Critical Alert** (solid red) - Low battery/fault/overload
|
||||
- **🟠 Battery Power** (solid orange) - Running on battery
|
||||
- **🟡 Charging** (solid yellow) - Battery charging
|
||||
- **🟢 Normal** (solid green) - Normal operation
|
||||
- **🔵 UPS Offline** (solid blue) - UPS disconnected
|
||||
- **🟣 No Data** (solid purple) - Component connected but no data
|
||||
- **⚪ Error** (solid white) - Component error
|
||||
|
||||
**Advanced Features**:
|
||||
- **Battery-aware Colors**: Discrete thresholds or smooth gradients
|
||||
- **Night Mode**: Time-based dimming with Home Assistant control
|
||||
- **Home Assistant Integration**: Auto-created entities for complete control
|
||||
|
||||
**Automatic Entity Creation**:
|
||||
- `switch.ups_status_led` (master enable/disable)
|
||||
- `switch.ups_led_night_mode` (night mode toggle)
|
||||
- `number.ups_led_brightness` (brightness 10-100%)
|
||||
- `text_sensor.ups_led_pattern` (current pattern name)
|
||||
|
||||
**Uses Data Provider Pattern**: No sensor entities required - accesses UPS data directly via `id(ups_monitor).is_online()`, etc.
|
||||
|
||||
#### `extended_sensors.yaml` / `extended_sensors_grouped.yaml`
|
||||
Advanced monitoring (17 additional sensors) for feature-rich devices:
|
||||
|
||||
@@ -186,22 +223,57 @@ packages:
|
||||
- Comprehensive validation of data provider pattern
|
||||
- **Use for**: Testing component as pure data provider, custom automation development
|
||||
|
||||
### `testing/led_status_test.yaml`
|
||||
UPS Status LED component comprehensive testing:
|
||||
```yaml
|
||||
substitutions:
|
||||
simulation_mode: "true" # Test without hardware
|
||||
led_color_mode: "gradient" # Test gradient colors
|
||||
packages:
|
||||
base_with_led: !include ../base_ups_with_led.yaml
|
||||
```
|
||||
**Features**:
|
||||
- Tests all 7 LED patterns with simulated UPS states
|
||||
- Battery-aware gradient color calculation verification
|
||||
- Night mode with time-based scheduling testing
|
||||
- Home Assistant integration validation (4 auto-created entities)
|
||||
- Performance optimization verification (10Hz updates)
|
||||
- **Use for**: LED component development, pattern testing, HA integration validation
|
||||
|
||||
### `testing/ups_with_smart_led.yaml`
|
||||
Complete smart LED integration testing:
|
||||
```yaml
|
||||
substitutions:
|
||||
led_brightness: "90%"
|
||||
led_color_mode: "gradient"
|
||||
timezone: "America/New_York"
|
||||
packages:
|
||||
base_with_led: !include ../base_ups_with_led.yaml
|
||||
essential: !include ../essential_sensors.yaml
|
||||
```
|
||||
**Features**:
|
||||
- Full LED + sensor integration testing
|
||||
- Customizable substitutions validation
|
||||
- Advanced features testing (battery gradients, timezone support)
|
||||
- Complete Home Assistant entity creation
|
||||
- **Use for**: Integration testing, configuration validation
|
||||
|
||||
## 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
|
||||
Complete APC UPS production configuration with LED status indication:
|
||||
- **Smart LED Integration**: Uses `base_ups_with_led.yaml` for automatic status display
|
||||
- Modular package composition with device-specific optimizations
|
||||
- Custom automation examples and notification setup
|
||||
- Choice of standard or grouped entity layout
|
||||
- APC-specific timer monitoring and power outage handling
|
||||
|
||||
### `examples/rack-ups-monitor.yaml`
|
||||
Complete CyberPower UPS production configuration:
|
||||
- Advanced sensor utilization
|
||||
- Smart threshold monitoring
|
||||
- Rich data analysis
|
||||
- Enhanced automation
|
||||
Complete CyberPower UPS production configuration with LED status indication:
|
||||
- **Smart LED Integration**: Uses `base_ups_with_led.yaml` for automatic status display
|
||||
- Advanced sensor utilization with rich CyberPower data
|
||||
- Smart threshold monitoring and power analysis
|
||||
- Enhanced automation with battery threshold alerts
|
||||
- Choice of standard or grouped entity layout
|
||||
|
||||
### `examples/grouped-ups-monitor.yaml`
|
||||
@@ -221,7 +293,15 @@ packages:
|
||||
```
|
||||
**Result**: ~150 lines → Essential monitoring only
|
||||
|
||||
### 2. Full-Featured UPS
|
||||
### 2. UPS with Smart LED Status
|
||||
```yaml
|
||||
packages:
|
||||
base_with_led: !include configs/base_ups_with_led.yaml
|
||||
essential: !include configs/essential_sensors.yaml
|
||||
```
|
||||
**Result**: ~200 lines → Essential monitoring + automatic LED status indication
|
||||
|
||||
### 3. Full-Featured UPS
|
||||
```yaml
|
||||
packages:
|
||||
base_ups: !include configs/base_ups.yaml
|
||||
@@ -234,7 +314,7 @@ packages:
|
||||
```
|
||||
**Result**: ~380 lines → Complete functionality with UPS configuration
|
||||
|
||||
### 3. Organized Interface UPS
|
||||
### 4. Organized Interface UPS
|
||||
```yaml
|
||||
packages:
|
||||
# Enable organized web interface
|
||||
@@ -251,7 +331,7 @@ packages:
|
||||
```
|
||||
**Result**: Same functionality with organized web interface layout
|
||||
|
||||
### 4. Custom Configuration
|
||||
### 5. Custom Configuration
|
||||
```yaml
|
||||
substitutions:
|
||||
name: "my-custom-ups"
|
||||
|
||||
+8
-61
@@ -71,67 +71,14 @@ ups_hid:
|
||||
fallback_nominal_voltage: 230V # European standard (IEC 60038) for better international compatibility
|
||||
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 (no sensor entities required!)
|
||||
interval:
|
||||
- interval: 2s
|
||||
then:
|
||||
- lambda: |-
|
||||
// Direct access to UPS data - no sensor entities needed
|
||||
if (id(ups_monitor).is_low_battery() || id(ups_monitor).has_fault()) {
|
||||
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(ups_monitor).is_on_battery()) {
|
||||
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_monitor).is_online()) {
|
||||
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();
|
||||
}
|
||||
|
||||
# Note: Binary sensors are now completely OPTIONAL!
|
||||
# Only define them if you need Home Assistant entities
|
||||
# The LED automation above works without any sensor entities
|
||||
# Note: Status LED has been moved to a separate package for better modularity
|
||||
# To enable automatic LED status indication, include the ups_status_led package:
|
||||
#
|
||||
# packages:
|
||||
# status_led: !include ups_status_led.yaml
|
||||
#
|
||||
# This provides automatic LED control with night mode, Home Assistant integration,
|
||||
# and smart pattern management - no manual automation needed!
|
||||
|
||||
# Essential text sensors
|
||||
text_sensor:
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
# Base UPS Configuration with Status LED
|
||||
# Combines base_ups.yaml with the new ups_status_led component
|
||||
# Use this for complete UPS monitoring with automatic LED indication
|
||||
|
||||
packages:
|
||||
base: !include base_ups.yaml
|
||||
led: !include ups_status_led.yaml
|
||||
led_controls: !include ups_led_controls.yaml
|
||||
|
||||
# Optional substitutions for LED customization
|
||||
substitutions:
|
||||
# LED hardware configuration
|
||||
led_pin: "GPIO48" # LED data pin
|
||||
|
||||
# LED behavior
|
||||
led_brightness: "80%" # Default brightness
|
||||
led_color_mode: "gradient" # gradient or discrete
|
||||
|
||||
# Night mode settings
|
||||
led_night_mode_enabled: "true" # Enable night mode
|
||||
led_night_brightness: "30%" # Dimmed brightness (30% of day brightness)
|
||||
led_night_start: "22:00" # Night mode start
|
||||
led_night_end: "07:00" # Night mode end
|
||||
|
||||
# This configuration provides:
|
||||
# - All base UPS functionality
|
||||
# - Automatic LED status indication with 7 solid color patterns
|
||||
# - Night mode with time-based dimming
|
||||
# - Home Assistant controls for LED
|
||||
# - Battery-aware color display (discrete/gradient modes)
|
||||
# - No manual automation required!
|
||||
@@ -29,6 +29,7 @@ logger:
|
||||
ups_hid: DEBUG
|
||||
ups_hid.apc: DEBUG
|
||||
ups_hid.apc_hid: DEBUG
|
||||
ups_status_led: DEBUG
|
||||
|
||||
# APC-specific power calculations
|
||||
sensor:
|
||||
|
||||
@@ -31,6 +31,11 @@ web_server:
|
||||
name: "⚙️ Configuration"
|
||||
sorting_weight: 60
|
||||
|
||||
# LED status indication
|
||||
- id: ups_led_controls
|
||||
name: "💡 LED Status Controls"
|
||||
sorting_weight: 65
|
||||
|
||||
# Control groups
|
||||
- id: ups_beeper_controls
|
||||
name: "🔔 Beeper Controls"
|
||||
|
||||
@@ -21,8 +21,8 @@ packages:
|
||||
# Uncomment to enable organized entity groups in ESPHome web interface
|
||||
entity_groups: !include ../entity_groups.yaml
|
||||
|
||||
# Core functionality
|
||||
base_ups: !include ../base_ups.yaml
|
||||
# Core functionality with LED status indication
|
||||
base_with_led: !include ../base_ups_with_led.yaml
|
||||
|
||||
# Choose EITHER grouped OR standard sensor packages (not both):
|
||||
# Standard packages (current default):
|
||||
|
||||
@@ -24,8 +24,8 @@ packages:
|
||||
# Uncomment to enable organized entity groups in ESPHome web interface
|
||||
entity_groups: !include ../entity_groups.yaml
|
||||
|
||||
# Core functionality
|
||||
base_ups: !include ../base_ups.yaml
|
||||
# Core functionality with LED status indication
|
||||
base_with_led: !include ../base_ups_with_led.yaml
|
||||
|
||||
# Choose EITHER grouped OR standard sensor packages (not both):
|
||||
# Standard packages (current default):
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
# LED Status Component Testing Configuration
|
||||
# Tests the ups_status_led component with all features enabled
|
||||
# Uses simulation mode for testing without physical UPS hardware
|
||||
|
||||
substitutions:
|
||||
name: "led-status-test"
|
||||
friendly_name: "LED Status Test"
|
||||
|
||||
# Enable simulation for testing
|
||||
simulation_mode: "true"
|
||||
update_interval: "5s" # Fast updates for testing
|
||||
|
||||
# LED testing configuration
|
||||
led_pin: "GPIO48"
|
||||
led_brightness: "75%"
|
||||
led_color_mode: "gradient" # Test gradient mode
|
||||
|
||||
# Night mode testing
|
||||
led_night_mode_enabled: "true"
|
||||
led_night_brightness: "20%"
|
||||
led_night_start: "20:00" # Early for testing
|
||||
led_night_end: "08:00"
|
||||
|
||||
# Timezone for night mode testing
|
||||
timezone: "UTC" # Use UTC for consistent testing
|
||||
|
||||
esphome:
|
||||
name: ${name}
|
||||
friendly_name: ${friendly_name}
|
||||
|
||||
# Use minimal base UPS configuration (without all packages)
|
||||
packages:
|
||||
base_ups: !include ../base_ups.yaml
|
||||
|
||||
# Add time component for LED night mode (required by ups_status_led)
|
||||
time:
|
||||
- platform: sntp
|
||||
id: sntp_time
|
||||
timezone: ${timezone}
|
||||
servers:
|
||||
- pool.ntp.org
|
||||
- time.nist.gov
|
||||
|
||||
# Add LED package manually for testing
|
||||
light:
|
||||
- platform: esp32_rmt_led_strip
|
||||
chipset: WS2812
|
||||
pin: ${led_pin}
|
||||
num_leds: 1
|
||||
rgb_order: GRB
|
||||
name: "UPS Status LED Hardware"
|
||||
id: ups_status_led_hw
|
||||
internal: true
|
||||
restore_mode: ALWAYS_OFF
|
||||
|
||||
# UPS Status LED Component
|
||||
ups_status_led:
|
||||
id: ups_led_controller
|
||||
ups_hid_id: ups_monitor
|
||||
light_id: ups_status_led_hw
|
||||
time_id: sntp_time
|
||||
|
||||
enabled: true
|
||||
brightness: ${led_brightness}
|
||||
battery_color_mode: ${led_color_mode}
|
||||
battery_low_threshold: 20
|
||||
battery_warning_threshold: 50
|
||||
|
||||
night_mode:
|
||||
enabled: ${led_night_mode_enabled}
|
||||
brightness: ${led_night_brightness}
|
||||
start_time: ${led_night_start}
|
||||
end_time: ${led_night_end}
|
||||
|
||||
# Enable required platforms for UPS HID component
|
||||
sensor:
|
||||
binary_sensor:
|
||||
button:
|
||||
|
||||
# Testing features:
|
||||
#
|
||||
# LED Pattern Testing (automatic, priority-based, solid colors):
|
||||
# LED Patterns:
|
||||
# 🔴 Critical Alert (solid red) - Low battery/fault/overload
|
||||
# 🟠 Battery Power (solid orange) - Running on battery
|
||||
# 🟡 Charging (solid yellow) - Battery charging
|
||||
# 🟢 Normal (solid green) - Normal operation
|
||||
# 🔵 UPS Offline (solid blue) - UPS disconnected
|
||||
# 🟣 No Data (solid purple) - Component connected but no data
|
||||
# ⚪ Error (solid white) - Component error
|
||||
#
|
||||
# Home Assistant Entities (auto-created):
|
||||
# - switch.led_status_test_enabled_switch (master LED control)
|
||||
# - switch.led_status_test_night_switch (night mode toggle)
|
||||
# - number.led_status_test_brightness_number (brightness slider)
|
||||
# - text_sensor.led_status_test_status_sensor (current pattern)
|
||||
#
|
||||
# Testing Capabilities:
|
||||
# ✅ All 7 LED patterns with simulated UPS states
|
||||
# ✅ Battery-aware gradient color calculation
|
||||
# ✅ Night mode with time-based scheduling
|
||||
# ✅ Home Assistant integration and control
|
||||
# ✅ Data provider pattern usage (no sensors required)
|
||||
# ✅ Performance optimization verification (10Hz updates, solid colors)
|
||||
# ✅ Hardware abstraction (WS2812 LED strip)
|
||||
#
|
||||
# Usage:
|
||||
# 1. Compile: esphome config configs/testing/led_status_test.yaml
|
||||
# 2. Flash to ESP32-S3 with connected WS2812 LED
|
||||
# 3. Monitor patterns change based on simulated UPS states
|
||||
# 4. Test Home Assistant controls through web interface
|
||||
# 5. Verify night mode activation/deactivation
|
||||
@@ -14,7 +14,7 @@ esphome:
|
||||
|
||||
# Use base UPS configuration (now has optional sensors)
|
||||
packages:
|
||||
base_ups: !include base_ups.yaml
|
||||
base_ups: !include ../base_ups.yaml
|
||||
|
||||
# ZERO sensor entities defined - testing pure data provider mode!
|
||||
|
||||
@@ -59,27 +59,27 @@ interval:
|
||||
switch(test_phase) {
|
||||
case 0: // Test critical state display
|
||||
if (id(ups_monitor).is_low_battery() || id(ups_monitor).has_fault()) {
|
||||
ESP_LOGI("led_test", "Critical state detected - RED strobe should be active");
|
||||
ESP_LOGI("led_test", "Critical state detected - RED solid should be active");
|
||||
}
|
||||
break;
|
||||
case 1: // Test battery operation
|
||||
if (id(ups_monitor).is_on_battery()) {
|
||||
ESP_LOGI("led_test", "Battery operation - ORANGE fade should be active");
|
||||
ESP_LOGI("led_test", "Battery operation - ORANGE solid should be active");
|
||||
}
|
||||
break;
|
||||
case 2: // Test charging state
|
||||
if (id(ups_monitor).is_charging()) {
|
||||
ESP_LOGI("led_test", "Charging state - YELLOW pattern should be active");
|
||||
ESP_LOGI("led_test", "Charging state - YELLOW solid should be active");
|
||||
}
|
||||
break;
|
||||
case 3: // Test normal operation
|
||||
if (id(ups_monitor).is_online()) {
|
||||
ESP_LOGI("led_test", "Normal operation - GREEN breathing should be active");
|
||||
ESP_LOGI("led_test", "Normal operation - GREEN solid should be active");
|
||||
}
|
||||
break;
|
||||
case 4: // Test offline state
|
||||
if (!id(ups_monitor).is_online()) {
|
||||
ESP_LOGI("led_test", "Offline state - BLUE fade should be active");
|
||||
ESP_LOGI("led_test", "Offline state - BLUE solid should be active");
|
||||
}
|
||||
break;
|
||||
case 5: // Data provider mode validation
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
# North American Regional Template Test Configuration
|
||||
# Tests North American regional defaults (120V/60Hz)
|
||||
# Use: esphome compile configs/testing/north_american_template_test.yaml
|
||||
|
||||
substitutions:
|
||||
name: "north-american-test"
|
||||
friendly_name: "North American Test"
|
||||
simulation_mode: "true" # Safe testing without hardware
|
||||
|
||||
esphome:
|
||||
name: "${name}"
|
||||
friendly_name: "${friendly_name}"
|
||||
comment: "Testing North American regional template (120V/60Hz)"
|
||||
|
||||
# Core ESP32 configuration
|
||||
esp32:
|
||||
board: esp32-s3-devkitc-1
|
||||
framework:
|
||||
type: esp-idf
|
||||
|
||||
# Minimal logging
|
||||
logger:
|
||||
level: INFO
|
||||
baud_rate: 115200
|
||||
|
||||
# Basic network
|
||||
wifi:
|
||||
ssid: "TestNetwork"
|
||||
password: "TestPassword"
|
||||
|
||||
# External components
|
||||
external_components:
|
||||
- source:
|
||||
type: local
|
||||
path: ../../components
|
||||
|
||||
# Use North American regional template
|
||||
packages:
|
||||
regional_defaults: !include ../regional/north_american_defaults.yaml
|
||||
|
||||
# UPS component (inherits North American defaults from regional template)
|
||||
ups_hid:
|
||||
id: ups_monitor
|
||||
update_interval: 30s
|
||||
simulation_mode: ${simulation_mode}
|
||||
# fallback_nominal_voltage comes from regional template (120V North American)
|
||||
|
||||
# Platform stubs
|
||||
binary_sensor:
|
||||
button:
|
||||
|
||||
# Test sensors to validate North American regional defaults
|
||||
sensor:
|
||||
- platform: ups_hid
|
||||
ups_hid_id: ups_monitor
|
||||
name: "Battery Level"
|
||||
type: battery_level
|
||||
unit_of_measurement: "%"
|
||||
|
||||
- platform: ups_hid
|
||||
ups_hid_id: ups_monitor
|
||||
name: "Input Voltage (North American 120V)"
|
||||
type: input_voltage
|
||||
unit_of_measurement: "V"
|
||||
|
||||
- platform: ups_hid
|
||||
ups_hid_id: ups_monitor
|
||||
name: "Input Frequency (North American 60Hz)"
|
||||
type: frequency
|
||||
unit_of_measurement: "Hz"
|
||||
|
||||
text_sensor:
|
||||
- platform: ups_hid
|
||||
ups_hid_id: ups_monitor
|
||||
name: "UPS Status"
|
||||
type: status
|
||||
|
||||
- platform: ups_hid
|
||||
ups_hid_id: ups_monitor
|
||||
name: "Protocol Name"
|
||||
type: protocol
|
||||
@@ -0,0 +1,182 @@
|
||||
# UPS LED Controls Package
|
||||
# Provides Home Assistant and Web UI control entities for ups_status_led component
|
||||
# Use with: packages: !include configs/ups_led_controls.yaml
|
||||
#
|
||||
# Requires: ups_status_led component to be configured with id: ups_led_controller
|
||||
|
||||
# Master LED enable/disable switch
|
||||
switch:
|
||||
- platform: template
|
||||
name: "UPS Status LED"
|
||||
id: ups_led_enable_switch
|
||||
icon: "mdi:led-on"
|
||||
entity_category: config
|
||||
optimistic: true
|
||||
restore_mode: RESTORE_DEFAULT_ON
|
||||
turn_on_action:
|
||||
- lambda: |-
|
||||
ESP_LOGI("led_controls", "Enabling LED");
|
||||
id(ups_led_controller).set_enabled_api(true);
|
||||
turn_off_action:
|
||||
- lambda: |-
|
||||
ESP_LOGI("led_controls", "Disabling LED");
|
||||
id(ups_led_controller).set_enabled_api(false);
|
||||
|
||||
# Night mode toggle switch
|
||||
- platform: template
|
||||
name: "UPS LED Night Mode"
|
||||
id: ups_led_night_mode_switch
|
||||
icon: "mdi:weather-night"
|
||||
entity_category: config
|
||||
optimistic: true
|
||||
restore_mode: RESTORE_DEFAULT_ON
|
||||
turn_on_action:
|
||||
- lambda: |-
|
||||
ESP_LOGI("led_controls", "Enabling night mode");
|
||||
id(ups_led_controller).set_night_mode_enabled_api(true);
|
||||
turn_off_action:
|
||||
- lambda: |-
|
||||
ESP_LOGI("led_controls", "Disabling night mode");
|
||||
id(ups_led_controller).set_night_mode_enabled_api(false);
|
||||
|
||||
# Brightness control sliders
|
||||
number:
|
||||
- platform: template
|
||||
name: "UPS LED Brightness"
|
||||
id: ups_led_brightness_number
|
||||
icon: "mdi:brightness-percent"
|
||||
entity_category: config
|
||||
min_value: 20 # Minimum 20% for meaningful enabled switch
|
||||
max_value: 100
|
||||
step: 5
|
||||
unit_of_measurement: "%"
|
||||
mode: slider
|
||||
optimistic: true
|
||||
restore_value: true
|
||||
initial_value: 80
|
||||
set_action:
|
||||
- lambda: |-
|
||||
ESP_LOGI("led_controls", "Setting brightness to %.2f%%", x);
|
||||
id(ups_led_controller).set_brightness_api(x / 100.0);
|
||||
|
||||
- platform: template
|
||||
name: "UPS LED Night Brightness"
|
||||
id: ups_led_night_brightness_number
|
||||
icon: "mdi:brightness-percent"
|
||||
entity_category: config
|
||||
min_value: 10 # Night multiplier: 10% of day brightness
|
||||
max_value: 50 # Up to 50% of day brightness
|
||||
step: 5
|
||||
unit_of_measurement: "%"
|
||||
mode: slider
|
||||
optimistic: true
|
||||
restore_value: true
|
||||
initial_value: 30 # 30% of day brightness (matches component default)
|
||||
set_action:
|
||||
- lambda: "id(ups_led_controller).set_night_mode_brightness_api(x / 100.0);"
|
||||
|
||||
- platform: template
|
||||
name: "UPS LED Night Start Hour"
|
||||
id: ups_led_night_start_hour
|
||||
icon: "mdi:clock-start"
|
||||
entity_category: config
|
||||
min_value: 0
|
||||
max_value: 23
|
||||
step: 1
|
||||
mode: slider
|
||||
optimistic: true
|
||||
restore_value: true
|
||||
initial_value: 22
|
||||
set_action:
|
||||
- lambda: "id(ups_led_controller).set_night_mode_start_time_api((int)x, id(ups_led_night_start_minute).state);"
|
||||
|
||||
- platform: template
|
||||
name: "UPS LED Night Start Minute"
|
||||
id: ups_led_night_start_minute
|
||||
icon: "mdi:clock-start"
|
||||
entity_category: config
|
||||
min_value: 0
|
||||
max_value: 59
|
||||
step: 15
|
||||
mode: slider
|
||||
optimistic: true
|
||||
restore_value: true
|
||||
initial_value: 0
|
||||
set_action:
|
||||
- lambda: "id(ups_led_controller).set_night_mode_start_time_api(id(ups_led_night_start_hour).state, (int)x);"
|
||||
|
||||
- platform: template
|
||||
name: "UPS LED Night End Hour"
|
||||
id: ups_led_night_end_hour
|
||||
icon: "mdi:clock-end"
|
||||
entity_category: config
|
||||
min_value: 0
|
||||
max_value: 23
|
||||
step: 1
|
||||
mode: slider
|
||||
optimistic: true
|
||||
restore_value: true
|
||||
initial_value: 7
|
||||
set_action:
|
||||
- lambda: "id(ups_led_controller).set_night_mode_end_time_api((int)x, id(ups_led_night_end_minute).state);"
|
||||
|
||||
- platform: template
|
||||
name: "UPS LED Night End Minute"
|
||||
id: ups_led_night_end_minute
|
||||
icon: "mdi:clock-end"
|
||||
entity_category: config
|
||||
min_value: 0
|
||||
max_value: 59
|
||||
step: 15
|
||||
mode: slider
|
||||
optimistic: true
|
||||
restore_value: true
|
||||
initial_value: 0
|
||||
set_action:
|
||||
- lambda: "id(ups_led_controller).set_night_mode_end_time_api(id(ups_led_night_end_hour).state, (int)x);"
|
||||
|
||||
# Current LED pattern display
|
||||
text_sensor:
|
||||
- platform: template
|
||||
name: "UPS LED Pattern"
|
||||
id: ups_led_pattern_sensor
|
||||
icon: "mdi:led-variant-on"
|
||||
entity_category: diagnostic
|
||||
lambda: |-
|
||||
// Match the exact logic from ups_status_led component
|
||||
if (!id(ups_monitor).is_connected()) {
|
||||
return {"UPS Offline"};
|
||||
}
|
||||
if (id(ups_monitor).is_low_battery() || id(ups_monitor).has_fault() || id(ups_monitor).is_overloaded()) {
|
||||
return {"Critical Alert"};
|
||||
}
|
||||
if (id(ups_monitor).is_on_battery()) {
|
||||
return {"Battery Power"};
|
||||
}
|
||||
if (id(ups_monitor).is_charging()) {
|
||||
return {"Charging"};
|
||||
}
|
||||
if (id(ups_monitor).is_online()) {
|
||||
return {"Normal"};
|
||||
}
|
||||
return {"No Data"};
|
||||
|
||||
update_interval: 2s
|
||||
|
||||
# Usage Notes:
|
||||
# - All entities use web_server_sorting_weight: 65 to group with LED controls
|
||||
# - Switches use optimistic mode for immediate UI feedback
|
||||
# - All number controls use template with lambda for immediate component updates
|
||||
# - Pattern text sensor shows current active LED pattern
|
||||
# - Night mode times are adjustable in 15-minute increments
|
||||
# - All controls persist values and restore after reboot
|
||||
# - Compatible with ESPHome web server v2 and v3
|
||||
# - Integrates seamlessly with Home Assistant
|
||||
#
|
||||
# Web UI Controls Provided:
|
||||
# - UPS LED Brightness (10-100%)
|
||||
# - UPS LED Night Brightness (5-50%)
|
||||
# - UPS LED Night Start Hour (0-23)
|
||||
# - UPS LED Night Start Minute (0, 15, 30, 45)
|
||||
# - UPS LED Night End Hour (0-23)
|
||||
# - UPS LED Night End Minute (0, 15, 30, 45)
|
||||
@@ -0,0 +1,56 @@
|
||||
# UPS Status LED Package
|
||||
# Smart LED status indicator using the new ups_status_led component
|
||||
# Replaces the manual interval-based LED control with automatic pattern management
|
||||
#
|
||||
# Note: Requires 'sntp_time' time component to be defined elsewhere
|
||||
# (e.g., via regional configuration packages)
|
||||
|
||||
# Physical LED configuration (hardware abstraction)
|
||||
light:
|
||||
- platform: esp32_rmt_led_strip
|
||||
chipset: WS2812
|
||||
pin: ${led_pin}
|
||||
num_leds: 1
|
||||
rgb_order: GRB
|
||||
name: "UPS Status LED Hardware"
|
||||
id: ups_status_led_hw
|
||||
internal: true # Hide from HA since controlled by ups_status_led
|
||||
restore_mode: ALWAYS_OFF
|
||||
# No effects needed - handled by ups_status_led component
|
||||
|
||||
# UPS Status LED Controller Component
|
||||
ups_status_led:
|
||||
id: ups_led_controller
|
||||
ups_hid_id: ups_monitor # Reference to UPS data provider
|
||||
light_id: ups_status_led_hw # Reference to physical LED
|
||||
time_id: sntp_time # Time for night mode scheduling
|
||||
|
||||
enabled: true # Master enable (controllable via HA)
|
||||
brightness: ${led_brightness} # Default brightness with substitution
|
||||
|
||||
# Battery color behavior
|
||||
battery_color_mode: ${led_color_mode} # discrete or gradient
|
||||
battery_low_threshold: 20 # Below = critical red
|
||||
battery_warning_threshold: 50 # Below = warning orange
|
||||
|
||||
# Night mode configuration
|
||||
night_mode:
|
||||
enabled: ${led_night_mode_enabled}
|
||||
brightness: ${led_night_brightness}
|
||||
start_time: ${led_night_start}
|
||||
end_time: ${led_night_end}
|
||||
|
||||
# Home Assistant entities automatically created:
|
||||
# - switch.ups_status_led (enable/disable)
|
||||
# - switch.ups_led_night_mode (night mode toggle)
|
||||
# - number.ups_led_brightness (brightness 10-100%)
|
||||
# - text_sensor.ups_led_pattern (current pattern)
|
||||
|
||||
# LED Patterns (automatic, priority-based, solid colors):
|
||||
# 1. CRITICAL (solid red) - Low battery/fault/overload
|
||||
# 2. BATTERY (solid orange) - On battery power
|
||||
# 3. CHARGING (solid yellow) - Charging
|
||||
# 4. NORMAL (solid green) - Normal operation
|
||||
# 5. OFFLINE (solid blue) - UPS disconnected
|
||||
# 6. NO DATA (solid purple) - No data from UPS
|
||||
# 7. ERROR (solid white) - Component error
|
||||
Reference in new issue
Block a user