feat(energy-control): add solar-based automatic mode switching#5
Conversation
|
@codex please review this PR only for critical or harmful issues. Focus on whether:
This is an MVP running in real conditions. Please report only issues that could cause incorrect, unsafe, or damaging behavior. Ignore nice-to-have improvements, broad refactoring, style suggestions, and speculative edge cases. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a1214b2782
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if ( | ||
| last_command_timestamp is not None | ||
| and current_timestamp - last_command_timestamp | ||
| < ENERGY_MODE_COMMAND_COOLDOWN_SECONDS | ||
| ): |
There was a problem hiding this comment.
Do not let cooldowns block outage switches
When grid state toggles and GRID_OUTAGE_TARGET_MODE differs from the solar/time target, a lower-priority rule can send the opposite mode while the grid is briefly available, then this same-target cooldown blocks the next outage command for up to 5 minutes. With the example defaults of solar SBU and outage SUB, an outage at t0 sends SUB, recovery at t1 can send solar SBU, and a second outage at t2 returns here without sending the configured outage SUB even though the current mode is now SBU, bypassing the declared highest-priority safety rule.
Useful? React with 👍 / 👎.
| averages = { | ||
| field: sum(sample[field] for sample in valid_samples) | ||
| / len(valid_samples) | ||
| for field in REQUIRED_TELEMETRY_FIELDS | ||
| } |
There was a problem hiding this comment.
Require current samples to satisfy hard solar limits
The solar switch decision averages the whole lookback, so a dangerous latest reading can be hidden by earlier good samples. For example, seven low-load samples plus one current load spike can keep average PLoad under the threshold and still switch from SUB to solar/battery priority exactly when the current load exceeds the configured maximum; the same applies to a current battery-voltage or PV drop. For real operation, the latest sample or per-sample hard limits need to pass before allowing the switch.
Useful? React with 👍 / 👎.
Adds autonomous inverter mode switching based on time window, grid availability, and recent battery, PV, and load conditions.