Skip to content

Commit 1b0af6f

Browse files
authored
Merge pull request #87 from Monitor-My-Solar/monitorMySolarStaging
Monitor my solar staging
2 parents 2ed8e68 + 13f6be2 commit 1b0af6f

16 files changed

Lines changed: 1308 additions & 195 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
custom_components/monitormysolar/__pycache__
33
custom_components/monitormysolar/.claude
44
custom_components/monitormysolar/docs/
5+
custom_components/monitormysolar/registers
56
./claude
67
*.claude
78
claude.md
8-
docs/
9+
docs/

custom_components/monitormysolar/CHANGELOG.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,88 @@
11
# Changelog
22

3+
## Version 3.1.0 - GridBoss Enhancements & Performance Improvements
4+
5+
### 🔄 **Important: GridBoss Upgrade Instructions**
6+
If you are using GridBoss functionality, please follow these steps to upgrade:
7+
1. **Delete the integration** from Home Assistant
8+
2. **Reboot** Home Assistant
9+
3. **Update through HACS** to get the latest version
10+
4. **Re-setup** the integration with your GridBoss configuration
11+
12+
This ensures a clean upgrade and prevents any configuration conflicts with the new GridBoss features.
13+
- **Multi-Inverter**: Enhanced support for parallel inverter configurations with GridBoss
14+
15+
### 🚀 Major Performance Improvements
16+
- **Fixed Home Assistant Slow Startup**: Implemented startup delay to prevent MQTT message processing during HA initialization
17+
- **Eliminated Excessive Coordinator Updates**: Reduced coordinator update frequency from every 1.5 seconds to only when needed
18+
- **Optimized MQTT Processing**: Deferred non-critical MQTT message processing until after HA startup completion
19+
- **Improved Main Thread Performance**: Prevented blocking operations during Home Assistant startup
20+
- **Resolved Bootstrap Timeout**: Fixed blocking `while True:` loop in SyncStatusSensor that was causing 5+ minute startup times
21+
- **Non-Blocking Async Scheduling**: Replaced blocking loops with proper async scheduling using `async_call_later()`
22+
23+
### 🔧 GridBoss Configuration & Setup Fixes
24+
- **Enhanced Config Flow**: Added dedicated GridBoss configuration step with proper dongle selection
25+
- **Improved Error Handling**: Added comprehensive error handling for dongle connectivity and firmware code reception
26+
- **Fixed Entity Creation Logic**: Implemented strict GridBoss entity filtering to prevent creation of unnecessary standard entities
27+
- **Corrected Device Naming**: Fixed GridBoss device naming to display "GridBoss" instead of generic names
28+
29+
### 📡 GridBoss MQTT & Payload Processing
30+
- **Fixed Nested Payload Parsing**: Implemented proper handling of GridBoss nested JSON payload structure
31+
- **Corrected Entity Name Mapping**: Fixed mapping between payload keys and entity unique_ids
32+
- **Enhanced Topic Routing**: Improved MQTT topic routing for GridBoss-specific settings
33+
- **Simplified Payload Processing**: Streamlined nested data processing with recursive flattening
34+
35+
### 🛠️ Technical Improvements
36+
- **Removed Complex Throttling**: Simplified coordinator update mechanism for better performance
37+
- **Enhanced Fault/Warning Deduplication**: Prevented duplicate processing of identical fault/warning data
38+
- **Improved Entity Type Determination**: Optimized entity type detection for better performance
39+
- **Better Error Recovery**: Enhanced error handling and recovery mechanisms
40+
41+
### 🎯 User Experience Enhancements
42+
- **Faster Home Assistant Startup**: Reduced startup time by deferring MQTT processing
43+
- **Cleaner Debug Logs**: Eliminated excessive "Manually updated MonitorySolar Coordinator data" messages
44+
- **More Responsive Interface**: Home Assistant becomes responsive much faster after restart
45+
- **Better Configuration Flow**: Improved GridBoss setup process with clear error messages
46+
47+
### 🔄 Backward Compatibility
48+
- **Maintained All Existing Features**: All previous functionality preserved
49+
- **No Breaking Changes**: Existing configurations continue to work without modification
50+
- **Preserved Entity History**: All entity data and settings remain intact
51+
- **Seamless Upgrade Path**: No manual intervention required for existing users
52+
53+
### 📋 Technical Details
54+
- **Startup Delay**: 30-second delay before MQTT message processing begins
55+
- **Firmware Code Processing**: Still processed immediately for proper entity creation
56+
- **GridBoss Entity Filtering**: Only creates entities explicitly allowed for "IAAB" firmware
57+
- **Payload Structure**: Supports both old and new nested payload formats
58+
59+
### 🐛 Bug Fixes
60+
- Fixed `IndentationError` in sensor.py that prevented integration loading
61+
- Resolved `NameError: name 'data_to_process' is not defined` in coordinator
62+
- Fixed GridBoss entity count issues (was creating ~400 entities, now creates only relevant ones)
63+
- Corrected GridBoss device naming in Home Assistant interface
64+
- Fixed nested payload parsing for GridBoss settings updates
65+
- **Fixed Home Assistant startup timeout**: Replaced blocking `while True:` loop in SyncStatusSensor with non-blocking async scheduling
66+
- **Resolved 5+ minute startup times**: Prevented bootstrap timeout warnings and excessive coordinator updates during startup
67+
- **Fixed GridBoss MQTT routing issue**: GridBoss settings were incorrectly being sent to bank-specific topics instead of the standard `/update` topic, causing settings to be rejected
68+
- **Enhanced GridBoss conditional entity system**: Implemented hierarchical availability logic based on Port Mode → SOC/Volt mode → Enable state
69+
- **Added Port Mode selects**: New SmartLoad1-4 Port Mode selects with proper numeric value mapping (0=Does Not Operate, 1=Smart Load, 2=AC Coupled)
70+
- **Fixed switch availability logic**: Added proper availability checking to switch entities based on Port Mode, SOC/Volt mode, and SmartLoad enable state
71+
- **Firmware code persistence**: Firmware codes are now saved to config entry data and only requested when not already available, improving startup performance
72+
- **Fixed availability timing issue**: Added 0.5s delay to availability updates to prevent blocking legitimate user actions when Port Mode changes
73+
- **Removed availability blocking from user actions**: Availability logic now only affects UI display (grayed out entities) but no longer blocks user actions, preventing the "revert" issue
74+
- **Fixed select entity revert issue**: Select entities now properly store previous state before changing and revert correctly on MQTT failure, preventing the auto-revert issue with Port Mode selects
75+
- **Fixed coordinator override issue**: Added user-initiated change flag to prevent coordinator from overriding user selections during MQTT processing, solving the select revert problem
76+
- **Fixed availability delay issue**: Port Mode changes now trigger immediate availability updates, and enable switches are always available when Port Mode is set to "Smart Load" or "AC Coupled" (both SmartLoad and AC Coupled enable switches)
77+
- **Added SOC/Volt mode select entities**: New SmartLoad1-4 Mode selects with "Time" and "SOC/Volt" options, available when Port Mode is set to "Smart Load" or "AC Coupled"
78+
79+
### 📝 Notes
80+
- **Dongle Firmware**: Requires dongle firmware 3.1.0+ for optimal GridBoss functionality
81+
- **Performance**: Significant improvement in Home Assistant startup time
82+
- **GridBoss**: Full support for GridBoss units with firmware code "IAAB"
83+
84+
---
85+
386
## Version 3.0.1 - GridBoss Support & Enhanced Multi-Inverter Features
487

588
### Minimum Requirements include the dongle Firmware 3.0.0> if your dongle is below this then a OTA update will be required.
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
# Conditional Entity System for GridBoss SmartLoad Settings
2+
3+
## Overview
4+
5+
This document describes the implementation of a conditional entity system that dynamically enables/disables GridBoss SmartLoad settings based on two key configurations:
6+
1. **SmartSOCVoltBits**: Controls SOC/Volt vs Time mode
7+
2. **SmartLoad Bits**: Controls which SmartLoads are enabled
8+
9+
This solves the challenge of having dependent settings where some values can only be set when other settings have specific values.
10+
11+
## Problem Statement
12+
13+
In GridBoss systems, certain settings have dependencies:
14+
15+
### SmartLoad Enable/Disable
16+
- **Disabled SmartLoads**: When `SmartLoadX_Enable` is `false`, all related settings should be unavailable
17+
- **Enabled SmartLoads**: When `SmartLoadX_Enable` is `true`, related settings become available
18+
19+
### SOC/Volt vs Time Mode
20+
- **SOC/Volt Mode**: When `SmartLoadX_SOC_Volt` is `true`, only SOC and voltage-based settings are available
21+
- **Time Mode**: When `SmartLoadX_SOC_Volt` is `false`, only time-based settings are available
22+
23+
### Always Available Settings
24+
- **Enable/Disable Switches**: Always available regardless of other settings
25+
26+
Home Assistant doesn't provide built-in popup alerts or dynamic entity enabling/disabling, so we needed a creative solution.
27+
28+
## Solution Architecture
29+
30+
### 1. SmartSOCVoltBits and SmartLoad Bits Tracking
31+
32+
The coordinator now tracks both configuration types for each dongle:
33+
34+
```python
35+
self._smart_soc_volt_bits = {} # Track SmartSOCVoltBits for each dongle
36+
self._smartload_bits = {} # Track SmartLoad Bits for each dongle
37+
```
38+
39+
### 2. Entity Availability System
40+
41+
Entities use the `available` property to dynamically show/hide based on dependency settings:
42+
43+
```python
44+
@property
45+
def available(self) -> bool:
46+
"""Return if entity is available."""
47+
if not self.coordinator.last_update_success:
48+
return False
49+
50+
# Check if entity should be available based on SmartLoad SOC/Volt settings
51+
return self.coordinator.is_entity_available_for_smartload(self._dongle_id, self._entity_type)
52+
```
53+
54+
### 3. Validation and User Feedback
55+
56+
When users try to set invalid values, the system:
57+
1. Prevents the setting from being applied
58+
2. Shows a persistent notification explaining why the setting is unavailable
59+
3. Logs a warning message
60+
61+
## Implementation Details
62+
63+
### Coordinator Methods
64+
65+
#### `update_smart_soc_volt_bits(dongle_id, smart_soc_volt_bits)`
66+
Updates the SmartSOCVoltBits settings and triggers entity availability updates.
67+
68+
#### `update_smartload_bits(dongle_id, smartload_bits)`
69+
Updates the SmartLoad Bits settings and triggers entity availability updates.
70+
71+
#### `is_entity_available_for_smartload(dongle_id, entity_unique_id)`
72+
Determines if an entity should be available based on:
73+
- Whether it's a GridBoss dongle
74+
- The SmartLoad number (1-4)
75+
- Whether the SmartLoad is enabled
76+
- Whether it's a SOC/Volt or Time entity
77+
- The current SmartSOCVoltBits setting
78+
79+
#### `is_smartload_enabled(dongle_id, smartload_number)`
80+
Checks if a specific SmartLoad is enabled.
81+
82+
#### `is_entity_available_for_smartload_enable(dongle_id, entity_unique_id)`
83+
Checks availability based only on SmartLoad enable state (used for Enable/Disable switches).
84+
85+
#### `_trigger_entity_availability_update(dongle_id)`
86+
Triggers async updates to entity availability when SmartSOCVoltBits change.
87+
88+
### Entity Classification
89+
90+
The system classifies entities into categories:
91+
92+
**SOC/Volt Entities** (available when `SmartLoadX_SOC_Volt` is `true`):
93+
- `StartSOC`, `EndSOC`
94+
- `StartVolt`, `EndVolt`
95+
- `SheddingStartSOC`, `SheddingEndSOC`
96+
- `SheddingStartVolt`, `SheddingEndVolt`
97+
98+
**Time Entities** (available when `SmartLoadX_SOC_Volt` is `false`):
99+
- `Start0`, `End0`
100+
- `Start1`, `End1`
101+
- `Start2`, `End2`
102+
103+
### User Experience
104+
105+
1. **Visual Feedback**: Unavailable entities appear grayed out in Home Assistant
106+
2. **Prevention**: Users cannot set values on unavailable entities
107+
3. **Notifications**: Clear explanations when users try to access unavailable settings
108+
4. **Dynamic Updates**: Entities become available/unavailable automatically when SmartSOCVoltBits change
109+
110+
## Example Usage
111+
112+
### Complete SmartLoad Configuration
113+
114+
```json
115+
"SmartLoad": {
116+
"Bits": {
117+
"SmartLoad1_Enable": true,
118+
"SmartLoad2_Enable": true,
119+
"SmartLoad3_Enable": false,
120+
"SmartLoad4_Enable": false
121+
}
122+
},
123+
"SmartSOCVoltBits": {
124+
"SmartLoad1_SOC_Volt": true,
125+
"SmartLoad2_SOC_Volt": false,
126+
"SmartLoad3_SOC_Volt": true,
127+
"SmartLoad4_SOC_Volt": false
128+
}
129+
```
130+
131+
**Result**:
132+
- **SmartLoad1**: ✅ Enabled + SOC/Volt mode → SOC/Volt entities available, Time entities unavailable
133+
- **SmartLoad2**: ✅ Enabled + Time mode → Time entities available, SOC/Volt entities unavailable
134+
- **SmartLoad3**: ❌ Disabled → All entities unavailable (except Enable switch)
135+
- **SmartLoad4**: ❌ Disabled → All entities unavailable (except Enable switch)
136+
137+
### User Interaction Examples
138+
139+
#### Example 1: Disabled SmartLoad
140+
1. User tries to set `SmartLoad3StartSOC` when `SmartLoad3_Enable` is `false`
141+
2. System shows notification: "The setting 'SmartLoad3 Start SOC' is not available because SmartLoad3 is disabled. Please enable SmartLoad3 first."
142+
3. Entity remains grayed out until SmartLoad3 is enabled
143+
144+
#### Example 2: Wrong Mode
145+
1. User tries to set `SmartLoad1Start0` (time entity) when `SmartLoad1_SOC_Volt` is `true`
146+
2. System shows notification: "The setting 'SmartLoad1 Start0' is not available because SmartLoad1 is configured for Time mode. Please change to SOC/Volt mode first."
147+
3. Entity remains grayed out until SmartLoad mode changes
148+
149+
#### Example 3: Always Available
150+
1. User can always access `SmartLoad1_Enable` switch regardless of other settings
151+
2. This allows users to enable/disable SmartLoads as needed
152+
153+
## Benefits
154+
155+
1. **Prevents Invalid Configurations**: Users cannot set conflicting settings
156+
2. **Clear User Feedback**: Persistent notifications explain why settings are unavailable
157+
3. **Dynamic Behavior**: Entities automatically update when dependencies change
158+
4. **No Breaking Changes**: Existing functionality remains intact
159+
5. **Extensible**: System can be extended for other conditional settings
160+
161+
## Technical Notes
162+
163+
- The system uses Home Assistant's built-in `available` property
164+
- Persistent notifications provide user feedback without popups
165+
- Entity availability updates are triggered asynchronously
166+
- The system gracefully handles missing or incomplete SmartSOCVoltBits data
167+
- All changes are backward compatible
168+
169+
## Future Enhancements
170+
171+
1. **Additional Dependencies**: Extend to other conditional settings
172+
2. **Bulk Operations**: Handle multiple entity updates more efficiently
173+
3. **Configuration UI**: Add visual indicators in the configuration flow
174+
4. **Automation Support**: Allow automations to be aware of entity availability

custom_components/monitormysolar/binary_sensor.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,26 @@ async def async_setup_entry(
3232
for dongle_id in dongle_ids:
3333
firmware_code = coordinator.get_firmware_code(dongle_id)
3434

35+
# Only create entities if we have a firmware code
36+
if not firmware_code:
37+
LOGGER.debug(f"Skipping entity creation for {dongle_id} - no firmware code available yet")
38+
continue
39+
3540
# Loop through the sensors in the configuration for this dongle
3641
for bank_name, sensors in sensors_config.items():
3742
for sensor in sensors:
43+
allowed_firmware_codes = sensor.get("allowed_firmware_codes", [])
44+
# For GridBoss dongles (IAAB), only create entities that explicitly allow this firmware code
45+
if coordinator.is_gridboss_dongle(dongle_id):
46+
if not allowed_firmware_codes or firmware_code not in allowed_firmware_codes:
47+
continue
48+
else:
49+
# For regular dongles, use the original logic
50+
if not allowed_firmware_codes or firmware_code in allowed_firmware_codes:
51+
pass # Continue to entity creation
52+
else:
53+
continue # Skip this entity
54+
3855
if bank_name == "battery":
3956
entities.append(
4057
BatteryStatusBinarySensor(sensor, hass, entry, dongle_id)

custom_components/monitormysolar/button.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,26 @@ async def async_setup_entry(hass, entry: MonitorMySolarEntry, async_add_entities
2424
firmware_code = coordinator.get_firmware_code(dongle_id)
2525
device_type = FIRMWARE_CODES.get(firmware_code, {}).get("Device_Type", "")
2626

27+
# Only create entities if we have a firmware code
28+
if not firmware_code:
29+
LOGGER.debug(f"Skipping entity creation for {dongle_id} - no firmware code available yet")
30+
continue
31+
2732
# Process buttons for this dongle
2833
for bank_name, buttons in buttons_config.items():
2934
for button in buttons:
35+
allowed_firmware_codes = button.get("allowed_firmware_codes", [])
36+
# For GridBoss dongles (IAAB), only create entities that explicitly allow this firmware code
37+
if coordinator.is_gridboss_dongle(dongle_id):
38+
if not allowed_firmware_codes or firmware_code not in allowed_firmware_codes:
39+
continue
40+
else:
41+
# For regular dongles, use the original logic
42+
if not allowed_firmware_codes or firmware_code in allowed_firmware_codes:
43+
pass # Continue to entity creation
44+
else:
45+
continue # Skip this entity
46+
3047
try:
3148
if bank_name == "inputbank1":
3249
entities.append(

0 commit comments

Comments
 (0)