refactor: rename component from nut_ups to ups_hid

Signed-off-by: bullshit <coding@ow-software.pl>
This commit is contained in:
bullshit committed 2025-08-08 15:25:03 +02:00
1 parent 03766881e1
commit a5b43af89c
24 files changed
+1076 -999

No files matched your search

+122 -747
View File
@@ -1,28 +1,45 @@
# ESPHome NUT UPS Component # ESPHome Components Collection
A production-ready ESPHome component for monitoring UPS devices via USB connection on ESP32-S3. Based on Network UPS Tools (NUT) protocols with support for APC, CyberPower, and generic HID UPS devices. A collection of production-ready ESPHome components for various hardware integrations and monitoring solutions.
## Available Components
### 🔋 UPS HID Component (`ups_hid`)
Monitor UPS devices via direct USB connection on ESP32-S3. Supports APC, CyberPower, and generic HID UPS devices with real-time monitoring of battery status, power conditions, and device information.
**Key Features:**
- Real-time UPS monitoring (battery, voltage, load, runtime)
- Multi-protocol support (APC Smart, APC HID, CyberPower HID, Generic HID)
- Auto-detection of UPS protocols
- RGB LED status indicator support
- Home Assistant integration
- Simulation mode for testing
[📖 Full Documentation](components/ups_hid/README.md)
## Installation ## Installation
### Using External Components (Recommended) ### Using External Components (Recommended)
Add to your ESPHome configuration:
```yaml ```yaml
# Add to your ESPHome configuration
external_components: external_components:
- source: github://bullshit/esphome-nut-ups - source: github://bullshit/esphome-components
components: [ nut_ups ] components: [ ups_hid ] # Add more components as needed
``` ```
### Manual Installation ### Manual Installation
1. Clone this repository: 1. Clone this repository:
```bash ```bash
git clone https://github.com/bullshit/esphome-nut-ups.git git clone https://github.com/bullshit/esphome-components.git
``` ```
2. Copy the `components/nut_ups` directory to your ESPHome project: 2. Copy component directories to your ESPHome project:
```bash ```bash
cp -r esphome-nut-ups/components/nut_ups /config/esphome/components/ cp -r esphome-components/components/* /config/esphome/components/
``` ```
3. Use local components in your configuration: 3. Use local components in your configuration:
@@ -33,799 +50,157 @@ external_components:
path: components path: components
``` ```
## Features
- 🔋 **Real-time UPS monitoring**: Battery level, voltages, load, runtime, status
- 🌈 **Visual status indicator**: RGB LED with customizable status colors
- 🏠 **Home Assistant integration**: Automatic entity discovery via ESPHome API
- 🔌 **Multi-protocol support**: APC Smart, APC HID, CyberPower HID, Generic HID
- 🎯 **Auto-detection**: Intelligent protocol detection based on USB vendor IDs
- 🛡️ **Production-ready**: Thread-safe, error rate limiting, comprehensive logging
- 🧪 **Simulation mode**: Test integration without physical UPS device
## Quick Start ## Quick Start
### Hardware Requirements ### UPS HID Component Example
- **ESP32-S3-DevKitC-1 v1.1** with USB OTG support
- **UPS device** with USB monitoring port
- **RGB LED** (optional, connected to GPIO38)
- **USB-A to USB-B cable** (UPS to ESP32-S3)
### Basic Configuration
```yaml ```yaml
# example.yaml
esphome: esphome:
name: ups-monitor name: ups-monitor
platform: ESP32 platform: ESP32
board: esp32-s3-devkitc-1 board: esp32-s3-devkitc-1
# Enable external components
external_components: external_components:
- source: - source:
type: local type: local
path: components path: components
# Configure the NUT UPS component # Configure UPS monitoring
nut_ups: ups_hid:
id: ups_monitor # Required ID for referencing id: ups_monitor
update_interval: 30s # How often to poll UPS data update_interval: 30s
usb_vendor_id: 0x051D # APC vendor ID (auto-detected if omitted) simulation_mode: false # Set to true for testing
usb_product_id: 0x0002 # Optional: specific product ID
protocol_timeout: 15s # USB communication timeout
auto_detect_protocol: true # Enable automatic protocol detection
simulation_mode: false # Set to true for testing without UPS
# Optional: RGB status LED (configured separately) # Monitor battery level
light:
- platform: esp32_rmt_led_strip
rgb_order: GRB
pin: GPIO38
num_leds: 1
chipset: ws2812
name: "UPS Status LED"
id: ups_status_led
# Define sensors (each sensor requires separate platform entry)
sensor: sensor:
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
type: battery_level type: battery_level
name: "UPS Battery Level" name: "UPS Battery Level"
unit_of_measurement: "%"
device_class: battery
- platform: nut_ups
nut_ups_id: ups_monitor
type: input_voltage
name: "UPS Input Voltage"
unit_of_measurement: "V"
device_class: voltage
- platform: nut_ups
nut_ups_id: ups_monitor
type: output_voltage
name: "UPS Output Voltage"
unit_of_measurement: "V"
device_class: voltage
- platform: nut_ups
nut_ups_id: ups_monitor
type: load_percent
name: "UPS Load"
unit_of_measurement: "%"
- platform: nut_ups
nut_ups_id: ups_monitor
type: runtime
name: "UPS Runtime"
unit_of_measurement: "min"
device_class: duration
- platform: nut_ups
nut_ups_id: ups_monitor
type: frequency
name: "UPS Frequency"
unit_of_measurement: "Hz"
# Monitor UPS status
binary_sensor: binary_sensor:
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
type: online type: online
name: "UPS Online" name: "UPS Online"
device_class: connectivity
- platform: nut_ups
nut_ups_id: ups_monitor
type: on_battery
name: "UPS On Battery"
device_class: battery
- platform: nut_ups
nut_ups_id: ups_monitor
type: low_battery
name: "UPS Low Battery"
device_class: battery
- platform: nut_ups
nut_ups_id: ups_monitor
type: charging
name: "UPS Charging"
device_class: battery
- platform: nut_ups
nut_ups_id: ups_monitor
type: fault
name: "UPS Fault"
device_class: problem
text_sensor:
- platform: nut_ups
nut_ups_id: ups_monitor
type: manufacturer
name: "UPS Manufacturer"
- platform: nut_ups
nut_ups_id: ups_monitor
type: model
name: "UPS Model"
- platform: nut_ups
nut_ups_id: ups_monitor
type: protocol
name: "UPS Protocol"
- platform: nut_ups
nut_ups_id: ups_monitor
type: status
name: "UPS Status"
``` ```
## Hardware Setup
### ESP32-S3 USB OTG Connection
```
UPS USB Port (Type-B) ←→ USB Cable ←→ ESP32-S3 USB OTG Port
```
### RGB LED Wiring (Optional)
```
GPIO38 (ESP32-S3) → RGB LED Data Pin
3.3V → RGB LED VCC
GND → RGB LED GND
```
### LED Status Indicators
- 🟢 **Green**: UPS online, normal operation
- 🟠 **Orange**: UPS running on battery power
- 🔴 **Red (blinking)**: Low battery or critical status
- 🔵 **Blue**: Charging or maintenance mode
- ⚫ **Off**: UPS disconnected or component error
## Supported UPS Devices
### Tested Compatible Models
| Vendor | Models | Protocol | Vendor ID |
|--------|--------|----------|-----------|
| **APC** | Back-UPS ES Series, Smart-UPS | APC Smart, APC HID | 0x051D |
| **CyberPower** | CP1500EPFCLCD, CP1000PFCLCD | CyberPower HID | 0x0764 |
| **Tripp Lite** | SMART1500LCDT, UPS series | Generic HID | 0x09AE |
| **Eaton/MGE** | Ellipse, Evolution series | Generic HID | 0x06DA |
| **Belkin** | Older USB UPS models | Generic HID | 0x050D |
### Protocol Compatibility Matrix
| Protocol | Communication | Auto-Detection | Features |
|----------|---------------|----------------|----------|
| **APC Smart** | Serial over USB | ✅ | Full monitoring, legacy APC |
| **APC HID** | USB HID reports | ✅ | Modern APC, enhanced features |
| **CyberPower HID** | Vendor-specific HID | ✅ | CyberPower optimized |
| **Generic HID** | Standard HID-PDC | ✅ | Universal fallback |
## Configuration Reference
### Component Options
```yaml
nut_ups:
id: ups_monitor # Required component ID for sensor references
update_interval: 30s # Polling interval (minimum 5s recommended)
# USB Device Configuration
usb_vendor_id: 0x051D # USB Vendor ID (hex), auto-detected if omitted
usb_product_id: 0x0002 # USB Product ID (hex), optional
# Protocol Settings
auto_detect_protocol: true # Enable automatic protocol detection
protocol_timeout: 15s # Communication timeout (5s-60s)
# Testing Options
simulation_mode: false # Enable simulation for testing (no USB required)
# Status LED configured separately (not part of nut_ups component)
light:
- platform: esp32_rmt_led_strip
rgb_order: GRB
pin: GPIO38 # GPIO pin for RGB LED
num_leds: 1
chipset: ws2812 # LED type (ws2812, ws2811, etc.)
name: "UPS Status LED"
id: ups_status_led
```
### Sensor Platform
Each sensor requires a separate platform entry with `nut_ups_id` and `type`:
```yaml
sensor:
- platform: nut_ups
nut_ups_id: ups_monitor # Reference to component ID
type: battery_level # Battery charge percentage (0-100%)
name: "Battery Level"
unit_of_measurement: "%"
device_class: battery
accuracy_decimals: 1
- platform: nut_ups
nut_ups_id: ups_monitor
type: input_voltage # AC input voltage (V)
name: "Input Voltage"
unit_of_measurement: "V"
device_class: voltage
accuracy_decimals: 1
- platform: nut_ups
nut_ups_id: ups_monitor
type: output_voltage # AC output voltage (V)
name: "Output Voltage"
unit_of_measurement: "V"
device_class: voltage
accuracy_decimals: 1
- platform: nut_ups
nut_ups_id: ups_monitor
type: load_percent # UPS load percentage (0-100%)
name: "Load Percentage"
unit_of_measurement: "%"
accuracy_decimals: 1
- platform: nut_ups
nut_ups_id: ups_monitor
type: runtime # Estimated runtime (minutes)
name: "Runtime"
unit_of_measurement: "min"
device_class: duration
accuracy_decimals: 0
- platform: nut_ups
nut_ups_id: ups_monitor
type: frequency # AC frequency (Hz)
name: "Frequency"
unit_of_measurement: "Hz"
accuracy_decimals: 1
```
**Available sensor types:**
- `battery_level`: Battery charge percentage (0-100%)
- `input_voltage`: AC input voltage (V)
- `output_voltage`: AC output voltage (V)
- `load_percent`: UPS load percentage (0-100%)
- `runtime`: Estimated runtime (minutes)
- `frequency`: AC frequency (Hz)
### Binary Sensor Platform
Each binary sensor requires `nut_ups_id` and `type`:
```yaml
binary_sensor:
- platform: nut_ups
nut_ups_id: ups_monitor
type: online # UPS is online (AC power available)
name: "UPS Online"
device_class: connectivity
- platform: nut_ups
nut_ups_id: ups_monitor
type: on_battery # UPS running on battery
name: "On Battery"
device_class: battery
- platform: nut_ups
nut_ups_id: ups_monitor
type: low_battery # Battery level is low
name: "Low Battery"
device_class: battery
- platform: nut_ups
nut_ups_id: ups_monitor
type: charging # Battery is charging
name: "Charging"
device_class: battery
- platform: nut_ups
nut_ups_id: ups_monitor
type: fault # UPS fault condition
name: "Fault"
device_class: problem
- platform: nut_ups
nut_ups_id: ups_monitor
type: overload # UPS is overloaded
name: "Overload"
device_class: problem
```
**Available binary sensor types:**
- `online`: UPS is online (AC power available)
- `on_battery`: UPS running on battery power
- `low_battery`: Battery level is critically low
- `charging`: Battery is currently charging
- `fault`: UPS has a fault condition
- `overload`: UPS is overloaded
### Text Sensor Platform
Each text sensor requires `nut_ups_id` and `type`:
```yaml
text_sensor:
- platform: nut_ups
nut_ups_id: ups_monitor
type: manufacturer # UPS manufacturer name
name: "Manufacturer"
- platform: nut_ups
nut_ups_id: ups_monitor
type: model # UPS model number
name: "Model"
- platform: nut_ups
nut_ups_id: ups_monitor
type: serial_number # UPS serial number (if available)
name: "Serial Number"
- platform: nut_ups
nut_ups_id: ups_monitor
type: firmware_version # UPS firmware version (if available)
name: "Firmware"
- platform: nut_ups
nut_ups_id: ups_monitor
type: protocol # Detected protocol name
name: "Protocol"
- platform: nut_ups
nut_ups_id: ups_monitor
type: status # Combined status string
name: "Status"
```
**Available text sensor types:**
- `manufacturer`: UPS manufacturer name
- `model`: UPS model number/name
- `serial_number`: UPS serial number (if available)
- `firmware_version`: UPS firmware version (if available)
- `protocol`: Currently detected protocol name
- `status`: Combined UPS status text
## Advanced Configuration
### Custom Protocol Priority
```yaml
nut_ups:
auto_detect_protocol: false # Disable auto-detection
# Component will use APC Smart Protocol by default
```
### Performance Tuning
```yaml
nut_ups:
id: ups_monitor
update_interval: 10s # Faster polling (minimum 5s recommended)
protocol_timeout: 5s # Faster timeout for responsive networks
# Individual sensor update intervals are controlled by the component
```
### Simulation Mode
For testing without physical UPS:
```yaml
nut_ups:
id: ups_monitor
simulation_mode: true # Enables realistic simulated data
update_interval: 5s # Faster updates to see simulation changes
logger:
level: DEBUG # See simulation data changes
```
## Troubleshooting
### Common Issues
#### 1. "No UPS devices found during initial enumeration"
**Cause**: USB connection or device power issues
**Solutions**:
- Verify USB cable connection (UPS ↔ ESP32-S3)
- Ensure UPS is powered on and USB monitoring is enabled
- Check ESP32-S3 USB OTG is functioning
- Try different USB cable
#### 2. "No compatible UPS protocol detected"
**Cause**: Unsupported UPS model or communication failure
**Solutions**:
- Check if your UPS model is in the supported devices list
- Enable debug logging: `logger: level: DEBUG`
- Try manual protocol selection: `auto_detect_protocol: false`
- Verify USB vendor/product IDs in logs
#### 3. "Failed to acquire USB mutex" errors
**Cause**: USB communication conflicts or hardware issues
**Solutions**:
- Increase protocol timeout: `protocol_timeout: 15s`
- Check for USB hardware conflicts
- Restart ESP32-S3 device
- Verify stable power supply
#### 4. "Protocol detection rate limited" warnings
**Cause**: Multiple failed detection attempts (normal protection)
**Solutions**:
- Wait 5 seconds for rate limit reset
- This is normal behavior protecting the UPS device
- Check physical connections if persistent
### Debug Logging
Enable detailed logging for troubleshooting:
```yaml
logger:
level: DEBUG
logs:
nut_ups: DEBUG
nut_ups.apc: DEBUG
nut_ups.cyberpower: DEBUG
nut_ups.generic: DEBUG
```
### Log Analysis
**Normal operation logs**:
```
[D][nut_ups:240] Detected known UPS vendor: APC (0x051D)
[I][nut_ups:371] Successfully detected APC HID protocol (took 156ms)
[D][nut_ups.apc:89] Battery: 85.0%, Runtime: 45.2 min
```
**Connection issues**:
```
[W][nut_ups:461] Failed to acquire USB mutex for write
[E][nut_ups:264] No compatible UPS protocol detected for vendor 0x051D
```
**Rate limiting (normal)**:
```
[W][nut_ups:185] Suppressed 5 similar error messages in the last 5000 ms
```
### Performance Monitoring
Monitor these metrics in Home Assistant:
- Update intervals (should be consistent)
- Protocol detection time (< 500ms typical)
- Error rates (should be minimal)
- USB communication success rate
## Advanced LED Status Control with Priorities
The component can control an RGB LED to display UPS status with priority-based visual indicators:
### LED Priority System
1. **🔴 Critical** (Highest Priority): Red blinking - Low battery, UPS fault, overload
2. **🟠 Battery Operation** (Medium Priority): Orange pulsing - Running on battery (normal level)
3. **🟡 Charging** (Low Priority): Yellow pulsing - Battery charging while online
4. **🟢 Normal Operation**: Green breathing - Online, normal operation
5. **⚫ Offline/Unknown**: LED off - UPS disconnected or error
### Complete LED Configuration
```yaml
# RGB LED with custom effects
light:
- platform: esp32_rmt_led_strip
rgb_order: GRB
pin: GPIO38
num_leds: 1
chipset: ws2812
name: "UPS Status LED"
id: ups_status_led
restore_mode: ALWAYS_OFF
effects:
- strobe:
name: "Critical Strobe"
colors:
- state: true
brightness: 100%
red: 100%
green: 0%
blue: 0%
duration: 250ms
- state: false
duration: 250ms
- pulse:
name: "Battery Pulse"
transition_length: 1s
update_interval: 1s
min_brightness: 20%
max_brightness: 80%
- pulse:
name: "Normal Breathing"
transition_length: 2s
update_interval: 2s
min_brightness: 30%
max_brightness: 70%
- pulse:
name: "Battery Operation"
transition_length: 800ms
update_interval: 800ms
min_brightness: 40%
max_brightness: 90%
# Priority-based LED control logic
interval:
- interval: 2s
then:
- lambda: |-
// Advanced UPS status LED control with priorities
// Critical conditions (highest priority) - Red blinking
if (id(low_battery).state || id(ups_fault).state || id(overload_warning).state) {
auto call = id(ups_status_led).turn_on();
call.set_effect("Critical Strobe");
call.perform();
}
// Battery operation (medium priority) - Orange pulsing
else if (id(on_battery).state && !id(low_battery).state) {
auto call = id(ups_status_led).turn_on();
call.set_rgb(1.0, 0.6, 0.0); // Orange
call.set_effect("Battery Operation");
call.perform();
}
// Charging (low priority) - Yellow pulsing
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("Battery Pulse");
call.perform();
}
// Normal operation (online, not on battery) - 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 Breathing");
call.perform();
}
// Offline/Unknown - LED off
else {
auto call = id(ups_status_led).turn_off();
call.perform();
}
```
## Integration Examples
### Advanced ESPHome Automations
```yaml
# Automated response scripts
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
# Event-driven automations with binary sensor triggers
binary_sensor:
- platform: nut_ups
nut_ups_id: ups_monitor
type: online
name: "UPS Online"
id: ups_online
on_press:
then:
- script.execute: power_restored
on_release:
then:
- logger.log:
format: "POWER OUTAGE: UPS switched to battery power"
level: WARN
- platform: nut_ups
nut_ups_id: ups_monitor
type: low_battery
name: "Low Battery Warning"
id: low_battery
on_press:
then:
- script.execute: ups_shutdown_warning
- script.execute: notify_critical
# Template sensors for calculations
sensor:
- 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(output_voltage).state) && !std::isnan(id(load_percentage).state)) {
// Estimate power assuming typical UPS efficiency and load factor
float estimated_power = (id(output_voltage).state * id(load_percentage).state) / 100.0;
return estimated_power * 8.0; // Assume 8A max current for estimation
}
return NAN;
update_interval: 30s
```
### Home Assistant Automation
```yaml
# automation.yaml
automation:
- alias: "UPS Power Loss Alert"
trigger:
- platform: state
entity_id: binary_sensor.ups_on_battery
to: 'on'
action:
- service: notify.mobile_app
data:
message: "⚡ Power outage detected! UPS running on battery."
- alias: "UPS Low Battery Critical"
trigger:
- platform: state
entity_id: binary_sensor.ups_low_battery
to: 'on'
action:
- service: script.shutdown_servers
- service: notify.mobile_app
data:
message: "🔋 UPS battery critically low! Initiating shutdown sequence."
```
### Grafana Dashboard
Monitor UPS metrics over time:
- Battery level trends
- Voltage stability
- Load patterns
- Power outage frequency
## Development ## Development
### Adding Custom Protocols ### Project Structure
1. Inherit from `UpsProtocolBase` ```
2. Implement required methods: `detect()`, `initialize()`, `read_data()` components/
3. Add to protocol detection in `detect_ups_protocol()` ├── ups_hid/ # UPS HID monitoring component
4. Update vendor ID mapping in `ups_vendors.h` │ ├── README.md # Component-specific documentation
│ ├── __init__.py # Component configuration
│ ├── ups_hid.h # Main component header
│ ├── ups_hid.cpp # Main component implementation
│ ├── sensor.py # Sensor platform
│ ├── binary_sensor.py # Binary sensor platform
│ ├── text_sensor.py # Text sensor platform
│ └── ... # Protocol implementations
├── [future_component]/ # Additional components
│ └── ...
└── ...
### Testing tools/
├── generate_vendor_list.py # Vendor ID synchronization tool
├── scan-usb.sh # USB device scanning utility
└── README.md # Tools documentation
```yaml .vscode/
# Use simulation mode for development └── tasks.json # VSCode development tasks
nut_ups:
simulation_mode: true
``` ```
## FAQ ### Development Tools
**Q: Can I monitor multiple UPS devices?** - **Generate Vendor List**: `python3 tools/generate_vendor_list.py`
A: Each ESP32-S3 supports one UPS via USB OTG. Use multiple ESP32-S3 devices for multiple UPS units. - Synchronizes vendor IDs between C++ and Python code
- **Scan USB Devices**: `bash tools/scan-usb.sh`
- Lists connected ESP32, UPS, and serial devices
- **VSCode Tasks**: Integrated development tasks via Command Palette
**Q: Does this work with network-attached UPS devices?** ### Adding New Components
A: No, this component requires direct USB connection. For network UPS monitoring, use the ESPHome NUT client component.
**Q: What's the power consumption?** 1. Create component directory: `components/your_component/`
A: Typical ESP32-S3 power consumption: ~100-200mA @ 5V during normal operation. 2. Implement core files:
- `__init__.py` - Component configuration and validation
- `your_component.h` - Component header
- `your_component.cpp` - Component implementation
- Platform files (`sensor.py`, etc.) as needed
3. Add component documentation: `components/your_component/README.md`
4. Update this main README with component description
5. Test with both real hardware and simulation where applicable
**Q: Can I use this with other ESP32 variants?** ### Coding Guidelines
A: Only ESP32-S3 supports USB OTG required for direct UPS communication.
## License - Follow ESPHome coding standards and patterns
- Don't use exceptions (ESPHome disables them)
- Include comprehensive logging with appropriate levels
- Implement thread-safe code where necessary
- Provide simulation modes for testing
- Include detailed documentation and examples
This component is open source and available under the MIT License. ## Hardware Requirements
Component-specific requirements are documented in each component's README:
- **UPS HID**: ESP32-S3-DevKitC-1 v1.1 with USB OTG support
- **Future components**: Requirements will be listed here
## Contributing ## Contributing
Contributions are welcome! Please follow these guidelines: Contributions are welcome! Please follow these guidelines:
1. **Fork the repository**: [github.com/bullshit/esphome-nut-ups](https://github.com/bullshit/esphome-nut-ups) 1. **Fork the repository**: [github.com/bullshit/esphome-components](https://github.com/bullshit/esphome-components)
2. **Create a feature branch**: `git checkout -b feature/your-feature-name` 2. **Create a feature branch**: `git checkout -b feature/your-feature-name`
3. **Test your changes**: Ensure code compiles and functions correctly 3. **Follow coding guidelines**: See development section above
4. **Submit a Pull Request**: Include detailed description of changes 4. **Test thoroughly**: Include both unit and integration tests
5. **Update documentation**: Add/update README files as needed
6. **Submit a Pull Request**: Include detailed description of changes
### Development Guidelines ### Development Environment
- Follow ESPHome coding standards and patterns This repository includes a complete development environment with:
- Don't use exceptions (ESPHome disables them)
- Include comprehensive logging with appropriate levels - **DevContainer**: Pre-configured development environment
- Test with both real hardware and simulation mode - **VSCode Integration**: Tasks, debugging, and extensions
- Update documentation for new features - **Development Tools**: USB scanning, vendor management, etc.
- **Test Configurations**: Example YAML files for testing
## Support ## Support
For issues and questions: For issues and questions:
1. **Check this documentation first** - Most common issues are covered 1. **Check component documentation** - Each component has detailed troubleshooting
2. **Enable debug logging** and analyze the output: 2. **Enable debug logging** in your ESPHome configuration
```yaml 3. **Search existing issues**: [GitHub Issues](https://github.com/bullshit/esphome-components/issues)
logger:
level: DEBUG
logs:
nut_ups: DEBUG
```
3. **Search existing issues**: [GitHub Issues](https://github.com/bullshit/esphome-nut-ups/issues)
4. **Create new issue** with: 4. **Create new issue** with:
- Component name and version
- Complete ESPHome configuration - Complete ESPHome configuration
- Relevant log output - Relevant log output
- UPS model and vendor/product IDs - Hardware information
- ESP32-S3 board information
### Reporting Bugs ## License
Include this information in bug reports: This project is open source and available under the MIT License.
- ESPHome version
- ESP32-S3 board model
- UPS make/model and USB vendor/product IDs
- Complete error logs with DEBUG level enabled
- Your ESPHome configuration (sanitized)
### Feature Requests ## Roadmap
For new UPS protocol support: ### Planned Components
- UPS vendor and model information
- USB vendor/product IDs (check logs) - 📡 **RF Module**: ASK/OOK transceiver integration
- Any available protocol documentation - 🌡️ **Multi-Sensor Hub**: I2C sensor aggregation
- Sample communication logs if possible - 🔌 **Smart Relay Controller**: Multi-channel relay management
- 📊 **Data Logger**: SD card logging with web interface
### Current Status
- ✅ **UPS HID Component**: Production ready
- 🔄 **Documentation**: Ongoing improvements
- 🔄 **Test Coverage**: Expanding automated tests
- 📋 **Future Components**: Planning and design phase
Stay tuned for updates and new component releases!
-67
View File
@@ -1,67 +0,0 @@
#pragma once
/**
* @file ups_vendors.h
* @brief Known UPS vendor IDs for device identification and validation
*
* This file contains the definitive list of known UPS vendor IDs
* shared between C++ runtime code and Python configuration validation.
*/
namespace esphome {
namespace nut_ups {
// Known UPS vendor IDs with their names
struct UpsVendor {
uint16_t vendor_id;
const char* name;
const char* description;
};
// Definitive list of known UPS vendors (based on NUT project driver.list)
static constexpr UpsVendor KNOWN_UPS_VENDORS[] = {
{0x0001, "Generic/Other", "Generic UPS vendors (multiple brands)"},
{0x0463, "MGE Office Protection Systems", "MGE Office Protection Systems"},
{0x050D, "Belkin", "Belkin (older USB UPS models)"},
{0x051D, "APC", "American Power Conversion"},
{0x05B8, "SVEN", "SVEN UPS devices"},
{0x0665, "Cypress/Belkin", "Cypress or Belkin UPS devices"},
{0x06DA, "MGE UPS Systems", "MGE UPS Systems (now Eaton)"},
{0x0764, "CyberPower", "CyberPower Systems"},
{0x0925, "Richcomm", "Richcomm Technologies (Digitus, Sweex)"},
{0x09AE, "Tripp Lite", "Tripp Lite"},
{0x09D6, "Micropower", "Micropower UPS devices"},
};
static constexpr size_t KNOWN_UPS_VENDORS_COUNT = sizeof(KNOWN_UPS_VENDORS) / sizeof(KNOWN_UPS_VENDORS[0]);
/**
* Check if a vendor ID is in the known UPS vendors list
* @param vendor_id The USB vendor ID to check
* @return True if vendor ID is known, false otherwise
*/
inline bool is_known_ups_vendor(uint16_t vendor_id) {
for (size_t i = 0; i < KNOWN_UPS_VENDORS_COUNT; i++) {
if (KNOWN_UPS_VENDORS[i].vendor_id == vendor_id) {
return true;
}
}
return false;
}
/**
* Get vendor name for a given vendor ID
* @param vendor_id The USB vendor ID
* @return Vendor name or nullptr if unknown
*/
inline const char* get_ups_vendor_name(uint16_t vendor_id) {
for (size_t i = 0; i < KNOWN_UPS_VENDORS_COUNT; i++) {
if (KNOWN_UPS_VENDORS[i].vendor_id == vendor_id) {
return KNOWN_UPS_VENDORS[i].name;
}
}
return nullptr;
}
} // namespace nut_ups
} // namespace esphome
+694
View File
@@ -0,0 +1,694 @@
# UPS HID Component for ESPHome
A production-ready ESPHome component for monitoring UPS devices via USB connection on ESP32-S3. Direct USB HID communication with support for APC, CyberPower, and generic HID UPS devices.
## Features
- 🔋 **Real-time UPS monitoring**: Battery level, voltages, load, runtime, status
- 🌈 **Visual status indicator**: RGB LED with customizable status colors
- 🏠 **Home Assistant integration**: Automatic entity discovery via ESPHome API
- 🔌 **Multi-protocol support**: APC Smart, APC HID, CyberPower HID, Generic HID
- 🎯 **Auto-detection**: Intelligent protocol detection based on USB vendor IDs
- 🛡️ **Production-ready**: Thread-safe, error rate limiting, comprehensive logging
- 🧪 **Simulation mode**: Test integration without physical UPS device
## Quick Start
### Hardware Requirements
- **ESP32-S3-DevKitC-1 v1.1** with USB OTG support
- **UPS device** with USB monitoring port
- **RGB LED** (optional, connected to GPIO38)
- **USB cable** (UPS to ESP32-S3)
### Basic Configuration
```yaml
# example.yaml
esphome:
name: ups-monitor
platform: ESP32
board: esp32-s3-devkitc-1
# Enable external components
external_components:
- source:
type: local
path: components
# Configure the UPS HID component
ups_hid:
id: ups_monitor # Required ID for referencing
update_interval: 30s # How often to poll UPS data
usb_vendor_id: 0x051D # APC vendor ID (auto-detected if omitted)
usb_product_id: 0x0002 # Optional: specific product ID
protocol_timeout: 15s # USB communication timeout
auto_detect_protocol: true # Enable automatic protocol detection
simulation_mode: false # Set to true for testing without UPS
# Optional: RGB status LED (configured separately)
light:
- platform: esp32_rmt_led_strip
rgb_order: GRB
pin: GPIO38
num_leds: 1
chipset: ws2812
name: "UPS Status LED"
id: ups_status_led
# Define sensors (each sensor requires separate platform entry)
sensor:
- platform: ups_hid
ups_hid_id: ups_monitor
type: battery_level
name: "UPS Battery Level"
unit_of_measurement: "%"
device_class: battery
- platform: ups_hid
ups_hid_id: ups_monitor
type: input_voltage
name: "UPS Input Voltage"
unit_of_measurement: "V"
device_class: voltage
- platform: ups_hid
ups_hid_id: ups_monitor
type: output_voltage
name: "UPS Output Voltage"
unit_of_measurement: "V"
device_class: voltage
- platform: ups_hid
ups_hid_id: ups_monitor
type: load_percent
name: "UPS Load"
unit_of_measurement: "%"
- platform: ups_hid
ups_hid_id: ups_monitor
type: runtime
name: "UPS Runtime"
unit_of_measurement: "min"
device_class: duration
- platform: ups_hid
ups_hid_id: ups_monitor
type: frequency
name: "UPS Frequency"
unit_of_measurement: "Hz"
binary_sensor:
- platform: ups_hid
ups_hid_id: ups_monitor
type: online
name: "UPS Online"
device_class: connectivity
- platform: ups_hid
ups_hid_id: ups_monitor
type: on_battery
name: "UPS On Battery"
device_class: battery
- platform: ups_hid
ups_hid_id: ups_monitor
type: low_battery
name: "UPS Low Battery"
device_class: battery
- platform: ups_hid
ups_hid_id: ups_monitor
type: charging
name: "UPS Charging"
device_class: battery
- platform: ups_hid
ups_hid_id: ups_monitor
type: fault
name: "UPS Fault"
device_class: problem
text_sensor:
- platform: ups_hid
ups_hid_id: ups_monitor
type: manufacturer
name: "UPS Manufacturer"
- platform: ups_hid
ups_hid_id: ups_monitor
type: model
name: "UPS Model"
- platform: ups_hid
ups_hid_id: ups_monitor
type: protocol
name: "UPS Protocol"
- platform: ups_hid
ups_hid_id: ups_monitor
type: status
name: "UPS Status"
```
## Hardware Setup
### ESP32-S3 USB OTG Connection
```
UPS USB Port (Type-B) ←→ USB Cable ←→ ESP32-S3 USB OTG Port
```
### RGB LED Wiring (Optional)
```
GPIO38 (ESP32-S3) → RGB LED Data Pin
3.3V → RGB LED VCC
GND → RGB LED GND
```
### LED Status Indicators
- 🟢 **Green**: UPS online, normal operation
- 🟠 **Orange**: UPS running on battery power
- 🔴 **Red (blinking)**: Low battery or critical status
- 🔵 **Blue**: Charging or maintenance mode
- ⚫ **Off**: UPS disconnected or component error
## Supported UPS Devices
### Tested Compatible Models
| Vendor | Models | Protocol | Vendor ID |
|--------|--------|----------|-----------|
| **APC** | Back-UPS ES Series, Smart-UPS | APC Smart, APC HID | 0x051D |
| **CyberPower** | CP1500EPFCLCD, CP1000PFCLCD | CyberPower HID | 0x0764 |
| **Tripp Lite** | SMART1500LCDT, UPS series | Generic HID | 0x09AE |
| **Eaton/MGE** | Ellipse, Evolution series | Generic HID | 0x06DA |
| **Belkin** | Older USB UPS models | Generic HID | 0x050D |
### Protocol Compatibility Matrix
| Protocol | Communication | Auto-Detection | Features |
|----------|---------------|----------------|----------|
| **APC Smart** | Serial over USB | ✅ | Full monitoring, legacy APC |
| **APC HID** | USB HID reports | ✅ | Modern APC, enhanced features |
| **CyberPower HID** | Vendor-specific HID | ✅ | CyberPower optimized |
| **Generic HID** | Standard HID-PDC | ✅ | Universal fallback |
## Configuration Reference
### Component Options
```yaml
ups_hid:
id: ups_monitor # Required component ID for sensor references
update_interval: 30s # Polling interval (minimum 5s recommended)
# USB Device Configuration
usb_vendor_id: 0x051D # USB Vendor ID (hex), auto-detected if omitted
usb_product_id: 0x0002 # USB Product ID (hex), optional
# Protocol Settings
auto_detect_protocol: true # Enable automatic protocol detection
protocol_timeout: 15s # Communication timeout (5s-60s)
# Testing Options
simulation_mode: false # Enable simulation for testing (no USB required)
# Status LED configured separately (not part of ups_hid component)
light:
- platform: esp32_rmt_led_strip
rgb_order: GRB
pin: GPIO38 # GPIO pin for RGB LED
num_leds: 1
chipset: ws2812 # LED type (ws2812, ws2811, etc.)
name: "UPS Status LED"
id: ups_status_led
```
### Sensor Platform
Each sensor requires a separate platform entry with `ups_hid_id` and `type`:
```yaml
sensor:
- platform: ups_hid
ups_hid_id: ups_monitor # Reference to component ID
type: battery_level # Battery charge percentage (0-100%)
name: "Battery Level"
unit_of_measurement: "%"
device_class: battery
accuracy_decimals: 1
- platform: ups_hid
ups_hid_id: ups_monitor
type: input_voltage # AC input voltage (V)
name: "Input Voltage"
unit_of_measurement: "V"
device_class: voltage
accuracy_decimals: 1
- platform: ups_hid
ups_hid_id: ups_monitor
type: output_voltage # AC output voltage (V)
name: "Output Voltage"
unit_of_measurement: "V"
device_class: voltage
accuracy_decimals: 1
- platform: ups_hid
ups_hid_id: ups_monitor
type: load_percent # UPS load percentage (0-100%)
name: "Load Percentage"
unit_of_measurement: "%"
accuracy_decimals: 1
- platform: ups_hid
ups_hid_id: ups_monitor
type: runtime # Estimated runtime (minutes)
name: "Runtime"
unit_of_measurement: "min"
device_class: duration
accuracy_decimals: 0
- platform: ups_hid
ups_hid_id: ups_monitor
type: frequency # AC frequency (Hz)
name: "Frequency"
unit_of_measurement: "Hz"
accuracy_decimals: 1
```
**Available sensor types:**
- `battery_level`: Battery charge percentage (0-100%)
- `input_voltage`: AC input voltage (V)
- `output_voltage`: AC output voltage (V)
- `load_percent`: UPS load percentage (0-100%)
- `runtime`: Estimated runtime (minutes)
- `frequency`: AC frequency (Hz)
### Binary Sensor Platform
Each binary sensor requires `ups_hid_id` and `type`:
```yaml
binary_sensor:
- platform: ups_hid
ups_hid_id: ups_monitor
type: online # UPS is online (AC power available)
name: "UPS Online"
device_class: connectivity
- platform: ups_hid
ups_hid_id: ups_monitor
type: on_battery # UPS running on battery
name: "On Battery"
device_class: battery
- platform: ups_hid
ups_hid_id: ups_monitor
type: low_battery # Battery level is low
name: "Low Battery"
device_class: battery
- platform: ups_hid
ups_hid_id: ups_monitor
type: charging # Battery is charging
name: "Charging"
device_class: battery
- platform: ups_hid
ups_hid_id: ups_monitor
type: fault # UPS fault condition
name: "Fault"
device_class: problem
- platform: ups_hid
ups_hid_id: ups_monitor
type: overload # UPS is overloaded
name: "Overload"
device_class: problem
```
**Available binary sensor types:**
- `online`: UPS is online (AC power available)
- `on_battery`: UPS running on battery power
- `low_battery`: Battery level is critically low
- `charging`: Battery is currently charging
- `fault`: UPS has a fault condition
- `overload`: UPS is overloaded
### Text Sensor Platform
Each text sensor requires `ups_hid_id` and `type`:
```yaml
text_sensor:
- platform: ups_hid
ups_hid_id: ups_monitor
type: manufacturer # UPS manufacturer name
name: "Manufacturer"
- platform: ups_hid
ups_hid_id: ups_monitor
type: model # UPS model number
name: "Model"
- platform: ups_hid
ups_hid_id: ups_monitor
type: serial_number # UPS serial number (if available)
name: "Serial Number"
- platform: ups_hid
ups_hid_id: ups_monitor
type: firmware_version # UPS firmware version (if available)
name: "Firmware"
- platform: ups_hid
ups_hid_id: ups_monitor
type: protocol # Detected protocol name
name: "Protocol"
- platform: ups_hid
ups_hid_id: ups_monitor
type: status # Combined status string
name: "Status"
```
**Available text sensor types:**
- `manufacturer`: UPS manufacturer name
- `model`: UPS model number/name
- `serial_number`: UPS serial number (if available)
- `firmware_version`: UPS firmware version (if available)
- `protocol`: Currently detected protocol name
- `status`: Combined UPS status text
## Advanced Configuration
### Custom Protocol Priority
```yaml
ups_hid:
auto_detect_protocol: false # Disable auto-detection
# Component will use APC Smart Protocol by default
```
### Performance Tuning
```yaml
ups_hid:
id: ups_monitor
update_interval: 10s # Faster polling (minimum 5s recommended)
protocol_timeout: 5s # Faster timeout for responsive networks
# Individual sensor update intervals are controlled by the component
```
### Simulation Mode
For testing without physical UPS:
```yaml
ups_hid:
id: ups_monitor
simulation_mode: true # Enables realistic simulated data
update_interval: 5s # Faster updates to see simulation changes
logger:
level: DEBUG # See simulation data changes
```
## Troubleshooting
### Common Issues
#### 1. "No UPS devices found during initial enumeration"
**Cause**: USB connection or device power issues
**Solutions**:
- Verify USB cable connection (UPS ↔ ESP32-S3)
- Ensure UPS is powered on and USB monitoring is enabled
- Check ESP32-S3 USB OTG is functioning
- Try different USB cable
#### 2. "No compatible UPS protocol detected"
**Cause**: Unsupported UPS model or communication failure
**Solutions**:
- Check if your UPS model is in the supported devices list
- Enable debug logging: `logger: level: DEBUG`
- Try manual protocol selection: `auto_detect_protocol: false`
- Verify USB vendor/product IDs in logs
#### 3. "Failed to acquire USB mutex" errors
**Cause**: USB communication conflicts or hardware issues
**Solutions**:
- Increase protocol timeout: `protocol_timeout: 15s`
- Check for USB hardware conflicts
- Restart ESP32-S3 device
- Verify stable power supply
#### 4. "Protocol detection rate limited" warnings
**Cause**: Multiple failed detection attempts (normal protection)
**Solutions**:
- Wait 5 seconds for rate limit reset
- This is normal behavior protecting the UPS device
- Check physical connections if persistent
### Debug Logging
Enable detailed logging for troubleshooting:
```yaml
logger:
level: DEBUG
logs:
ups_hid: DEBUG
ups_hid.apc: DEBUG
ups_hid.cyberpower: DEBUG
ups_hid.generic: DEBUG
```
### Log Analysis
**Normal operation logs**:
```
[D][ups_hid:240] Detected known UPS vendor: APC (0x051D)
[I][ups_hid:371] Successfully detected APC HID protocol (took 156ms)
[D][ups_hid.apc:89] Battery: 85.0%, Runtime: 45.2 min
```
**Connection issues**:
```
[W][ups_hid:461] Failed to acquire USB mutex for write
[E][ups_hid:264] No compatible UPS protocol detected for vendor 0x051D
```
**Rate limiting (normal)**:
```
[W][ups_hid:185] Suppressed 5 similar error messages in the last 5000 ms
```
### Performance Monitoring
Monitor these metrics in Home Assistant:
- Update intervals (should be consistent)
- Protocol detection time (< 500ms typical)
- Error rates (should be minimal)
- USB communication success rate
## Advanced LED Status Control
The component can control an RGB LED to display UPS status with priority-based visual indicators:
### LED Priority System
1. **🔴 Critical** (Highest Priority): Red blinking - Low battery, UPS fault, overload
2. **🟠 Battery Operation** (Medium Priority): Orange pulsing - Running on battery (normal level)
3. **🟡 Charging** (Low Priority): Yellow pulsing - Battery charging while online
4. **🟢 Normal Operation**: Green breathing - Online, normal operation
5. **⚫ Offline/Unknown**: LED off - UPS disconnected or error
### Complete LED Configuration
```yaml
# RGB LED with custom effects
light:
- platform: esp32_rmt_led_strip
rgb_order: GRB
pin: GPIO38
num_leds: 1
chipset: ws2812
name: "UPS Status LED"
id: ups_status_led
restore_mode: ALWAYS_OFF
effects:
- strobe:
name: "Critical Strobe"
colors:
- state: true
brightness: 100%
red: 100%
green: 0%
blue: 0%
duration: 250ms
- state: false
duration: 250ms
- pulse:
name: "Battery Pulse"
transition_length: 1s
update_interval: 1s
min_brightness: 20%
max_brightness: 80%
- pulse:
name: "Normal Breathing"
transition_length: 2s
update_interval: 2s
min_brightness: 30%
max_brightness: 70%
- pulse:
name: "Battery Operation"
transition_length: 800ms
update_interval: 800ms
min_brightness: 40%
max_brightness: 90%
# Priority-based LED control logic
interval:
- interval: 2s
then:
- lambda: |-
// Advanced UPS status LED control with priorities
// Critical conditions (highest priority) - Red blinking
if (id(low_battery).state || id(ups_fault).state || id(overload_warning).state) {
auto call = id(ups_status_led).turn_on();
call.set_effect("Critical Strobe");
call.perform();
}
// Battery operation (medium priority) - Orange pulsing
else if (id(on_battery).state && !id(low_battery).state) {
auto call = id(ups_status_led).turn_on();
call.set_rgb(1.0, 0.6, 0.0); // Orange
call.set_effect("Battery Operation");
call.perform();
}
// Charging (low priority) - Yellow pulsing
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("Battery Pulse");
call.perform();
}
// Normal operation (online, not on battery) - 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 Breathing");
call.perform();
}
// Offline/Unknown - LED off
else {
auto call = id(ups_status_led).turn_off();
call.perform();
}
```
## Integration Examples
### Home Assistant Automation
```yaml
# automation.yaml
automation:
- alias: "UPS Power Loss Alert"
trigger:
- platform: state
entity_id: binary_sensor.ups_on_battery
to: 'on'
action:
- service: notify.mobile_app
data:
message: "⚡ Power outage detected! UPS running on battery."
- alias: "UPS Low Battery Critical"
trigger:
- platform: state
entity_id: binary_sensor.ups_low_battery
to: 'on'
action:
- service: script.shutdown_servers
- service: notify.mobile_app
data:
message: "🔋 UPS battery critically low! Initiating shutdown sequence."
```
## FAQ
**Q: Can I monitor multiple UPS devices?**
A: Each ESP32-S3 supports one UPS via USB OTG. Use multiple ESP32-S3 devices for multiple UPS units.
**Q: Does this work with network-attached UPS devices?**
A: No, this component requires direct USB connection. For network UPS monitoring, use a different ESPHome component that supports network communication.
**Q: What's the power consumption?**
A: Typical ESP32-S3 power consumption: ~100-200mA @ 5V during normal operation.
**Q: Can I use this with other ESP32 variants?**
A: Only ESP32-S3 supports USB OTG required for direct UPS communication.
## Development
### Adding Custom Protocols
1. Inherit from `UpsProtocolBase`
2. Implement required methods: `detect()`, `initialize()`, `read_data()`
3. Add to protocol detection in `detect_ups_protocol()`
4. Update vendor ID mapping in `ups_vendors.h`
### Testing
```yaml
# Use simulation mode for development
ups_hid:
simulation_mode: true
```
## Support
For issues and questions:
1. **Check this documentation first** - Most common issues are covered
2. **Enable debug logging** and analyze the output:
```yaml
logger:
level: DEBUG
logs:
ups_hid: DEBUG
```
3. **Search existing issues**: [GitHub Issues](https://github.com/bullshit/esphome-components/issues)
4. **Create new issue** with:
- Complete ESPHome configuration
- Relevant log output
- UPS model and vendor/product IDs
- ESP32-S3 board information
### Reporting Bugs
Include this information in bug reports:
- ESPHome version
- ESP32-S3 board model
- UPS make/model and USB vendor/product IDs
- Complete error logs with DEBUG level enabled
- Your ESPHome configuration (sanitized)
### Feature Requests
For new UPS protocol support:
- UPS vendor and model information
- USB vendor/product IDs (check logs)
- Any available protocol documentation
- Sample communication logs if possible
@@ -1,4 +1,4 @@
"""NUT UPS Component for ESPHome - Enhanced validation and configuration.""" """UPS HID Component for ESPHome - Enhanced validation and configuration."""
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
@@ -15,11 +15,10 @@ CONF_USB_VENDOR_ID = "usb_vendor_id"
CONF_USB_PRODUCT_ID = "usb_product_id" CONF_USB_PRODUCT_ID = "usb_product_id"
CONF_PROTOCOL_TIMEOUT = "protocol_timeout" CONF_PROTOCOL_TIMEOUT = "protocol_timeout"
CONF_AUTO_DETECT_PROTOCOL = "auto_detect_protocol" CONF_AUTO_DETECT_PROTOCOL = "auto_detect_protocol"
CONF_NUT_UPS_ID = "nut_ups_id" CONF_UPS_HID_ID = "ups_hid_id"
# Known UPS vendor IDs for validation # Known UPS vendor IDs for validation
KNOWN_VENDOR_IDS = { KNOWN_VENDOR_IDS = {
0x0001: "Generic/Other",
0x0463: "MGE Office Protection Systems", 0x0463: "MGE Office Protection Systems",
0x050D: "Belkin", 0x050D: "Belkin",
0x051D: "APC", 0x051D: "APC",
@@ -32,8 +31,8 @@ KNOWN_VENDOR_IDS = {
0x09D6: "Micropower", 0x09D6: "Micropower",
} }
nut_ups_ns = cg.esphome_ns.namespace("nut_ups") ups_hid_ns = cg.esphome_ns.namespace("ups_hid")
NutUpsComponent = nut_ups_ns.class_("NutUpsComponent", cg.PollingComponent) UpsHidComponent = ups_hid_ns.class_("UpsHidComponent", cg.PollingComponent)
def validate_usb_config(config): def validate_usb_config(config):
@@ -70,7 +69,7 @@ def validate_protocol_timeout(value):
def validate_update_interval(value): def validate_update_interval(value):
"""Validate update interval for UPS monitoring.""" """Validate update interval for UPS HID monitoring."""
value = cv.update_interval(value) value = cv.update_interval(value)
ms = value.total_milliseconds ms = value.total_milliseconds
@@ -86,7 +85,7 @@ def validate_update_interval(value):
CONFIG_SCHEMA = cv.All( CONFIG_SCHEMA = cv.All(
cv.Schema( cv.Schema(
{ {
cv.GenerateID(): cv.declare_id(NutUpsComponent), cv.GenerateID(): cv.declare_id(UpsHidComponent),
cv.Optional(CONF_UPDATE_INTERVAL, default="30s"): validate_update_interval, cv.Optional(CONF_UPDATE_INTERVAL, default="30s"): validate_update_interval,
cv.Optional(CONF_SIMULATION_MODE, default=False): cv.boolean, cv.Optional(CONF_SIMULATION_MODE, default=False): cv.boolean,
cv.Optional(CONF_USB_VENDOR_ID, default=0x051D): cv.hex_uint16_t, cv.Optional(CONF_USB_VENDOR_ID, default=0x051D): cv.hex_uint16_t,
@@ -4,9 +4,9 @@
#include <cstring> #include <cstring>
namespace esphome { namespace esphome {
namespace nut_ups { namespace ups_hid {
static const char *const APC_HID_TAG = "nut_ups.apc_hid"; static const char *const APC_HID_TAG = "ups_hid.apc_hid";
// APC HID Usage Pages and Usage IDs (based on NUT project research) // APC HID Usage Pages and Usage IDs (based on NUT project research)
static const uint16_t APC_USAGE_PAGE_UPS = 0x84; static const uint16_t APC_USAGE_PAGE_UPS = 0x84;
@@ -38,7 +38,7 @@ static std::string convert_apc_date(uint32_t apc_date) {
} }
// APC HID Protocol implementation // APC HID Protocol implementation
ApcHidProtocol::ApcHidProtocol(NutUpsComponent *parent) : UpsProtocolBase(parent) {} ApcHidProtocol::ApcHidProtocol(UpsHidComponent *parent) : UpsProtocolBase(parent) {}
bool ApcHidProtocol::detect() { bool ApcHidProtocol::detect() {
ESP_LOGD(APC_HID_TAG, "Detecting APC HID Protocol..."); ESP_LOGD(APC_HID_TAG, "Detecting APC HID Protocol...");
@@ -339,5 +339,5 @@ void ApcHidProtocol::parse_device_info_report(const HidReport &report) {
} }
} }
} // namespace nut_ups } // namespace ups_hid
} // namespace esphome } // namespace esphome
@@ -1,14 +1,14 @@
#pragma once #pragma once
#include "nut_ups.h" #include "ups_hid.h"
namespace esphome { namespace esphome {
namespace nut_ups { namespace ups_hid {
// APC HID Protocol implementation for modern APC UPS devices // APC HID Protocol implementation for modern APC UPS devices
class ApcHidProtocol : public UpsProtocolBase { class ApcHidProtocol : public UpsProtocolBase {
public: public:
explicit ApcHidProtocol(NutUpsComponent *parent); explicit ApcHidProtocol(UpsHidComponent *parent);
bool detect() override; bool detect() override;
bool initialize() override; bool initialize() override;
@@ -36,5 +36,5 @@ private:
void parse_device_info_report(const HidReport &report); void parse_device_info_report(const HidReport &report);
}; };
} // namespace nut_ups } // namespace ups_hid
} // namespace esphome } // namespace esphome
@@ -1,4 +1,4 @@
#include "nut_ups.h" #include "ups_hid.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "esphome/core/helpers.h" #include "esphome/core/helpers.h"
#include "esphome/core/hal.h" #include "esphome/core/hal.h"
@@ -7,10 +7,10 @@
namespace esphome namespace esphome
{ {
namespace nut_ups namespace ups_hid
{ {
static const char *const APC_TAG = "nut_ups.apc"; static const char *const APC_TAG = "ups_hid.apc";
// APC Smart Protocol Commands // APC Smart Protocol Commands
static const char APC_CMD_STATUS = 'Q'; // Status inquiry static const char APC_CMD_STATUS = 'Q'; // Status inquiry
@@ -483,5 +483,5 @@ namespace esphome
return flags; return flags;
} }
} // namespace nut_ups } // namespace ups_hid
} // namespace esphome } // namespace esphome
@@ -2,15 +2,15 @@
#include "esphome/core/log.h" #include "esphome/core/log.h"
namespace esphome { namespace esphome {
namespace nut_ups { namespace ups_hid {
static const char *const TAG_BINARY = "nut_ups.binary_sensor"; static const char *const TAG_BINARY = "ups_hid.binary_sensor";
void NutUpsBinarySensor::dump_config() { void UpsHidBinarySensor::dump_config() {
ESP_LOGCONFIG(TAG_BINARY, "NUT UPS Binary Sensor:"); ESP_LOGCONFIG(TAG_BINARY, "UPS HID Binary Sensor:");
ESP_LOGCONFIG(TAG_BINARY, " Type: %s", sensor_type_.c_str()); ESP_LOGCONFIG(TAG_BINARY, " Type: %s", sensor_type_.c_str());
LOG_BINARY_SENSOR(" ", "Binary Sensor", this); LOG_BINARY_SENSOR(" ", "Binary Sensor", this);
} }
} // namespace nut_ups } // namespace ups_hid
} // namespace esphome } // namespace esphome
@@ -2,14 +2,14 @@
#include "esphome/core/component.h" #include "esphome/core/component.h"
#include "esphome/components/binary_sensor/binary_sensor.h" #include "esphome/components/binary_sensor/binary_sensor.h"
#include "nut_ups.h" #include "ups_hid.h"
namespace esphome namespace esphome
{ {
namespace nut_ups namespace ups_hid
{ {
class NutUpsBinarySensor : public binary_sensor::BinarySensor, public Component class UpsHidBinarySensor : public binary_sensor::BinarySensor, public Component
{ {
public: public:
void set_sensor_type(const std::string &type) { sensor_type_ = type; } void set_sensor_type(const std::string &type) { sensor_type_ = type; }
@@ -19,5 +19,5 @@ namespace esphome
std::string sensor_type_; std::string sensor_type_;
}; };
} // namespace nut_ups } // namespace ups_hid
} // namespace esphome } // namespace esphome
@@ -9,12 +9,12 @@ from esphome.const import (
DEVICE_CLASS_POWER, DEVICE_CLASS_POWER,
) )
from . import nut_ups_ns, NutUpsComponent, CONF_NUT_UPS_ID from . import ups_hid_ns, UpsHidComponent, CONF_UPS_HID_ID
DEPENDENCIES = ["nut_ups"] DEPENDENCIES = ["ups_hid"]
NutUpsBinarySensor = nut_ups_ns.class_( UpsHidBinarySensor = ups_hid_ns.class_(
"NutUpsBinarySensor", binary_sensor.BinarySensor, cg.Component "UpsHidBinarySensor", binary_sensor.BinarySensor, cg.Component
) )
BINARY_SENSOR_TYPES = { BINARY_SENSOR_TYPES = {
@@ -39,16 +39,16 @@ BINARY_SENSOR_TYPES = {
} }
CONFIG_SCHEMA = binary_sensor.binary_sensor_schema(NutUpsBinarySensor).extend( CONFIG_SCHEMA = binary_sensor.binary_sensor_schema(UpsHidBinarySensor).extend(
{ {
cv.GenerateID(CONF_NUT_UPS_ID): cv.use_id(NutUpsComponent), cv.GenerateID(CONF_UPS_HID_ID): cv.use_id(UpsHidComponent),
cv.Required(CONF_TYPE): cv.one_of(*BINARY_SENSOR_TYPES, lower=True), cv.Required(CONF_TYPE): cv.one_of(*BINARY_SENSOR_TYPES, lower=True),
} }
) )
async def to_code(config): async def to_code(config):
parent = await cg.get_variable(config[CONF_NUT_UPS_ID]) parent = await cg.get_variable(config[CONF_UPS_HID_ID])
var = await binary_sensor.new_binary_sensor(config) var = await binary_sensor.new_binary_sensor(config)
await cg.register_component(var, config) await cg.register_component(var, config)
@@ -1,10 +1,10 @@
#include "nut_ups.h" #include "ups_hid.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
namespace esphome { namespace esphome {
namespace nut_ups { namespace ups_hid {
static const char *const CP_TAG = "nut_ups.cyberpower"; static const char *const CP_TAG = "ups_hid.cyberpower";
// CyberPower HID Report IDs and data structures // CyberPower HID Report IDs and data structures
static const uint8_t CP_REPORT_ID_UPS_STATUS = 0x01; static const uint8_t CP_REPORT_ID_UPS_STATUS = 0x01;
@@ -357,5 +357,5 @@ bool CyberPowerProtocol::parse_device_info_report(const HidReport &report, UpsDa
return true; return true;
} }
} // namespace nut_ups } // namespace ups_hid
} // namespace esphome } // namespace esphome
@@ -1,10 +1,10 @@
#include "nut_ups.h" #include "ups_hid.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
namespace esphome { namespace esphome {
namespace nut_ups { namespace ups_hid {
static const char *const GEN_TAG = "nut_ups.generic"; static const char *const GEN_TAG = "ups_hid.generic";
// Standard HID Usage Pages (based on NUT usbhid-ups.c) // Standard HID Usage Pages (based on NUT usbhid-ups.c)
static const uint16_t HID_USAGE_PAGE_POWER_DEVICE = 0x84; static const uint16_t HID_USAGE_PAGE_POWER_DEVICE = 0x84;
@@ -231,5 +231,5 @@ bool GenericHidProtocol::parse_generic_report(const std::vector<uint8_t>& respon
return found_data; return found_data;
} }
} // namespace nut_ups } // namespace ups_hid
} // namespace esphome } // namespace esphome
@@ -3,17 +3,17 @@
namespace esphome namespace esphome
{ {
namespace nut_ups namespace ups_hid
{ {
static const char *const S_TAG = "nut_ups.sensor"; static const char *const S_TAG = "ups_hid.sensor";
void NutUpsSensor::dump_config() void UpsHidSensor::dump_config()
{ {
ESP_LOGCONFIG(S_TAG, "NUT UPS Sensor:"); ESP_LOGCONFIG(S_TAG, "UPS HID Sensor:");
ESP_LOGCONFIG(S_TAG, " Type: %s", sensor_type_.c_str()); ESP_LOGCONFIG(S_TAG, " Type: %s", sensor_type_.c_str());
LOG_SENSOR(" ", "Sensor", this); LOG_SENSOR(" ", "Sensor", this);
} }
} // namespace nut_ups } // namespace ups_hid
} // namespace esphome } // namespace esphome
@@ -2,14 +2,14 @@
#include "esphome/core/component.h" #include "esphome/core/component.h"
#include "esphome/components/sensor/sensor.h" #include "esphome/components/sensor/sensor.h"
#include "nut_ups.h" #include "ups_hid.h"
namespace esphome namespace esphome
{ {
namespace nut_ups namespace ups_hid
{ {
class NutUpsSensor : public sensor::Sensor, public Component class UpsHidSensor : public sensor::Sensor, public Component
{ {
public: public:
void set_sensor_type(const std::string &type) { sensor_type_ = type; } void set_sensor_type(const std::string &type) { sensor_type_ = type; }
@@ -19,5 +19,5 @@ namespace esphome
std::string sensor_type_; std::string sensor_type_;
}; };
} // namespace nut_ups } // namespace ups_hid
} // namespace esphome } // namespace esphome
@@ -14,11 +14,11 @@ from esphome.const import (
UNIT_HERTZ, UNIT_HERTZ,
) )
from . import nut_ups_ns, NutUpsComponent, CONF_NUT_UPS_ID from . import ups_hid_ns, UpsHidComponent, CONF_UPS_HID_ID
DEPENDENCIES = ["nut_ups"] DEPENDENCIES = ["ups_hid"]
NutUpsSensor = nut_ups_ns.class_("NutUpsSensor", sensor.Sensor, cg.Component) UpsHidSensor = ups_hid_ns.class_("UpsHidSensor", sensor.Sensor, cg.Component)
SENSOR_TYPES = { SENSOR_TYPES = {
"battery_level": { "battery_level": {
@@ -60,18 +60,18 @@ SENSOR_TYPES = {
CONFIG_SCHEMA = sensor.sensor_schema( CONFIG_SCHEMA = sensor.sensor_schema(
NutUpsSensor, UpsHidSensor,
accuracy_decimals=1, accuracy_decimals=1,
).extend( ).extend(
{ {
cv.GenerateID(CONF_NUT_UPS_ID): cv.use_id(NutUpsComponent), cv.GenerateID(CONF_UPS_HID_ID): cv.use_id(UpsHidComponent),
cv.Required(CONF_TYPE): cv.one_of(*SENSOR_TYPES, lower=True), cv.Required(CONF_TYPE): cv.one_of(*SENSOR_TYPES, lower=True),
} }
) )
async def to_code(config): async def to_code(config):
parent = await cg.get_variable(config[CONF_NUT_UPS_ID]) parent = await cg.get_variable(config[CONF_UPS_HID_ID])
var = await sensor.new_sensor(config) var = await sensor.new_sensor(config)
await cg.register_component(var, config) await cg.register_component(var, config)
@@ -3,17 +3,17 @@
namespace esphome namespace esphome
{ {
namespace nut_ups namespace ups_hid
{ {
static const char *const TXT_TAG = "nut_ups.text_sensor"; static const char *const TXT_TAG = "ups_hid.text_sensor";
void NutUpsTextSensor::dump_config() void UpsHidTextSensor::dump_config()
{ {
ESP_LOGCONFIG(TXT_TAG, "NUT UPS Text Sensor:"); ESP_LOGCONFIG(TXT_TAG, "UPS HID Text Sensor:");
ESP_LOGCONFIG(TXT_TAG, " Type: %s", sensor_type_.c_str()); ESP_LOGCONFIG(TXT_TAG, " Type: %s", sensor_type_.c_str());
LOG_TEXT_SENSOR(" ", "Text Sensor", this); LOG_TEXT_SENSOR(" ", "Text Sensor", this);
} }
} // namespace nut_ups } // namespace ups_hid
} // namespace esphome } // namespace esphome
@@ -2,14 +2,14 @@
#include "esphome/core/component.h" #include "esphome/core/component.h"
#include "esphome/components/text_sensor/text_sensor.h" #include "esphome/components/text_sensor/text_sensor.h"
#include "nut_ups.h" #include "ups_hid.h"
namespace esphome namespace esphome
{ {
namespace nut_ups namespace ups_hid
{ {
class NutUpsTextSensor : public text_sensor::TextSensor, public Component class UpsHidTextSensor : public text_sensor::TextSensor, public Component
{ {
public: public:
void set_sensor_type(const std::string &type) { sensor_type_ = type; } void set_sensor_type(const std::string &type) { sensor_type_ = type; }
@@ -19,5 +19,5 @@ namespace esphome
std::string sensor_type_; std::string sensor_type_;
}; };
} // namespace nut_ups } // namespace ups_hid
} // namespace esphome } // namespace esphome
@@ -5,12 +5,12 @@ from esphome.const import (
CONF_TYPE, CONF_TYPE,
) )
from . import nut_ups_ns, NutUpsComponent, CONF_NUT_UPS_ID from . import ups_hid_ns, UpsHidComponent, CONF_UPS_HID_ID
DEPENDENCIES = ["nut_ups"] DEPENDENCIES = ["ups_hid"]
NutUpsTextSensor = nut_ups_ns.class_( UpsHidTextSensor = ups_hid_ns.class_(
"NutUpsTextSensor", text_sensor.TextSensor, cg.Component "UpsHidTextSensor", text_sensor.TextSensor, cg.Component
) )
TEXT_SENSOR_TYPES = [ TEXT_SENSOR_TYPES = [
@@ -23,16 +23,16 @@ TEXT_SENSOR_TYPES = [
] ]
CONFIG_SCHEMA = text_sensor.text_sensor_schema(NutUpsTextSensor).extend( CONFIG_SCHEMA = text_sensor.text_sensor_schema(UpsHidTextSensor).extend(
{ {
cv.GenerateID(CONF_NUT_UPS_ID): cv.use_id(NutUpsComponent), cv.GenerateID(CONF_UPS_HID_ID): cv.use_id(UpsHidComponent),
cv.Required(CONF_TYPE): cv.one_of(*TEXT_SENSOR_TYPES, lower=True), cv.Required(CONF_TYPE): cv.one_of(*TEXT_SENSOR_TYPES, lower=True),
} }
) )
async def to_code(config): async def to_code(config):
parent = await cg.get_variable(config[CONF_NUT_UPS_ID]) parent = await cg.get_variable(config[CONF_UPS_HID_ID])
var = await text_sensor.new_text_sensor(config) var = await text_sensor.new_text_sensor(config)
await cg.register_component(var, config) await cg.register_component(var, config)
@@ -1,4 +1,4 @@
#include "nut_ups.h" #include "ups_hid.h"
#include "ups_vendors.h" #include "ups_vendors.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "esphome/core/application.h" #include "esphome/core/application.h"
@@ -27,10 +27,10 @@
#endif #endif
namespace esphome { namespace esphome {
namespace nut_ups { namespace ups_hid {
void NutUpsComponent::setup() { void UpsHidComponent::setup() {
ESP_LOGCONFIG(TAG, "Setting up NUT UPS Component..."); ESP_LOGCONFIG(TAG, "Setting up UPS HID Component...");
if (simulation_mode_) { if (simulation_mode_) {
ESP_LOGW(TAG, "Running in simulation mode - no actual UPS communication"); ESP_LOGW(TAG, "Running in simulation mode - no actual UPS communication");
@@ -76,12 +76,12 @@ void NutUpsComponent::setup() {
connected_ = true; connected_ = true;
ESP_LOGI(TAG, "Successfully connected to UPS using %s", get_protocol_name().c_str()); ESP_LOGI(TAG, "Successfully connected to UPS using %s", get_protocol_name().c_str());
#else #else
ESP_LOGE(TAG, "NUT UPS component requires ESP32 platform"); ESP_LOGE(TAG, "UPS HID component requires ESP32 platform");
mark_failed(); mark_failed();
#endif #endif
} }
void NutUpsComponent::update() { void UpsHidComponent::update() {
if (simulation_mode_) { if (simulation_mode_) {
simulate_ups_data(); simulate_ups_data();
update_sensors(); update_sensors();
@@ -126,8 +126,8 @@ void NutUpsComponent::update() {
} }
} }
void NutUpsComponent::dump_config() { void UpsHidComponent::dump_config() {
ESP_LOGCONFIG(TAG, "NUT UPS Component:"); ESP_LOGCONFIG(TAG, "UPS HID Component:");
ESP_LOGCONFIG(TAG, " Simulation Mode: %s", simulation_mode_ ? "YES" : "NO"); ESP_LOGCONFIG(TAG, " Simulation Mode: %s", simulation_mode_ ? "YES" : "NO");
ESP_LOGCONFIG(TAG, " USB Vendor ID: 0x%04X", usb_vendor_id_); ESP_LOGCONFIG(TAG, " USB Vendor ID: 0x%04X", usb_vendor_id_);
ESP_LOGCONFIG(TAG, " USB Product ID: 0x%04X", usb_product_id_); ESP_LOGCONFIG(TAG, " USB Product ID: 0x%04X", usb_product_id_);
@@ -145,14 +145,14 @@ void NutUpsComponent::dump_config() {
} }
} }
std::string NutUpsComponent::get_protocol_name() const { std::string UpsHidComponent::get_protocol_name() const {
if (active_protocol_) { if (active_protocol_) {
return active_protocol_->get_protocol_name(); return active_protocol_->get_protocol_name();
} }
return "Unknown"; return "Unknown";
} }
bool NutUpsComponent::initialize_usb() { bool UpsHidComponent::initialize_usb() {
#ifdef USE_ESP32 #ifdef USE_ESP32
ESP_LOGD(TAG, "Initializing USB communication..."); ESP_LOGD(TAG, "Initializing USB communication...");
@@ -176,7 +176,7 @@ bool NutUpsComponent::initialize_usb() {
#endif #endif
} }
bool NutUpsComponent::should_log_error(ErrorRateLimit& limiter) { bool UpsHidComponent::should_log_error(ErrorRateLimit& limiter) {
uint32_t now = millis(); uint32_t now = millis();
// Check if we're past the rate limit window // Check if we're past the rate limit window
@@ -204,14 +204,14 @@ bool NutUpsComponent::should_log_error(ErrorRateLimit& limiter) {
return false; return false;
} }
void NutUpsComponent::log_suppressed_errors(ErrorRateLimit& limiter) { void UpsHidComponent::log_suppressed_errors(ErrorRateLimit& limiter) {
if (limiter.suppressed_count > 0) { if (limiter.suppressed_count > 0) {
ESP_LOGW(TAG, "Suppressed %u similar error messages", limiter.suppressed_count); ESP_LOGW(TAG, "Suppressed %u similar error messages", limiter.suppressed_count);
limiter.suppressed_count = 0; limiter.suppressed_count = 0;
} }
} }
bool NutUpsComponent::detect_ups_protocol() { bool UpsHidComponent::detect_ups_protocol() {
ESP_LOGD(TAG, "Detecting UPS protocol..."); ESP_LOGD(TAG, "Detecting UPS protocol...");
if (!auto_detect_protocol_) { if (!auto_detect_protocol_) {
@@ -381,7 +381,7 @@ bool NutUpsComponent::detect_ups_protocol() {
return false; return false;
} }
bool NutUpsComponent::read_ups_data() { bool UpsHidComponent::read_ups_data() {
if (!active_protocol_) { if (!active_protocol_) {
ESP_LOGW(TAG, "No active protocol available for reading data"); ESP_LOGW(TAG, "No active protocol available for reading data");
return false; return false;
@@ -410,7 +410,7 @@ bool NutUpsComponent::read_ups_data() {
return false; return false;
} }
void NutUpsComponent::update_sensors() { void UpsHidComponent::update_sensors() {
// Create local copy of data under lock to minimize lock time // Create local copy of data under lock to minimize lock time
UpsData local_data; UpsData local_data;
{ {
@@ -498,7 +498,7 @@ void NutUpsComponent::update_sensors() {
} }
} }
void NutUpsComponent::simulate_ups_data() { void UpsHidComponent::simulate_ups_data() {
static uint32_t sim_counter = 0; static uint32_t sim_counter = 0;
sim_counter++; sim_counter++;
@@ -559,19 +559,19 @@ void NutUpsComponent::simulate_ups_data() {
} }
} }
void NutUpsComponent::register_sensor(sensor::Sensor *sens, const std::string &type) { void UpsHidComponent::register_sensor(sensor::Sensor *sens, const std::string &type) {
sensors_[type] = sens; sensors_[type] = sens;
} }
void NutUpsComponent::register_binary_sensor(binary_sensor::BinarySensor *sens, const std::string &type) { void UpsHidComponent::register_binary_sensor(binary_sensor::BinarySensor *sens, const std::string &type) {
binary_sensors_[type] = sens; binary_sensors_[type] = sens;
} }
void NutUpsComponent::register_text_sensor(text_sensor::TextSensor *sens, const std::string &type) { void UpsHidComponent::register_text_sensor(text_sensor::TextSensor *sens, const std::string &type) {
text_sensors_[type] = sens; text_sensors_[type] = sens;
} }
bool NutUpsComponent::usb_write(const std::vector<uint8_t> &data) { bool UpsHidComponent::usb_write(const std::vector<uint8_t> &data) {
#ifdef USE_ESP32 #ifdef USE_ESP32
if (data.empty()) { if (data.empty()) {
return false; return false;
@@ -610,7 +610,7 @@ bool NutUpsComponent::usb_write(const std::vector<uint8_t> &data) {
#endif #endif
} }
bool NutUpsComponent::usb_read(std::vector<uint8_t> &data, uint32_t timeout_ms) { bool UpsHidComponent::usb_read(std::vector<uint8_t> &data, uint32_t timeout_ms) {
#ifdef USE_ESP32 #ifdef USE_ESP32
data.clear(); data.clear();
@@ -650,7 +650,7 @@ bool NutUpsComponent::usb_read(std::vector<uint8_t> &data, uint32_t timeout_ms)
} }
#ifdef USE_ESP32 #ifdef USE_ESP32
esp_err_t NutUpsComponent::usb_init() { esp_err_t UpsHidComponent::usb_init() {
ESP_LOGD(TAG, "Initializing USB Host..."); ESP_LOGD(TAG, "Initializing USB Host...");
if (usb_host_initialized_) { if (usb_host_initialized_) {
@@ -684,7 +684,7 @@ esp_err_t NutUpsComponent::usb_init() {
return ESP_OK; return ESP_OK;
} }
void NutUpsComponent::usb_deinit() { void UpsHidComponent::usb_deinit() {
ESP_LOGD(TAG, "Deinitializing USB Host..."); ESP_LOGD(TAG, "Deinitializing USB Host...");
if (!usb_host_initialized_) { if (!usb_host_initialized_) {
@@ -724,7 +724,7 @@ void NutUpsComponent::usb_deinit() {
ESP_LOGI(TAG, "USB Host deinitialized"); ESP_LOGI(TAG, "USB Host deinitialized");
} }
esp_err_t NutUpsComponent::usb_host_lib_init() { esp_err_t UpsHidComponent::usb_host_lib_init() {
usb_host_config_t host_config = { usb_host_config_t host_config = {
.skip_phy_setup = false, .skip_phy_setup = false,
.intr_flags = ESP_INTR_FLAG_LEVEL1, .intr_flags = ESP_INTR_FLAG_LEVEL1,
@@ -744,7 +744,7 @@ esp_err_t NutUpsComponent::usb_host_lib_init() {
return ESP_OK; return ESP_OK;
} }
esp_err_t NutUpsComponent::usb_client_register() { esp_err_t UpsHidComponent::usb_client_register() {
usb_host_client_config_t client_config = { usb_host_client_config_t client_config = {
.is_synchronous = false, .is_synchronous = false,
.max_num_event_msg = 5, .max_num_event_msg = 5,
@@ -763,7 +763,7 @@ esp_err_t NutUpsComponent::usb_client_register() {
return ESP_OK; return ESP_OK;
} }
esp_err_t NutUpsComponent::usb_device_enumerate() { esp_err_t UpsHidComponent::usb_device_enumerate() {
ESP_LOGD(TAG, "Enumerating USB devices..."); ESP_LOGD(TAG, "Enumerating USB devices...");
uint8_t dev_addr_list[10]; uint8_t dev_addr_list[10];
@@ -823,7 +823,7 @@ esp_err_t NutUpsComponent::usb_device_enumerate() {
return ESP_ERR_NOT_FOUND; return ESP_ERR_NOT_FOUND;
} }
bool NutUpsComponent::usb_is_ups_device(const usb_device_desc_t *desc) { bool UpsHidComponent::usb_is_ups_device(const usb_device_desc_t *desc) {
uint16_t vid = desc->idVendor; uint16_t vid = desc->idVendor;
uint16_t pid = desc->idProduct; uint16_t pid = desc->idProduct;
@@ -852,7 +852,7 @@ bool NutUpsComponent::usb_is_ups_device(const usb_device_desc_t *desc) {
return false; return false;
} }
esp_err_t NutUpsComponent::usb_claim_interface() { esp_err_t UpsHidComponent::usb_claim_interface() {
// Get active configuration // Get active configuration
const usb_config_desc_t *config_desc; const usb_config_desc_t *config_desc;
esp_err_t ret = usb_host_get_active_config_descriptor(usb_device_.dev_hdl, &config_desc); esp_err_t ret = usb_host_get_active_config_descriptor(usb_device_.dev_hdl, &config_desc);
@@ -891,7 +891,7 @@ esp_err_t NutUpsComponent::usb_claim_interface() {
return ESP_OK; return ESP_OK;
} }
esp_err_t NutUpsComponent::usb_get_endpoints() { esp_err_t UpsHidComponent::usb_get_endpoints() {
// Get active configuration // Get active configuration
const usb_config_desc_t *config_desc; const usb_config_desc_t *config_desc;
esp_err_t ret = usb_host_get_active_config_descriptor(usb_device_.dev_hdl, &config_desc); esp_err_t ret = usb_host_get_active_config_descriptor(usb_device_.dev_hdl, &config_desc);
@@ -940,7 +940,7 @@ esp_err_t NutUpsComponent::usb_get_endpoints() {
return ESP_OK; return ESP_OK;
} }
esp_err_t NutUpsComponent::usb_transfer_sync(const std::vector<uint8_t> &data_out, esp_err_t UpsHidComponent::usb_transfer_sync(const std::vector<uint8_t> &data_out,
std::vector<uint8_t> &data_in, std::vector<uint8_t> &data_in,
uint32_t timeout_ms) { uint32_t timeout_ms) {
if (!device_connected_ || !usb_device_.dev_hdl) { if (!device_connected_ || !usb_device_.dev_hdl) {
@@ -1030,8 +1030,8 @@ esp_err_t NutUpsComponent::usb_transfer_sync(const std::vector<uint8_t> &data_ou
return ret; return ret;
} }
void NutUpsComponent::usb_host_lib_task(void *arg) { void UpsHidComponent::usb_host_lib_task(void *arg) {
auto *component = static_cast<NutUpsComponent *>(arg); auto *component = static_cast<UpsHidComponent *>(arg);
ESP_LOGD(TAG, "USB Host task started"); ESP_LOGD(TAG, "USB Host task started");
@@ -1060,8 +1060,8 @@ void NutUpsComponent::usb_host_lib_task(void *arg) {
vTaskDelete(nullptr); vTaskDelete(nullptr);
} }
void NutUpsComponent::usb_client_event_callback(const usb_host_client_event_msg_t *event_msg, void *arg) { void UpsHidComponent::usb_client_event_callback(const usb_host_client_event_msg_t *event_msg, void *arg) {
auto *component = static_cast<NutUpsComponent *>(arg); auto *component = static_cast<UpsHidComponent *>(arg);
switch (event_msg->event) { switch (event_msg->event) {
case USB_HOST_CLIENT_EVENT_NEW_DEV: case USB_HOST_CLIENT_EVENT_NEW_DEV:
@@ -1105,5 +1105,5 @@ std::string UpsProtocolBase::bytes_to_string(const std::vector<uint8_t> &data) {
return result; return result;
} }
} // namespace nut_ups } // namespace ups_hid
} // namespace esphome } // namespace esphome
@@ -31,10 +31,10 @@
namespace esphome namespace esphome
{ {
namespace nut_ups namespace ups_hid
{ {
static const char *const TAG = "nut_ups"; static const char *const TAG = "ups_hid";
// UPS status flags // UPS status flags
enum UpsStatus enum UpsStatus
@@ -107,17 +107,17 @@ namespace esphome
class CyberPowerProtocol; class CyberPowerProtocol;
class GenericHidProtocol; class GenericHidProtocol;
class NutUpsComponent : public PollingComponent class UpsHidComponent : public PollingComponent
{ {
public: public:
NutUpsComponent() : usb_device_{}, usb_mutex_(nullptr), usb_task_handle_(nullptr), UpsHidComponent() : usb_device_{}, usb_mutex_(nullptr), usb_task_handle_(nullptr),
usb_host_initialized_(false), device_connected_(false) { usb_host_initialized_(false), device_connected_(false) {
#ifdef USE_ESP32 #ifdef USE_ESP32
memset(&usb_device_, 0, sizeof(usb_device_)); memset(&usb_device_, 0, sizeof(usb_device_));
#endif #endif
} }
~NutUpsComponent() { ~UpsHidComponent() {
#ifdef USE_ESP32 #ifdef USE_ESP32
// Log any remaining suppressed errors before cleanup // Log any remaining suppressed errors before cleanup
log_suppressed_errors(usb_error_limiter_); log_suppressed_errors(usb_error_limiter_);
@@ -255,7 +255,7 @@ namespace esphome
class UpsProtocolBase class UpsProtocolBase
{ {
public: public:
explicit UpsProtocolBase(NutUpsComponent *parent) : parent_(parent) {} explicit UpsProtocolBase(UpsHidComponent *parent) : parent_(parent) {}
virtual ~UpsProtocolBase() = default; virtual ~UpsProtocolBase() = default;
virtual bool detect() = 0; virtual bool detect() = 0;
@@ -265,7 +265,7 @@ namespace esphome
virtual std::string get_protocol_name() const = 0; virtual std::string get_protocol_name() const = 0;
protected: protected:
NutUpsComponent *parent_; UpsHidComponent *parent_;
bool send_command(const std::vector<uint8_t> &cmd, std::vector<uint8_t> &response, uint32_t timeout_ms = 1000); bool send_command(const std::vector<uint8_t> &cmd, std::vector<uint8_t> &response, uint32_t timeout_ms = 1000);
std::string bytes_to_string(const std::vector<uint8_t> &data); std::string bytes_to_string(const std::vector<uint8_t> &data);
@@ -275,7 +275,7 @@ namespace esphome
class ApcSmartProtocol : public UpsProtocolBase class ApcSmartProtocol : public UpsProtocolBase
{ {
public: public:
explicit ApcSmartProtocol(NutUpsComponent *parent) : UpsProtocolBase(parent) {} explicit ApcSmartProtocol(UpsHidComponent *parent) : UpsProtocolBase(parent) {}
bool detect() override; bool detect() override;
bool initialize() override; bool initialize() override;
@@ -294,7 +294,7 @@ namespace esphome
class CyberPowerProtocol : public UpsProtocolBase class CyberPowerProtocol : public UpsProtocolBase
{ {
public: public:
explicit CyberPowerProtocol(NutUpsComponent *parent) : UpsProtocolBase(parent) {} explicit CyberPowerProtocol(UpsHidComponent *parent) : UpsProtocolBase(parent) {}
bool detect() override; bool detect() override;
bool initialize() override; bool initialize() override;
@@ -321,7 +321,7 @@ namespace esphome
class GenericHidProtocol : public UpsProtocolBase class GenericHidProtocol : public UpsProtocolBase
{ {
public: public:
explicit GenericHidProtocol(NutUpsComponent *parent) : UpsProtocolBase(parent) {} explicit GenericHidProtocol(UpsHidComponent *parent) : UpsProtocolBase(parent) {}
bool detect() override; bool detect() override;
bool initialize() override; bool initialize() override;
@@ -333,5 +333,5 @@ namespace esphome
bool parse_generic_report(const std::vector<uint8_t>& response, UpsData& data); bool parse_generic_report(const std::vector<uint8_t>& response, UpsData& data);
}; };
} // namespace nut_ups } // namespace ups_hid
} // namespace esphome } // namespace esphome
+76
View File
@@ -0,0 +1,76 @@
#pragma once
/**
* @file ups_vendors.h
* @brief Known UPS vendor IDs for device identification and validation
*
* This file contains the definitive list of known UPS vendor IDs
* shared between C++ runtime code and Python configuration validation.
*/
namespace esphome
{
namespace ups_hid
{
// Known UPS vendor IDs with their names
struct UpsVendor
{
uint16_t vendor_id;
const char *name;
const char *description;
};
// Definitive list of known UPS vendors (based on NUT project driver.list)
static constexpr UpsVendor KNOWN_UPS_VENDORS[] = {
//{0x0001, "Generic/Other", "Generic UPS vendors (multiple brands)"},
{0x0463, "MGE Office Protection Systems", "MGE Office Protection Systems"},
{0x050D, "Belkin", "Belkin (older USB UPS models)"},
{0x051D, "APC", "American Power Conversion"},
{0x05B8, "SVEN", "SVEN UPS devices"},
{0x0665, "Cypress/Belkin", "Cypress or Belkin UPS devices"},
{0x06DA, "MGE UPS Systems", "MGE UPS Systems (now Eaton)"},
{0x0764, "CyberPower", "CyberPower Systems"},
{0x0925, "Richcomm", "Richcomm Technologies (Digitus, Sweex)"},
{0x09AE, "Tripp Lite", "Tripp Lite"},
{0x09D6, "Micropower", "Micropower UPS devices"},
};
static constexpr size_t KNOWN_UPS_VENDORS_COUNT = sizeof(KNOWN_UPS_VENDORS) / sizeof(KNOWN_UPS_VENDORS[0]);
/**
* Check if a vendor ID is in the known UPS vendors list
* @param vendor_id The USB vendor ID to check
* @return True if vendor ID is known, false otherwise
*/
inline bool is_known_ups_vendor(uint16_t vendor_id)
{
for (size_t i = 0; i < KNOWN_UPS_VENDORS_COUNT; i++)
{
if (KNOWN_UPS_VENDORS[i].vendor_id == vendor_id)
{
return true;
}
}
return false;
}
/**
* Get vendor name for a given vendor ID
* @param vendor_id The USB vendor ID
* @return Vendor name or nullptr if unknown
*/
inline const char *get_ups_vendor_name(uint16_t vendor_id)
{
for (size_t i = 0; i < KNOWN_UPS_VENDORS_COUNT; i++)
{
if (KNOWN_UPS_VENDORS[i].vendor_id == vendor_id)
{
return KNOWN_UPS_VENDORS[i].name;
}
}
return nullptr;
}
} // namespace ups_hid
} // namespace esphome
+38 -38
View File
@@ -1,12 +1,12 @@
substitutions: substitutions:
name: nut-ups-monitor-full-test name: ups-hid-monitor-full-test
friendly_name: "NUT UPS Monitor" friendly_name: "UPS HID Monitor"
timezone: "America/New_York" timezone: "America/New_York"
esphome: esphome:
name: "${name}" name: "${name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
comment: "Full test configuration for NUT UPS Component with ESP32-S3" comment: "Full test configuration for UPS HID Component with ESP32-S3"
esp32: esp32:
board: esp32-s3-devkitc-1 board: esp32-s3-devkitc-1
@@ -18,7 +18,7 @@ esp32:
logger: logger:
level: VERBOSE level: VERBOSE
logs: logs:
nut_ups: DEBUG ups_hid: DEBUG
# Enable Home Assistant API # Enable Home Assistant API
api: api:
@@ -98,8 +98,8 @@ external_components:
type: local type: local
path: components path: components
# Main NUT UPS Component Configuration # Main UPS HID Component Configuration
nut_ups: ups_hid:
id: ups_monitor id: ups_monitor
update_interval: 10s update_interval: 10s
@@ -117,8 +117,8 @@ nut_ups:
# Numeric Sensors # Numeric Sensors
sensor: sensor:
# Essential UPS metrics # Essential UPS metrics
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "Battery Level" name: "Battery Level"
id: battery_level id: battery_level
type: battery_level type: battery_level
@@ -127,8 +127,8 @@ sensor:
state_class: measurement state_class: measurement
accuracy_decimals: 0 accuracy_decimals: 0
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "Input Voltage" name: "Input Voltage"
id: input_voltage id: input_voltage
type: input_voltage type: input_voltage
@@ -137,8 +137,8 @@ sensor:
state_class: measurement state_class: measurement
accuracy_decimals: 1 accuracy_decimals: 1
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "Output Voltage" name: "Output Voltage"
id: output_voltage id: output_voltage
type: output_voltage type: output_voltage
@@ -147,8 +147,8 @@ sensor:
state_class: measurement state_class: measurement
accuracy_decimals: 1 accuracy_decimals: 1
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "Load Percentage" name: "Load Percentage"
id: load_percentage id: load_percentage
type: load_percent type: load_percent
@@ -157,8 +157,8 @@ sensor:
state_class: measurement state_class: measurement
accuracy_decimals: 0 accuracy_decimals: 0
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "Runtime Remaining" name: "Runtime Remaining"
id: runtime_remaining id: runtime_remaining
type: runtime type: runtime
@@ -167,8 +167,8 @@ sensor:
state_class: measurement state_class: measurement
accuracy_decimals: 0 accuracy_decimals: 0
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "Input Frequency" name: "Input Frequency"
id: input_frequency id: input_frequency
type: frequency type: frequency
@@ -212,8 +212,8 @@ sensor:
# Binary Sensors for UPS status # Binary Sensors for UPS status
binary_sensor: binary_sensor:
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "UPS Online" name: "UPS Online"
id: ups_online id: ups_online
type: online type: online
@@ -227,15 +227,15 @@ binary_sensor:
format: "POWER OUTAGE: UPS switched to battery power" format: "POWER OUTAGE: UPS switched to battery power"
level: WARN level: WARN
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "On Battery Power" name: "On Battery Power"
id: on_battery id: on_battery
type: on_battery type: on_battery
device_class: battery device_class: battery
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "Low Battery Warning" name: "Low Battery Warning"
id: low_battery id: low_battery
type: low_battery type: low_battery
@@ -245,22 +245,22 @@ binary_sensor:
- script.execute: ups_shutdown_warning - script.execute: ups_shutdown_warning
- script.execute: notify_critical - script.execute: notify_critical
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "UPS Fault" name: "UPS Fault"
id: ups_fault id: ups_fault
type: fault type: fault
device_class: problem device_class: problem
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "Battery Charging" name: "Battery Charging"
id: battery_charging id: battery_charging
type: charging type: charging
device_class: battery device_class: battery
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "Overload Warning" name: "Overload Warning"
id: overload_warning id: overload_warning
type: overload type: overload
@@ -284,26 +284,26 @@ binary_sensor:
# Text Sensors for UPS information # Text Sensors for UPS information
text_sensor: text_sensor:
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "UPS Model" name: "UPS Model"
id: ups_model id: ups_model
type: model type: model
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "UPS Manufacturer" name: "UPS Manufacturer"
id: ups_manufacturer id: ups_manufacturer
type: manufacturer type: manufacturer
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "UPS Status" name: "UPS Status"
id: ups_status_text id: ups_status_text
type: status type: status
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "Detected Protocol" name: "Detected Protocol"
id: ups_protocol id: ups_protocol
type: protocol type: protocol
+18 -18
View File
@@ -1,7 +1,7 @@
esphome: esphome:
name: nut-ups-monitor-minimal-test name: ups-hid-monitor-minimal-test
friendly_name: "NUT UPS Monitor" friendly_name: "UPS HID Monitor"
comment: "Full test configuration for NUT UPS Component with ESP32-S3" comment: "Full test configuration for UPS HID Component with ESP32-S3"
esp32: esp32:
board: esp32-s3-devkitc-1 board: esp32-s3-devkitc-1
@@ -26,7 +26,7 @@ wifi:
ssid: !secret wifi_ssid ssid: !secret wifi_ssid
password: !secret wifi_password password: !secret wifi_password
ap: ap:
ssid: "NUT-UPS-Monitor" ssid: "UPS-HID-Monitor"
password: !secret ap_password password: !secret ap_password
captive_portal: captive_portal:
@@ -61,8 +61,8 @@ external_components:
type: local type: local
path: components path: components
# NUT UPS Component # UPS HID Component
nut_ups: ups_hid:
id: ups_monitor id: ups_monitor
simulation_mode: true # Set to false for production simulation_mode: true # Set to false for production
update_interval: 5s update_interval: 5s
@@ -73,8 +73,8 @@ nut_ups:
# Sensors # Sensors
sensor: sensor:
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "UPS Battery Level" name: "UPS Battery Level"
id: ups_battery_level id: ups_battery_level
type: battery_level type: battery_level
@@ -83,8 +83,8 @@ sensor:
state_class: measurement state_class: measurement
accuracy_decimals: 0 accuracy_decimals: 0
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "UPS Runtime" name: "UPS Runtime"
id: ups_runtime id: ups_runtime
type: runtime type: runtime
@@ -95,15 +95,15 @@ sensor:
# Binary Sensors # Binary Sensors
binary_sensor: binary_sensor:
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "UPS On Battery" name: "UPS On Battery"
id: ups_on_battery id: ups_on_battery
type: on_battery type: on_battery
device_class: battery device_class: battery
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "UPS Fault" name: "UPS Fault"
id: ups_fault id: ups_fault
type: fault type: fault
@@ -111,14 +111,14 @@ binary_sensor:
# Text Sensors # Text Sensors
text_sensor: text_sensor:
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "UPS Status" name: "UPS Status"
id: ups_status id: ups_status
type: status type: status
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "UPS Model" name: "UPS Model"
id: ups_model id: ups_model
type: model type: model
+9 -9
View File
@@ -16,7 +16,7 @@ esp32:
logger: logger:
level: VERBOSE level: VERBOSE
logs: logs:
nut_ups: DEBUG ups_hid: DEBUG
api: api:
encryption: encryption:
@@ -36,30 +36,30 @@ external_components:
path: components path: components
# Test with unknown vendor ID to trigger validation warning # Test with unknown vendor ID to trigger validation warning
nut_ups: ups_hid:
id: ups_monitor id: ups_monitor
update_interval: 30s update_interval: 30s
usb_vendor_id: 0x9999 # Unknown vendor ID - should trigger warning usb_vendor_id: 0x9999 # Unknown vendor ID - should trigger warning
usb_product_id: 0x0001 usb_product_id: 0x0001
auto_detect_protocol: true auto_detect_protocol: true
protocol_timeout: 15s protocol_timeout: 15s
simulation_mode: true simulation_mode: true
sensor: sensor:
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "Battery Level" name: "Battery Level"
type: battery_level type: battery_level
unit_of_measurement: "%" unit_of_measurement: "%"
binary_sensor: binary_sensor:
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "UPS Online" name: "UPS Online"
type: online type: online
text_sensor: text_sensor:
- platform: nut_ups - platform: ups_hid
nut_ups_id: ups_monitor ups_hid_id: ups_monitor
name: "UPS Status" name: "UPS Status"
type: status type: status