Skip to content

Handle %-scaled charge/discharge rate entities during inverter calibration and control writes - #4675

Closed
springfall2008 with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-charge-discharge-rate-calibration
Closed

Handle %-scaled charge/discharge rate entities during inverter calibration and control writes#4675
springfall2008 with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-charge-discharge-rate-calibration

Conversation

Copilot AI commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Predbat assumed charge_rate/discharge_rate entities were watt-scaled and wrote raw W values during calibration/control. For integrations exposing signed/percent controls (e.g. -100..100 %), this caused service_validation_error writes and persistent unit-mismatch noise.

  • Rate unit detection + conversion path

    • Added %-entity detection for configured charge_rate / discharge_rate entities.
    • Added conversion helpers to translate:
      • read path: % -> W (for internal control logic)
      • write path: W -> % (for service writes)
    • Keeps existing W behavior unchanged for watt-native entities.
  • Signed percent discharge handling

    • For signed ranges (e.g. min < 0 < max), discharge writes are sign-adjusted (negative) and clamped to entity bounds.
    • For unsigned percent ranges, discharge remains positive and clamped within configured limits.
  • Control-loop integration points

    • Updated both current-rate reads and target-rate writes:
      • get_current_charge_rate
      • get_current_discharge_rate
      • adjust_charge_rate
      • adjust_discharge_rate
  • Regression coverage

    • Added focused inverter test for a shared %-scaled rate entity mapped via charge_rate/discharge_rate, verifying correct charge (+%) and discharge (-%) writes.
if self._rate_entity_uses_percent(discharge_rate_entity):
    discharge_rate_percent = self._rate_watts_to_percent(discharge_rate_entity, new_rate, discharge=True)
    self.write_and_poll_value("discharge_rate", discharge_rate_entity, discharge_rate_percent, fuzzy=5, required_unit="%")
else:
    self.write_and_poll_value("discharge_rate", discharge_rate_entity, new_rate, fuzzy=..., required_unit="W")

Co-authored-by: springfall2008 <48591903+springfall2008@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix charge_rate/discharge_rate calibration writes for percentage scaling Handle %-scaled charge/discharge rate entities during inverter calibration and control writes Aug 23, 2026
Copilot AI requested a review from springfall2008 August 23, 2026 18:58
@springfall2008

Copy link
Copy Markdown
Owner

Closing as there is already a percent setting

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.

charge_rate/discharge_rate calibration writes fail with service_validation_error when the underlying entity is scaled in % rather than W

2 participants