Plan Kimi K2.7-coder----Own plan
Artificial Intelligence

Plan Kimi K2.7-coder----Own plan

To understand this blog post you need to read the post "Keeeping token cost down and evaluation test" and the other posts

Jan Petersen
July 4, 2026
3 min read
3 views

Plan: Tesla Cheapest-Hours Charge Planner

Build a minimal Dockerized Node.js app that charges a Tesla during the cheapest Danish electricity hours, keeps the car ready by a configurable morning time, and stays within the Tesla Fleet API $10 individual-developer credit by polling SOC only twice daily (18:00 and 20:00) and issuing only start/stop commands.

Decisions

  • Price source: Energi Data Service (energidataservice.dk), region DK1/DK2 configurable.
  • Tariffs: editable tiers in the web UI.
  • Car state: poll SOC at 18:00 and 20:00; assume car is home at planning time.
  • Target SOC: default 80%, user-configurable; battery capacity via dropdown (Model Y Standard 2026 default); charger kW user-configurable.
  • Algorithm: compute hours needed from SOC gap, battery kWh, charger kW, and efficiency; find cheapest contiguous window before departure time; issue charge_start at start and charge_stop at end.
  • Stack: Node.js + Express backend, in-process node-cron, plain HTML/vanilla JS frontend (no build), JSON file storage in mounted ./data.
  • Tesla integration: copy simplified OAuth PKCE flow from the existing Tesla app, AES-encrypt tokens, use a separate Vehicle Command Proxy (VCP) sidecar for command signing.
  • Containers: 2 containers — combined backend+frontend, plus VCP sidecar.
  • Scheduling: fetch prices once daily; SOC poll at 18:00/20:00; command execution at planned window boundaries.
  • UI settings: departure time, target SOC, active days bitmask, region, tariff tiers, charger kW, car model.
  • Notifications: optional ntfy.sh.
  • Overrides: charge now, stop charging, skip tonight.
  • API usage tracking: log and display Fleet API call counts.
  • Deployment: Cloudflare Tunnel for public HTTPS OAuth callback; SERVER_URL configurable.

Phases

  1. Scaffold projectpackage.json, Express server, Dockerfiles, docker-compose.yml, VCP sidecar.
  2. Storage & config — JSON file helpers, config schema, API usage log.
  3. Tesla auth — OAuth PKCE, token refresh, encrypted token storage, public key endpoint.
  4. Tesla commands — VCP client, start/stop charging, wake-up, SOC read.
  5. Price fetcher — Energi Data Service client, price cache, tariff editor.
  6. Optimizer — hours-needed calculation, cheapest contiguous window search.
  7. Scheduler — node-cron jobs for prices, SOC polls, command execution.
  8. Web UI — settings page, schedule view, status, manual overrides, API usage view.
  9. Notifications — ntfy.sh integration.
  10. Deployment docs — Cloudflare Tunnel setup, Tesla developer app registration, env vars.

Relevant files to create

  • package.json
  • src/index.js — Express server, static UI, API routes
  • src/config.js — JSON config storage
  • src/tesla/auth.js — OAuth PKCE, token refresh
  • src/tesla/client.js — VCP/Fleet API wrapper, start/stop/SOC
  • src/tesla/keys.js — EC key generation
  • src/prices/energidata.js — Energi Data Service fetcher
  • src/prices/tariffs.js — tariff calculation
  • src/scheduler/optimizer.js — cheapest window calculation
  • src/scheduler/jobs.js — node-cron jobs
  • src/notifications/ntfy.js — ntfy.sh sender
  • public/index.html — settings/status UI
  • public/app.js — frontend logic
  • Dockerfile
  • vcp/Dockerfile
  • docker-compose.yml
  • .env.example
  • README.md

Verification

  1. docker-compose up --build starts backend and VCP without errors.
  2. OAuth flow completes and stores encrypted tokens.
  3. Price fetcher returns hourly DK1/DK2 prices.
  4. Optimizer selects cheapest contiguous window for a sample SOC/departure.
  5. Scheduler triggers start/stop commands at correct times in a test environment.
  6. Web UI shows config, planned schedule, status, and API call count.
  7. ntfy.sh notifications sent on start/stop/error.

Scope excluded

  • Geofencing / home detection (assumed home at 18:00/20:00).
  • Per-day departure/SOC schedules (active-days bitmask only).
  • Multiple vehicles.
  • Cloud hosting instructions beyond Cloudflare Tunnel.
  • Advanced telemetry or analytics.

Share this post

Related Posts

Comments

Be the first to leave a comment.

Leave a comment

Comments are reviewed before they appear.