Skip to content

Loadpoint: wake up sleeping vehicle once to read unknown soc - #35807

Open
rakete1 wants to merge 1 commit into
evcc-io:masterfrom
rakete1:fix/soc-retry-asleep
Open

rakete1 wants to merge 1 commit into
evcc-io:masterfrom
rakete1:fix/soc-retry-asleep

Conversation

@rakete1

@rakete1 rakete1 commented Nov 4, 2026 •

Copy link
Copy Markdown

Fixes #35770

Wakes a sleeping vehicle once per connection if its SoC is unknown, so that the SoC is available again after a restart and SoC-based plans no longer start from 0%. As agreed in the issue, this applies on every start, not only with a plan.

  • reads continue after the wake-up until a SoC arrives, the same way as for ErrMustRetry
  • no change with a known SoC, no wake-up with api.WakeUpDisabled
  • only helps vehicles assigned at startup, i.e. a default vehicle. Detection still skips sleeping vehicles
  • the wake-up flag is not persisted, so a crash loop after startup can wake the car on every start

Verified on a Tesla with go-e on top of 0.318.2: with no plan set, evcc woke the car from offline on restart and read the SoC 30 s later.

🤖 Generated with Claude Code

@github-actions github-actions Bot added bug Something isn't working vehicles Specific vehicle support labels Nov 4, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've found 5 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="core/loadpoint_vehicle.go" line_range="261-264" />
<code_context>
+	}
+
+	if vehicle, ok := api.Cap[api.Resurrector](lp.GetVehicle()); ok {
+		lp.socWakeUpDone = true
+
+		lp.log.DEBUG.Println("soc unknown: waking up vehicle")
+		if err := vehicle.WakeUp(); err != nil {
+			lp.log.ERROR.Printf("wake-up vehicle: %v", err)
+		}
</code_context>
<issue_to_address>
**Wake failures suppress retries**

When `vehicle.WakeUp()` returns an error, `wakeUpVehicleForSoc` sets `socWakeUpDone` before calling `WakeUp`, so later asleep reads skip another attempt and the SoC remains unavailable until reconnect.

Set `socWakeUpDone` only after `WakeUp` succeeds, or clear it when the call fails.
</issue_to_address>

### Comment 2
<location path="core/loadpoint.go" line_range="2398" />
<code_context>
-		if !errors.Is(socErr, api.ErrMustRetry) {
+		// arrives, instead of waiting for the next interval. Same for sleeping
+		// vehicles while the SoC is unknown, e.g. after a restart.
+		asleepSocUnknown := errors.Is(socErr, api.ErrAsleep) && lp.vehicleSoc == 0
+		if asleepSocUnknown {
+			lp.wakeUpVehicleForSoc()
</code_context>
<issue_to_address>
**Estimated SOC stops the retry**

When a sampled estimator has a zero baseline and charged energy increases while the vehicle API returns `ErrAsleep`, a sampled estimator can raise `lp.vehicleSoc` above zero after the asleep read fails; on the next poll, `asleepSocUnknown` is false and `socUpdated` is set despite no successful vehicle read, so charging-only polling stops before the actual SOC arrives.

Keep the retry state tied to a successful API SoC read rather than the estimator-adjusted `lp.vehicleSoc`.
</issue_to_address>

### Comment 3
<location path="core/loadpoint_vehicle.go" line_range="260-261" />
<code_context>
+		return
+	}
+
+	if vehicle, ok := api.Cap[api.Resurrector](lp.GetVehicle()); ok {
+		lp.socWakeUpDone = true
+
+		lp.log.DEBUG.Println("soc unknown: waking up vehicle")
</code_context>
<issue_to_address>
**Charger-only wake-up is skipped**

When the vehicle has no `api.Resurrector` capability but its charger can wake it, `wakeUpVehicleForSoc` only checks the active vehicle for `api.Resurrector`, so vehicles that can be woken through a charger’s CP interrupt are not woken and their unknown SoC remains unavailable until another event causes a read.

Try the charger’s `api.Resurrector` as a fallback when the vehicle itself cannot wake the car.
</issue_to_address>

### Comment 4
<location path="core/loadpoint.go" line_range="2401" />
<code_context>
+		asleepSocUnknown := errors.Is(socErr, api.ErrAsleep) && lp.vehicleSoc == 0
+		if asleepSocUnknown {
+			lp.wakeUpVehicleForSoc()
+		}
+		if !errors.Is(socErr, api.ErrMustRetry) && !asleepSocUnknown {
 			lp.socUpdated = lp.clock.Now()
</code_context>
<issue_to_address>
**Gate wake-up on plan**

The issue asks to wake only when a SoC-based plan is set, and not to wake without one so a plan added later can trigger the wake. This call wakes whenever the SoC is unknown and the vehicle reports ErrAsleep, regardless of plan state, and can consume the per-connection wake-up before a plan is added.
</issue_to_address>

### Comment 5
<location path="core/loadpoint.go" line_range="189" />
<code_context>
 	pvTimer        time.Time        // PV enabled/disable timer
 	phaseTimer     time.Time        // 1p3p switch timer
 	wakeUpTimer    *Timer           // Vehicle wake-up timeout
+	socWakeUpDone  bool             // Vehicle was woken up once to read an unknown soc

 	// charge progress
</code_context>
<issue_to_address>
**SoC terminology is lowercase**

The new field comment, function comment, and debug log spell the acronym as `soc`, contrary to the repository's required `SoC` capitalization.

Use `SoC` in the added comments and debug log.

Also at `core/loadpoint_vehicle.go:254`, `core/loadpoint_vehicle.go:263`.
</issue_to_address>

Linked issues

#35770 Wake the vehicle once to read the SoC when it is unknown and a plan is set · 5 of 6 met

# Requirement Status Notes
1 Wake once per connection only when the SoC is unknown, the vehicle is asleep, and a SoC-based plan is set; do not wake without a plan, so a plan added later triggers a wake on the next failed read. 🟡 Partly met The change handles unknown SoC and ErrAsleep and limits wake-ups per connection, but calls the wake helper without checking for a plan; an early wake without a plan can also consume the per-connection flag before a plan is added.
2 Do not wake vehicles with api.WakeUpDisabled. ✅ Met The wake helper returns when the vehicle has this feature.
3 Keep socUpdated at zero on ErrAsleep while vehicleSoc is zero, and continue polling until a SoC arrives. ✅ Met The ErrAsleep/unknown-SoC case is excluded from the socUpdated assignment.
4 Do not change behavior when the SoC is known. ✅ Met The special handling applies only when vehicleSoc is zero.
5 Stop polling at the first successful SoC read. ✅ Met A successful read updates socUpdated, after which vehicleSocPollAllowed no longer allows connected-mode polling.
6 If wake-up fails, continue reads without further wake-ups. ✅ Met The helper sets socWakeUpDone before calling WakeUp, while the ErrAsleep/unknown-SoC case keeps polling enabled.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread core/loadpoint_vehicle.go Resolved
Comment thread core/loadpoint.go Resolved
Comment thread core/loadpoint_vehicle.go Resolved
Comment thread core/loadpoint.go Resolved
Comment thread core/loadpoint.go Resolved
@rakete1
rakete1 force-pushed the fix/soc-retry-asleep branch from 96dc973 to 33308d3 Compare November 4, 2026 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working vehicles Specific vehicle support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wake the vehicle once to read the SoC when it is unknown and a plan is set

1 participant