Solar Dashboard - Phased approach to building with Claude Code
Seeing how poor the original site was, I requested from the seller the specification for inverter's communication module soon after I bought the inverter. The specification looks almost like it's matching what I've got. The gaps mattered to me only in the pre-generative-AI era.
Based on the spec, the real messages and what the old dashboard makes of them this can be deduced, at least for the most part and the most important metrics.
That is how I arrived at the phased order captured in this post, a couple of years before I had an agent to hand it to. Each phase builds on what the previous one has learned.
In order to consider phase complete, success criteria had to be met.
The starting point
The inverter's communication module posts its readings straight to the vendor's site, over plain HTTP, across the public Internet. If the site drops a message it is lost, and what it keeps I can only view as a filtered table.
Phase 1: the scraper
The first thing to build was a throwaway tool that logs in to the old dashboard and records what it shows, both the momentary and the historical readings. Labels, values and units are captured verbatim, exactly as displayed, and the interpretation is left for later.
The scraper doesn't interfere with the live path at all, as the inverter keeps talking to the vendor as before.
Why bother?
The old dashboard already knows what each number means, so it is the closest thing to documentation of the format
inverter's communication module is using.
Once I also hold the raw message behind each reading, I can line the two up side by side.
A few decisions I made up front:
- momentary and historical readings share one file, with one JSON object per line and each record tagged with its kind,
- every record carries two timestamps, the measurement time as shown by the dashboard and the time of scraping,
- the scraper remembers which historical ranges it has already fetched, so subsequent runs only fetch what's missing,
- no retry machinery, if the old dashboard is down, that period simply can't be analysed.
Old dashboard's authentication
The old system requires users, this agent included, to authenticate.
Instead of baking the credentials into the prompt I used local .env file, later replaced with SOPS
(Secrets OPerationS) to store them encrypted in the source control.
Deterministic script extracts the secrets to .env file to make it usable to the next, algorithmic, solution.
In order to design a scraper I asked Claude to build a throw-away proxy that can pre-authenticate for the purpose of recurring discovery sessions by an agent, so it could explore the site without my password ever entering its context.
Once the structure of the old system was known, Claude built a scraper as a Python program, which was able to authenticate with credentials retrieved from .env file too.
Phase 2: the relay
Previous phase delivered a tool that scrapes the old dashboard for visual representation of the data. Now I need to intercept the raw data sent by the inverter to the old dashboard so that data mapping and gap analysis has data points to work on.
In this phase the inverter gets pointed at the relay instead of the vendor's server. The relay passes each message to the old dashboard untouched, sends the vendor's response back to the inverter, and appends both the request and the response to a buffer on its own disk.
The old dashboard receives each message just once, at the time it arrives. If it is down at that moment, the message never gets there.
In this phase the relay recorded whatever arrived. The gates came later: it now only records traffic coming from the IP whitelist (the inverter's address), serial, path and size checks included, and refuses everything else.
The buffer keeps messages for a configurable period and prunes the older ones. The relay gives a unique identifier to each message but is rather dumb about the payload's contents. It leaves the payload untouched and stores the time of receipt alongside it (the clock of the communication module is not reliable).
For convenience, the early relay was run from the development workstation.
Phase 3: the forwarder
The messages already accumulate on a relay but Grafana shouldn't use the relay directly.
The purpose of it was to provide a simple, file-backed, always-on resilience layer (when homelab is offline)
collocated with inverter that can also handle a combo of encryption/signing/authentication if needed.
Unoptimized operations on raw, unstructured messages stored on a slowish, remote device accessed via API which isn't
compatible with Grafana and isn't designed for the use case will certainly be substandard.
I need to get the messages into my homelab's Postgres database for analysis, and the raw format will be a good start.
With this in mind, forwarder was created.
The forwarder runs in my homelab and is the only component writing to the database. It pulls the buffer from the relay over the LAN, with every request authenticated and all communication signed. It simply pulls pages of messages from relay using the last cursor position and inserts the fetched records into solar-dash's own Postgres database. The cursor is updated to reflect only messages successfully written.
The cursor value is stored in database which means that my multiple environments can share the same (compatible) relay.
A few decisions I made up front:
- the database gets every message, oldest first, and at most once, relay gives each record a unique id and the db has a constraint ignoring records with the same id,
- the database is plain Postgres with an append-only table of raw messages (a time-series database would be an overkill for the volume of messages inverter is sending).
Phase 4: experiments and analysis driving the data pipeline
The real inverter messages are now easily accessible and collocated. They are not instantly interpretable in their raw form, but they make a solid foundation for experiments. Scraped readings have been collected in JSONL files too. Claude can compare the bulk of them against the PI30 (aka P30) protocol specification. The protocol specification is for a slightly different version, so it was a starting point rather than an authority: some fields did not match what the communication module actually sent.
The result was an evolving field mapping, with uncertain interpretations left open until enough evidence was available. The old dashboard was a useful reference, but its readings also needed to be checked rather than taken on faith. Claude was enormously helpful here identifying discrepancies and suggesting the type and timing of experiments.
To get varied evidence, I ran controlled experiments, such as cutting the grid supply, switching between utility bypass and solar, inverter priority modes, taking manual measurements with calibrated multimeter, individual battery voltages and many other ones. These tests helped reveal operating modes and test whether the proposed field meanings held up in different conditions. Some helped with the calibration of field values others highlighted issues with the setup.
Incremental learning about the message structure did require a few pivots. It made sense for the transformation of the raw message to be schema-on-read SQL views so that the raw messages stay as an untouched source alongside. That allows reapplying the correct transformation after pivots.
As we progressed through the experiments and analysis Claude was incrementally folding the small bits of verified knowledge into the database views.
DT, the most useful of messages, goes through two views:
- splitting comma-delimited raw message into numbered fields, a step shared amongst all message types
- a single decoded view that names the fields, unpacks the bitfields and derives the calculations
What I love about this approach is that the captured raw messages is all that ever matters. If we learn a part of the message was interpreted wrong I just change the view definition. Updating the view definition immediately reinterprets the entire historical dataset with no backfill or reprocessing required.
Until long-running Grafana queries slow down I don't need to worry about the performance of the database views.
Phase 5: the dashboard
All phases were exciting but this one was the proverbial cherry on top of the cake.
Since I remember I was always partial to a graph and I always loved a good dashboard.
They are just extremely efficient at showing patterns, trends and deviations, giving you at-a-glance check
whether everything is fine.
It was not uncommon that I used a dashboard to identify a problem before the bulk of the users were impacted.
Sometimes even before the problem was reported, giving us a chance to fix and remediate proactively.
All my dashboards were either handcrafted or altered clones of existing ones. I never used generative AI for Grafana dashboards, but I had no doubt top Claude models will do a stellar job.
The first version was good already, something like 10 panels at once, illustrating the most important parameters
of the system. Then iterations followed with many new panels added and existing ones tweaked.
I have been using these dashboards since early September, and they have been a great help.
Performance-wise, while this isn't a large data use case, I accumulated over 120K data points since inception. I can chart the entire period and the dashboard loads swiftly and every panel works smoothly for that entire period. When I shrink the time range to a week or less, everything is instant.
With my limited example I have noticed that heavy use of my Grafana pod spikes memory usage by about 400MB but the CPU barely notices. The Postgres pod spikes by about 0.25core but memory spike is negligible.
Other posts in solar-dash series
- The challenge
- The vision
- Claude setup
- Phased approach
- Learning the protocol
- Managing agentic output
- Reflecting on agentic coding
- Conclusions