Skip to content

feat(energy-control): add solar-based automatic mode switching#5

Open
deKibi wants to merge 10 commits into
mainfrom
feature/autonomous-energy-mode-switching
Open

feat(energy-control): add solar-based automatic mode switching#5
deKibi wants to merge 10 commits into
mainfrom
feature/autonomous-energy-mode-switching

Conversation

@deKibi

@deKibi deKibi commented Jul 11, 2026

Copy link
Copy Markdown
Owner

Adds autonomous inverter mode switching based on time window, grid availability, and recent battery, PV, and load conditions.

@deKibi deKibi self-assigned this Jul 11, 2026
@deKibi

deKibi commented Jul 11, 2026

Copy link
Copy Markdown
Owner Author

@codex please review this PR only for critical or harmful issues.

Focus on whether:

  • mode switching can trigger under unsafe or clearly incorrect conditions;
  • rules can conflict or send the wrong target mode;
  • repeated commands can be spammed;
  • grid-outage priority can be bypassed;
  • invalid or insufficient telemetry can still cause a switch;
  • the current mode check can fail and trigger unnecessary switching.

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread energy_mode_control/energy_mode_controller.py
Comment thread energy_mode_control/solar_auto_switch.py
@deKibi

deKibi commented Jul 12, 2026

Copy link
Copy Markdown
Owner Author

@codex Please review this PR focusing only on critical or high-impact issues in the automatic energy mode switching flow.

Verify:

  • solar switching uses BatteryVoltage, PLoad, and PvVoltage correctly, and no longer depends on ChargerPower;
  • average PLoad limit is 700 W and the latest-sample hard limit is 800 W, including boundary cases;
  • seasonal daylight windows and their start/end boundaries are correct;
  • the system does not send repeated commands when the inverter is already in the target mode;
  • cooldown is isolated by (rule, target_mode), so grid-outage emergency switching is not blocked by solar or scheduled rules;
  • grid-outage logic has priority over regular solar/scheduled switching;
  • switching back happens only after the daylight window ends;
  • missing or insufficient telemetry fails safely without switching;
  • config validation, defaults, tests, and GitHub Actions are consistent with the implementation.

Please report only real correctness, safety, regression, or race-condition risks. Ignore minor style issues, naming preferences, and unrelated refactoring suggestions.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 99dffbefb1

ℹ️ 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".

Comment thread energy_mode_control/solar_auto_switch.py
Comment on lines 120 to +123
):
target_mode = AUTO_SWITCH_TARGET_MODE
switch_reason = "auto-switch target time has been reached"
switch_rule = SCHEDULED_SWITCH_RULE

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Block scheduled switchbacks during daylight

When both scheduled and solar switching are enabled, this branch wins before the solar rule and only checks that AUTO_SWITCH_TARGET_TIME has been reached. If that scheduled target is configured before the solar/daylight window ends, an inverter already in solar-priority mode can be commanded back to the scheduled mode while daylight is still active; the switchback should be gated on being outside the daylight window or validated to occur after the window end.

Useful? React with 👍 / 👎.

@deKibi deKibi Jul 12, 2026

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed in 8960ae4

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Result

I reviewed the follow-up fix at 8960ae442f93893fa0f24ec8ea87bc090478d481 for the scheduled switchback concern.

I did not find a remaining critical or harmful issue in this specific fix, so I made no code changes, did not commit, and did not create a new PR.

Testing

  • pytest tests/control_power_mode/test_energy_mode_controller.py tests/control_power_mode/test_time_utils.py — 30 passed.

View task →

@deKibi

deKibi commented Jul 12, 2026

Copy link
Copy Markdown
Owner Author

@codex Please perform a final focused review of the latest PR state.

Context:

  • This PR adds automatic switching into solar-priority mode using the existing
    fixed SOLAR_AUTO_SWITCH_START_TIME / SOLAR_AUTO_SWITCH_END_TIME window.
  • Seasonal or dynamic windows, generic timezone support, partial overrides,
    and broad refactoring are out of scope.
  • ChargerPower is intentionally excluded from the decision because it can show
    about 8 W in SUB mode even during strong sunlight.
  • The current load limits are 700 W average and 800 W for the latest sample.
  • Scheduled switching must not interrupt the active solar window; with the
    half-open interval [start, end), switching back is allowed at the exact end.
  • Grid-outage switching must remain the highest-priority rule.
  • Cooldowns are isolated by rule and target mode.
  • Tests cover the business logic without real MySQL or serial connections.

Please review the complete latest diff and report only critical correctness,
safety, regression, priority, cooldown, or command-spam issues.

In particular, verify:

  • solar switching can actually occur when all conditions pass;
  • scheduled switching is blocked inside the solar window and allowed at its end;
  • grid-outage logic cannot be blocked or overridden by regular rules;
  • commands are not repeatedly sent when the target mode is already confirmed;
  • insufficient or invalid telemetry fails safely;
  • tests and configuration match the implemented fixed-window behavior.

Ignore minor style, naming, seasonal-window suggestions, unrelated refactoring,
and optional improvements. The goal is to close this PR and run the real-world
switching test tomorrow.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 8960ae442f

ℹ️ 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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant