Skip to content

Implemented charge windows instead of just picking random low price s… - #951

Merged
fredli74 merged 87 commits into
masterfrom
charge_window_planner
Aug 5, 2026
Merged

Implemented charge windows instead of just picking random low price s…#951
fredli74 merged 87 commits into
masterfrom
charge_window_planner

Conversation

@fredli74

@fredli74 fredli74 commented Feb 6, 2026

Copy link
Copy Markdown
Owner

No description provided.

…egments

Signed-off-by: Fredrik Lidström <fredli74@gmail.com>
@fredli74

fredli74 commented Feb 6, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@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: f4aff26557

ℹ️ 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 server/logic.ts Outdated
Comment thread server/logic.ts Outdated

Copilot AI 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.

Pull request overview

This pull request implements a sophisticated charge window scheduling algorithm that replaces the simpler approach of just picking random low-price slots. The new system intelligently schedules charge windows by considering price data, time constraints, and multiple competing charge intents (manual, trip, routine, fill) to optimize both cost and charging behavior.

Changes:

  • Replaced the old GeneratePlan function with a new "soft intents" model that collects all charge requirements first, then schedules them optimally across available price windows
  • Implemented a greedy sliding-window algorithm to find optimal charge windows that minimize cost while respecting constraints like minimum window duration (to avoid fragmentation in cold weather) and maximum price thresholds
  • Added support for splitting charge sessions across multiple windows when cost savings justify it, with configurable thresholds for when to split vs. consolidate charging

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/logic.ts Outdated
Comment thread server/logic.ts Outdated
Comment thread server/logic.ts Outdated
Comment thread server/logic.ts Outdated
Comment thread server/logic.ts Outdated
Comment thread server/logic.ts Outdated
Comment thread server/logic.ts Outdated
Comment thread server/logic.ts Outdated
Comment thread server/logic.ts Outdated
fredli74 and others added 6 commits February 6, 2026 02:46
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Fredrik Lidström <fredli74@gmail.com>

Copilot AI 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.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/logic.ts Outdated
@fredli74

fredli74 commented Feb 6, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@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: 289a128246

ℹ️ 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 server/logic.ts Outdated
Comment thread server/logic.ts Outdated

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/logic.ts Outdated
Comment thread app/src/app.vue
Comment thread app/src/app.vue
Comment thread app/src/app.vue
Comment thread server/logic.ts Outdated
Signed-off-by: Fredrik Lidström <fredli74@gmail.com>
… quantumMs

Signed-off-by: Fredrik Lidström <fredli74@gmail.com>
…ehicle not waking up to charge, cause it though the level was ok already

Signed-off-by: Fredrik Lidström <fredli74@gmail.com>

Copilot AI 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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/src/app.vue
Comment thread app/src/app.vue
Signed-off-by: Fredrik Lidström <fredli74@gmail.com>

Copilot AI 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.

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread shared/sc-utils.ts
Comment thread app/src/components/edit-vehicle-location-settings.vue Outdated
Comment thread app/src/components/edit-vehicle-location-settings.vue
Comment thread app/src/components/edit-vehicle-location-settings.vue
Comment thread server/logic.ts Outdated
fredli74 and others added 16 commits April 28, 2026 00:08
Signed-off-by: Fredrik Lidström <fredli74@gmail.com>
…silon

Audit comparisons previously included non-SmartCharge schedule IDs
(e.g. Tesla app schedules like 1723769697) causing false positive
mismatches whenever the car had extra schedules in the live data.

Fix 1: filter normalizeChargeSchedules / equalChargeSchedules to
IDs in [TeslaScheduleIDs.First, TeslaScheduleIDs.Last] and filter
normalizePreconditionSchedules / equalPreconditionSchedules to
TeslaScheduleIDs.Precondition only.

Fix 2: increase SCHEDULE_COORD_ABS_EPSILON from 1e-5 to 5e-5.
The original 1e-5 was insufficient to cover the observed ~2.6e-5
drift between micro-degree integer DB values (e.g. 57695873/1e6)
and what Tesla stores as IEEE 754 float32 (~57.695899). float32
ULP near 60 N is ~4-8e-6; the new epsilon (5e-5) covers both
float32 rounding and DB-to-float32 conversion artefacts while
still catching genuine location changes of >5 m.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Keep audit interval logic but with past cutoffs to disable recurring audits
- Keep same-leg in-place schedule adjustments by ID
- Require enabled in Tesla schedule payloads
- Send enabled=true on adjustment updates to enforce explicit authoritative behavior
- Remove ambiguous cache fallback for enabled on schedule write-back

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Shift the audit sunset window three months so the periodic and
post-update schedule audits run at 30-minute cadence again while the
new charge window planner is being verified in production.

Copilot AI 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.

Pull request overview

Copilot reviewed 26 out of 27 changed files in this pull request and generated no new comments.

Suppressed comments (2)

app/src/components/edit-vehicle.vue:160

  • locationSettings() is invoked from the template during render, but it mutates reactive state via getOrCreateLocationSettings() (pushing into this.vehicle.locationSettings). Render-time side effects can cause extra render passes and make UI state harder to reason about (and locationSettings() is called more than once per render: v-if="locationSettings().length" and the v-for). Consider moving the “ensure defaults exist” mutation to a lifecycle hook / watcher and keeping locationSettings() pure (mapping only).
  locationSettings(): any[] {
    return (
      (this.locations &&
        this.locations
          .filter((l) => l.ownerID === this.vehicle.ownerID)
          .map((l) => {
            const settings = this.getOrCreateLocationSettings(l.id);

providers/tesla/tesla-server.ts:189

  • Vehicles query may return null when incomplete is true. At least one existing caller (providers/tesla/app/tesla.vue) iterates the result directly (for (const v of await providerQuery(...))), which will throw on null and can lead to a misleading UI state (e.g., showing the authorize button even though vehicles exist). If null is the intended “mapping incomplete” sentinel (as TeslaAgent now expects), please update all call sites to explicitly handle null (e.g., treat as “retry later” / show a transient error) rather than assuming an array.
        if (incomplete) {
          return null;
        }

@fredli74
fredli74 marked this pull request as ready for review August 5, 2026 12:31
@fredli74
fredli74 merged commit fcd41b0 into master Aug 5, 2026
2 checks passed
@fredli74
fredli74 deleted the charge_window_planner branch August 5, 2026 12:32

@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: 285ff52727

ℹ️ 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 server/logic.ts
Comment on lines +1112 to +1113
const plan = await planWindows(timeNeeded, deadline, undefined, `intent:${cohortMaxLevel}`, isActiveCharge());
hardStart = applyWindows(plan.windows, buildAllocations(plannedLevel, cohortIntents));

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 Fall back when no price windows are available

When a scheduled manual/trip/routine intent has a future deadline but the location has no price data (or every slot before the deadline is filtered out), planWindows() returns an empty windows array; this branch still applies that empty plan and then marks the cohort as planned. The result is an empty chargePlan, so scheduled charging is silently skipped at locations without tariff data, whereas the old path fell back to direct charging when priceAvailable was false.

Useful? React with 👍 / 👎.

fredli74 added a commit that referenced this pull request Aug 5, 2026
Follow-up to #951, covering the review and cleanup findings on that PR.

Planner: the per-step Trace logging ran unconditionally (LOGLEVEL
defaults to Trace and nothing lowers it), costing ~54 stdout lines and
~35% of every planning call; keep a header and one outcome line and drop
the scaffolding that only fed logs. State the ordering and finiteness
preconditions as asserts now that the redundant sorts are gone, merge
the redundant node comparator, fold action/stepIndex into a step
reference, and yield on a 5 ms budget instead of a step count.

Charge curve: the 0.75 anti-overshoot trim sat behind `l < to`, true for
every iteration of its own loop, so every estimate ran ~25% of a band
long. Extract chargeDuration so it can be tested and fix the predicate.

Settings: settings.vue and vehicleFragment now share one locationSettings
field list, and splitCharge's default moves into the schema.

Verified identical over 4500 fuzzed plans on well-formed input.
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.

2 participants