Plan Kimi K2.7-coder
Artificial IntelligenceCoClaw

Plan Kimi K2.7-coder

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

Jan Petersen
July 4, 2026
11 min read
2 views

Validation summary Plan Strengths Weaknesses plan-big-pickle.md Most detailed. Real API cost table, Danish Konstant tariffs, thorough error-handling matrix, UI page breakdown, setup wizard, health endpoint. Polls every 15 min if the car is unplugged (adds API cost). Bundles VCP into the same container. Less structured as an executable plan. plan-Kimi K2.7 Code.md Best structured for execution. SOC reads only twice daily (18:00/20:00). Clean VCP sidecar. API usage tracking. DK1/DK2 region config. Manual overrides. Explicit verification. Less depth on error handling, UI pages, and cost math than Plan 1. Oddly specific default car model. plan-MAI.md Simplest MVP framing. Too vague: no price source, no auth plan, no UI, no API budget analysis, not actionable. Best standalone plan: plan-Kimi K2.7 Code.md — it is the most executable, respects the API budget best, and has the cleanest architecture.

However, combining the best of Plan 1 + Plan 2 is better than either alone.

Tesla Cheapest-Hours Charge Planner

A minimal Dockerized Node.js + Express app that charges a Tesla during the cheapest Danish electricity hours, reaches a user-defined target SOC by a chosen morning departure time, and stays comfortably within the Tesla Fleet API $10/month individual-developer credit by reading vehicle state only twice daily (18:00 and 20:00) and issuing only start/stop commands.

Requirements

  • Primary goal: the car is ready in the morning at the target battery percentage the user asked for.
  • Strategy: charge only during the cheapest hourly electricity prices of the day.
  • Tesla Fleet API budget: stay within the $10/month credit provided for individual developers/small applications.
    • Limit reads to two scheduled SOC checks per day (18:00 and 20:00).
    • Issue commands only to start/stop charging and to wake the car when needed.
  • Price data: free Danish public electricity price feed (Energi Data Service), region DK1 or DK2.
  • Runtime: local Docker, with environment variables for secrets and a mounted ./data volume for persistence.

Decisions

  • Price source: Energi Data Service (energidataservice.dk), region configurable DK1/DK2.
  • Tariffs: editable tiers in the web UI, defaulting to a Danish Konstant-style tariff model.
  • SOC reads: only at 18:00 and 20:00 to keep API spend low; no continuous polling.
  • Architecture: Node.js backend + Vehicle Command Proxy (VCP) sidecar (cleaner than bundling VCP into the same image).
  • Frontend: htmx + Tailwind CSS served directly by Express, no separate build step.
  • Storage: JSON files in a mounted ./data volume.
  • Notifications: optional ntfy.sh push notifications.
  • Public HTTPS for OAuth: Cloudflare Tunnel (or user-supplied reverse proxy) so Tesla can redirect back to the app.

Architecture

text
┌──────────────────────────────────────────────┐
│  Docker Compose stack                        │
│                                              │
│  ┌──────────────┐   HTTP   ┌──────────────┐ │
│  │  Node.js     │◄────────►│  VCP         │ │
│  │  Express     │          │  (Go proxy)  │ │
│  │  scheduler   │          │              │ │
│  │  htmx UI     │          │              │ │
│  └──────┬───────┘          └──────────────┘ │
│         │                                    │
│   ┌─────▼──────┐                             │
│   │ ./data/    │  mounted volume             │
│   │ config.json│                             │
│   │ price_cache.json                         │
│   │ api_usage.json                           │
│   └────────────┘                             │
└──────────────────────────────────────────────┘

Stack

  • Runtime: Node.js 22 + TypeScript + Express 5
  • Scheduling: node-cron in-process
  • UI: htmx + Tailwind CSS
  • Charts: Chart.js via CDN for the 24h price chart
  • Command signing: teslamotors/vehicle-command (VCP sidecar)
  • Storage: JSON files on mounted volume

Daily cycle

TimeActionTesla API callsCost
~14:00 CETFetch Energi Data Service DK1/DK2 prices for next 24-36h0$0
18:00vehicle_data?endpoints=charge_state1 Data ($0.002)$0.002
18:00If plugged in → compute cheapest window
18:00If not plugged in → re-check at 20:00 only+1 Data ($0.002)$0.002
Window startwake_up (if asleep) + charge_start1 Wake ($0.02) + 1 Cmd ($0.001)$0.021
Window endcharge_stop1 Cmd ($0.001)$0.001
Total (best case)$0.024/night
Total (worst case)~$0.04/night
Monthly (30 days)$0.72-$1.20

Scheduling algorithm

  1. Fetch hourly spot prices from Energi Data Service (DK1/DK2).
  2. Add Danish tariffs from the configurable tariff model (default Konstant-style tiers).
  3. Get current_soc from the scheduled vehicle_data read.
  4. Compute energy needed: kwh_needed = (target_soc - current_soc) / 100 * battery_kwh.
  5. Compute hours needed: hours_needed = ceil(kwh_needed / charger_kw).
  6. Filter candidate hours to the interval [now, departure_time], excluding past hours.
  7. Find the cheapest contiguous window of hours_needed length.
  8. If no suitable window exists → skip the night and log the reason.

Auth & setup

Reuses a simplified OAuth PKCE flow inspired by the existing Tesla Charger app:

  1. In-app setup wizard served at /setup:
    • Enter Tesla Developer client_id + client_secret.
    • Click "Connect to Tesla" → redirected to Tesla authorize URL.
    • User logs in on Tesla and grants permissions.
    • Tesla redirects to /api/auth/callback with an auth code.
    • App exchanges the code for access and refresh tokens, stored AES-encrypted in config.json.
    • App registers as a Fleet API partner via partner_accounts.
    • App generates an EC P-256 key pair and serves the public key at the well-known Tesla endpoint.
  2. Token refresh happens automatically 5 minutes before expiry.
  3. If refresh fails, the UI shows a "re-auth required" flag.

Configuration

FieldTypeDefaultEditable via UI
target_socnumber80Yes (slider 50-100)
departure_timestring"07:00"Yes (time picker)
soc_read_timesstring[]["18:00", "20:00"]Yes
charger_kwnumber11Yes
battery_kwhnumber75Yes
regionstring"DK1"Yes (DK1/DK2)
active_daysbitmask62 (Mon-Fri)Yes (checkboxes)
tariff_tiersarrayKonstant defaultYes
ntfy_topicstring""Yes
tesla_vinstringauto-detectedNo
tesla_client_idstringSetup wizard
tesla_client_secretstringSetup wizard (encrypted)
access_tokenstringOAuth (encrypted)
refresh_tokenstringOAuth (encrypted)
ec_private_keystringGenerated (encrypted)
ec_public_keystringGenerated

UI pages

Dashboard (/)

  • Large battery SOC percentage display.
  • Charging status badge: Idle / Charging / Disconnected / Done / Planned.
  • Next planned charging window, e.g. "Charging 03:00-05:00".
  • Target SOC slider.
  • Departure time picker.
  • SOC read-time config.

Prices (/prices)

  • 24h bar chart via Chart.js.
  • Cheapest hours highlighted in green.
  • Planned charging window highlighted in blue.
  • Current price indicator.

Settings (/settings)

  • Charger power (kW), battery capacity (kWh), active days.
  • DK1/DK2 region selector.
  • Editable tariff tiers.
  • ntfy.sh topic.

Setup (/setup)

  • Three-step OAuth wizard, hidden once setup is complete.

API usage (/usage)

  • Call counts per category (Data, Command, Wake).
  • Estimated monthly cost.

API endpoints

MethodPathAuthPurpose
GET/api/configYesRead config
POST/api/configYesUpdate config
GET/api/statusYesVehicle SOC, charging state, schedule
GET/api/pricesYesToday + tomorrow prices
POST/api/prices/refreshYesForce price refresh
GET/api/scheduleYesPlanned charging window
POST/api/charge/startYesManual override: start now
POST/api/charge/stopYesManual override: stop now
POST/api/charge/skipYesSkip tonight
GET/api/usageYesAPI call counts and cost estimate
GET/api/auth/statusNoTesla auth status
GET/api/auth/startNoInitiate OAuth flow
GET/api/auth/callbackNoOAuth callback
POST/api/auth/registerYesRegister partner account
GET/healthNoContainer health
GET/.well-known/appspecific/com.tesla.3p.public-key.pemNoTesla public key

Error handling

ScenarioBehavior
Car already at/above target SOCSkip night. Log: "Already charged."
Not plugged in at 18:00Re-check once at 20:00. If still unplugged, abort the night.
Price API downUse last cached prices. If no cache, skip the night.
Tesla 429 rate limitExponential backoff: 1 min → 5 min → 15 min → abort night.
charge_start failsRetry once after 30 s. If still fails, log + ntfy + abort.
charge_stop failsRetry once after 30 s. Log + ntfy. The car stops on its own at target SOC.
Container restart mid-chargeOn boot: check vehicle_data. If charging and past the planned window, stop.
Token refresh failsClear tokens. Re-auth required flag in the UI.
VCP proxy unreachableLog error; retry up to twice, then abort the command.

Project structure

text
tesla-cheap-charger/
├── docker-compose.yml          # Node app + VCP sidecar
├── Dockerfile                  # Node app image
├── vcp/
│   └── Dockerfile              # VCP sidecar image
├── .env.example
├── .gitignore
├── README.md
├── package.json
├── tsconfig.json
└── src/
    ├── index.ts                # Express entry point
    ├── config.ts               # JSON config/cache/usage helpers
    ├── scheduler/
    │   ├── jobs.ts             # node-cron jobs
    │   └── optimizer.ts        # Cheapest contiguous window
    ├── tesla/
    │   ├── auth.ts             # OAuth PKCE flow
    │   ├── client.ts           # Fleet API + VCP wrapper
    │   └── keys.ts             # EC P-256 key management
    ├── prices/
    │   ├── energidata.ts       # Energi Data Service client
    │   └── tariffs.ts          # Tariff calculation
    ├── notifications/
    │   └── ntfy.ts             # ntfy.sh sender
    ├── routes/
    │   ├── api.ts              # REST API routes
    │   ├── auth.ts             # OAuth callback routes
    │   └── pages.ts            # HTML page routes
    ├── views/
    │   ├── layout.html
    │   ├── dashboard.html
    │   ├── prices.html
    │   ├── settings.html
    │   ├── setup.html
    │   └── usage.html
    └── utils/
        ├── time.ts             # Denmark timezone helpers
        └── crypto.ts           # AES encryption for tokens

Docker Compose

yaml
services:
  vcp:
    build: ./vcp
    environment:
      - TZ=Europe/Copenhagen
    volumes:
      - ./data:/data
    networks:
      - tesla-net

  app:
    build: .
    ports:
      - "3001:3001"
    volumes:
      - ./data:/app/data
    environment:
      - PORT=3001
      - TZ=Europe/Copenhagen
      - NODE_ENV=production
      - VCP_URL=http://vcp:4040
    networks:
      - tesla-net
    depends_on:
      - vcp
    restart: unless-stopped

networks:
  tesla-net:

Budget

ItemMonthlyNotes
Tesla Fleet API~$0.72-$1.20Covered by $10 monthly credit
VPS/hosting$0Docker on existing home server
Energi Data Service$0Free, open data
ntfy.sh$0Free, open source
Total out-of-pocket$0

Dependencies

  • express — HTTP framework
  • axios — HTTP client (Tesla, Energi Data Service, ntfy)
  • node-cron — In-process scheduling
  • crypto-js — AES token encryption
  • uuid — OAuth state nonce
  • dotenv — Env file loading
  • Dev: typescript, tsx, @types/*
  • No native Node modules required.

Implementation phases

  1. Scaffoldpackage.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, boot reconciliation.
  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.

Verification

  1. docker-compose up --build starts the backend and VCP without errors.
  2. OAuth setup wizard completes, stores encrypted tokens, and registers the partner account.
  3. GET /api/prices returns hourly DK1/DK2 prices and a populated 24h chart.
  4. Optimizer unit test: for a sample SOC gap, battery, charger kW, and departure time, it returns the cheapest contiguous window.
  5. SOC read jobs fire at 18:00 and 20:00; scheduler issues charge_start/charge_stop at the planned window boundaries in a test environment.
  6. UI displays config, planned schedule, status, manual overrides, and API call count/cost.
  7. ntfy.sh notifications are sent on start, stop, and error paths.
  8. Monthly API cost estimate shown in the UI stays under $2 for normal usage.

Out of scope

  • Geofencing / home detection (assumed home at planning time).
  • 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.