
Running rooftop solar, a home battery, two electric vehicles (EVs), and dynamic hourly electricity...
Running rooftop solar, a home battery, two electric vehicles (EVs), and dynamic hourly electricity tariffs requires tight coordination. Without automation, these systems work against each other.
At home, I run dual east/west solar panels feeding a hybrid inverter with a 10 kWh battery, alongside a plug-in hybrid, an EV, and dynamic tariffs from my electricity provider. On sunny days, you should never buy grid power when solar can charge the battery for free. On dark, cloudy days, you want to buy grid power only during the cheapest hourly windows. Moreover, if you charge the home battery from the grid before plugging in an EV, the car drains your charged home battery right away.
Last weekend, in a couple of hours of hands-on work starting Saturday evening, I engineered cheap-watts to automate this workflow and open-sourced it on GitHub, complete with a full offline unit test suite across more than 25 commits.
The best part? I almost never touched the code myself.
By pairing Gemini 4 Hydrogen and Gemini 4 Carbon inside Google Antigravity, I practiced agentic engineering and stayed focused on high-level architecture. Here are the three main takeaways from the weekend build:
--dry-run flag so agents move fast without risking live keys or hardware.Most developers rely on one AI model for every task. Either you wait on a heavy reasoning model while bouncing early ideas back and forth, or you ask a fast model to handle multi-file refactors where edge cases slip through.
Inside Antigravity, I split my workflow across two models based on what each does best:
.py file, I worked with Hydrogen to draft three planning files under docs/planning/. I created an Architecture Decision Record (adr-001-initial-architecture.md), a five-phase execution plan (execution-plan.md), and a task backlog (tasks.md).tasks.md and ADR-001. Carbon scaffolded the modules, wrote binary protocol bitmasks, generated offline JSON fixtures, and ran pytest until every test passed.This split changed how I spent my weekend. Instead of debugging OAuth token rotation or counting Modbus register offsets by hand, I worked as the system architect. I defined rules, tested hardware connectivity on my local network, and reviewed PRs.
cheap-watts system architecture
During Saturday's brainstorming session with Gemini 4 Hydrogen, I ruled out building a web dashboard. Dashboards add frontend maintenance for a service that should run unattended in the background.
Instead, I designed cheap-watts as a headless Python 3.12 command-line interface (CLI) managed with uv and triggered every 30 minutes via cron. Running 48 times per day keeps the planner responsive to weather shifts and plugged-in cars while staying under the vehicle telematics API's 50 requests/day quota per account.
Reviewing the git history from Saturday night through Tuesday highlights four key architecture decisions.
In Phase 2 on Saturday evening, Gemini 4 Carbon built read-only clients for electricity provider tariffs, Open-Meteo solar forecasts, vehicle telematics, and the inverter vendor's cloud API. The solar forecast client supports dual east (-90°) and west (90°) roof planes without requiring an API key. Right after that, I added a read-only cheap-watts probe CLI command to test live credentials.
Running probe on Sunday exposed my first hardware constraint. My inverter's Wi-Fi stick logger connects to a third-party mobile app rather than the inverter manufacturer's cloud. That platform lacked self-service developer keys and public charging schedule write endpoints.
Because I had isolated inverter operations behind a Python Protocol (InverterClient), pivoting took a single commit. I asked Gemini 4 Carbon to build a local LAN adapter behind that same protocol. Carbon implemented a Modbus-over-TCP client over local port 8899. It reads live registers and writes the inverter's 6-slot charging schedule while keeping weekday and generator bitmasks intact. Local LAN control removed cloud rate limits, required zero external API keys, and left the mobile app untouched.

Coordinating a home battery with two EVs requires clear ordering rules in src/engine/planner.py:
cheap-watts turns grid-charging OFF for the whole day, so rooftop solar fills the battery for free. If a car has low charge, it emails me a reminder to plug it in for a slow daytime charge using excess solar.cheap-watts blocks those hours from inverter grid-charging. It schedules the cheapest battery charging windows after the vehicle window ends, so the car charger doesn't immediately drain grid-bought kWhs from the home battery.Once the pipeline ran every 30 minutes on live feeds, a subtle stateful scheduling bug appeared.
Suppose the electricity provider publishes next-day prices and cheap-watts schedules battery grid-charging from 02:00 to 04:00. At 02:30, cron runs again. Because the battery now holds more charge, a stateless planner calculates a smaller deficit and rewrites the active charging plan mid-charge. Rolling the 24-hour lookahead forward also risked 25-hour wrap collisions on the inverter's 6-slot 00:00..24:00 schedule ring.
I described this symptom to Antigravity without editing planner.py. Gemini 4 Carbon added a sticky schedule guard, locking the daily charging plan to the electricity provider's active day-ahead tariff horizon. The schedule stays locked across 30-minute runs and unlocks early only if:
ev_conflict_override).new_tariff_horizon).solar_regime_changed).Nobody wants 48 status emails per day. cheap-watts stores its last applied schedule and alert timestamps in data/state.json. It sends SMTP emails only when the battery charging plan changes or a new EV recommendation triggers outside a 12-hour cooldown.
For deployment on my home mini PC, I worked with Gemini 4 Hydrogen to compare local uv runs against GitHub Container Registry (ghcr.io). I chose ghcr.io with a decoupled crontab setup:
# Run optimization every 30 minutes using the cached local image:
*/30 * * * * docker run --rm --network host --env-file /opt/cheap-watts/.env -v /opt/cheap-watts/data:/app/data -v /opt/cheap-watts/logs:/app/logs ghcr.io/rsamborski/cheap-watts:latest run >> /opt/cheap-watts/logs/cron.log 2>&1
# Pull image updates on a separate hourly schedule:
15 * * * * docker pull --quiet ghcr.io/rsamborski/cheap-watts:latest >> /opt/cheap-watts/logs/cron.log 2>&1
Separating docker pull from docker run ensures a temporary internet or GitHub outage never blocks local LAN Modbus control of the inverter.
romin-security skill and PR gates
Letting an AI coding agent move fast in a repository with utility API tokens, vehicle OAuth credentials, and physical inverter registers carries real risk. One bad commit to a public GitHub repository can expose live keys to automated scanners within seconds.
Before writing a single line of application code on Saturday evening, I ran the romin-security skill, codified by Riccardo Carlesso based on Romin Irani's security guide. Designed to prevent secret leaks during fast agentic builds, the skill protected the repository from the start:
.env (left blank in .env.example) and wrap in Pydantic SecretStr fields so keys never appear in stack traces or logs. Rotated vehicle OAuth refresh tokens use 0600 file permissions..gitleaks.toml with custom patterns, including sk- personal API tokens from the electricity provider. Gitleaks runs in local pre-commit hooks and in GitHub Actions with fetch-depth: 0 to scan the full commit history.permissions: {} and pins third-party actions to full commit SHAs. Before opening the repository to the public I scrubbed personal data, generalized vehicle settings, and added SECURITY.md.AGENTS.md file and protected PRsOnce the core engine worked, I protected the main branch on GitHub and codified agent rules in AGENTS.md. Neither I nor Antigravity can push straight to main. Every bug fix, refactor, or feature uses a branch and must pass five PR gates before merge:
> 90% branch coverage (fail_under = 90 in pyproject.toml).:latest to ghcr.io.These gates keep Gemini 4 Carbon in check during autonomous runs. When a change drops test coverage below 90% or trips a linter rule, pre-commit and CI block the merge. The agent fixes the failure on its own before I review the PR.
Unit tests check math, not live weather forecasts or inverter firmware quirks. Because cheap-watts writes Modbus holding registers to a 10 kW grid-tied hybrid inverter, I built --dry-run as a strict hardware safety gate from the start.
In --dry-run mode, the container queries all live inputs: electricity provider tariffs, dual-string solar forecasts, vehicle telemetry, and local inverter Modbus registers. It runs the full planner, skips every Modbus write call, and prefixes change emails with [DRY-RUN].
Before going live, I ran cheap-watts in --dry-run mode on my mini PC for several days and monitored its [DRY-RUN] alerts. So far, every decision was accurate, from recommending the cheapest vehicle charging windows to sizing battery grid-charging right after the cars finished. Each time an alert arrived, I verified the plan and applied those exact settings by hand.
After that testing period, I dropped --dry-run from crontab and switched cheap-watts to production mode. Whenever I ship a major update, I turn --dry-run back on first to verify nothing broke before re-enabling live inverter writes.
Ready to explore the project or try an agentic engineering workflow on your next weekend build? Here is where to go next:
AGENTS.md and CI gates.romin-security skill on GitHub.I'm always curious how others are using agentic engineering in their projects. Share your setups and questions with me on social media:
discussI Constantly Try to Survive Reality Maybe that's why I built an entire universe, including a...
aiWhen you build an AI agent, you're actually using two separate things, not one. In this episode of...
agentsHow stateful agent harnesses run, suspend, and wake in under a second on Agent Substrate 1.0, from one VM to millions of actors.
top7Welcome to this week's Top 7, where the DEV editorial team handpicks their favorite posts from the...
discussMeme Monday! Today's cover image comes from the last thread. DEV is an inclusive space! Humor in...
angularI upload images of places, wrestlers, and general objects to the application. When uploading images...
Workflows from the Neura Market marketplace related to this CoPilot resource