Speaking OCPP to my Wallbox

14 min readhomelab

Over the last months the house got more and more connected: the blinds, the heating, the garage door, the irrigation and, since October, the car charger. Each of them speaks its own protocol, and each of them ended up as a small backend in my smarthome monorepo, behind one frontend and one login. This is the first post of a series about these pieces, and I start with the one I wanted to do for the longest time: the electric car charger.

The charger is a Wallbox Pulsar Plus in the garage. Out of the box it talks to the myWallbox cloud, and the app lets you start, stop and schedule a charge. What I wanted was different: first, the charger should only talk to a service running in my lab, and second, that service should decide when and how fast the car charges using the solar production of the roof when there is some.

In this post, I will go through the small part of OCPP that is needed for this: how the charger registers, what it sends during a charging session, how to set the charging current, and how a service on top of it can expose all that to a frontend and to an assistant. The solar part comes at the end, in short, and will get its own post.

OCPP in five minutes

OCPP, the Open Charge Point Protocol, is the protocol between a charging station and its backend. The OCPP vocabulary calls the station the charge point and the backend the central system. Public chargers use it to talk to their operator, and many home chargers support it too, often hidden in an “advanced” menu of the app.

I use version 1.6J, the J standing for JSON. It is old (2015) but it is what the Pulsar Plus supports, and it is still what most chargers speak. Version 2.0.1 exists and apparently fixes a lot of things. Our charger does not support it.

A few things make 1.6J pleasant to work with:

  • The charger is the client. It opens a WebSocket to the central system and keeps it open. Nothing has to reach the charger from the outside, so it can stay in its IoT VLAN with no inbound rule.
  • The charger identifies itself in the URL. It connects to wss://<host>/ocpp/<chargePointId>. The Wallbox appends its ID itself, so in the app you only enter wss://ocpp.<base domain>/ocpp.
  • Authentication is plain HTTP Basic auth on the WebSocket handshake. The username is the charge point ID, and the password, called the AuthorizationKey, is 16 to 40 characters.
  • Both sides send commands. The charger reports what happens, the central system sends orders, both over the same socket.

Every message is a JSON array, and there are only three kinds of them. A CALL is a request, with a unique ID chosen by the sender, the action name and a payload. The other side answers with a CALLRESULT carrying the same ID, or a CALLERROR:

json
[2, "19223201", "Heartbeat", {}]
[3, "19223201", {"currentTime": "2026-11-26T14:16:12Z"}]
[4, "19223201", "NotImplemented", "Unknown action", {}]

ocpp-go sends one call at a time per charger: it waits for the answer, or for a timeout, before it sends the next one, so the code never pipelines requests.

The protocol is split into feature profiles. The charger tells which ones it supports, and the Pulsar Plus has Core, FirmwareManagement, LocalAuthListManagement, Reservation, SmartCharging and RemoteTrigger. For what I want, three of them are enough:

profile messages I use what for
Core BootNotification, Heartbeat, StatusNotification, Authorize, StartTransaction, StopTransaction, MeterValues (from the charger); GetConfiguration, ChangeConfiguration, RemoteStartTransaction (to the charger) registration, sessions, measurements, settings
SmartCharging SetChargingProfile, ClearChargingProfile, GetCompositeSchedule setting the current
RemoteTrigger TriggerMessage asking for a status or a meter reading now

The table lists 14 of the 28 request types in OCPP 1.6J; the rest cover things like firmware updates, reservations and local authorization lists. I did not write the framing and the message types myself: the service uses ocpp-go, which handles the WebSocket, the JSON schemas and the request/response matching.

Registering the charger

On the Wallbox side, the setup is in the myWallbox app, under Connectivity, OCPP: enable it, set the URL and the password. The charge point ID is shown there too, and it goes into the configuration of the central system.

The first thing the central system sees is the WebSocket handshake, with the charge point ID in the path and the Basic auth header. My server only accepts one charge point ID, and it compares the password in constant time.

Once the socket is open, the charger introduces itself with a BootNotification:

json
[2, "1", "BootNotification", {
  "chargePointVendor": "Wall Box Chargers",
  "chargePointModel": "PLP1-0-2-3",
  "chargePointSerialNumber": "…",
  "firmwareVersion": "6.7.43"
}]

The answer decides if the charger is registered. Accepted means yes, and it carries the server time and the heartbeat interval in seconds. Pending or Rejected would make the charger retry later.

json
[3, "1", {
  "status": "Accepted",
  "currentTime": "2026-11-26T14:15:25Z",
  "interval": 60
}]

The charger then reports the state of its connectors with StatusNotification, one for connector 0 (the charger itself) and one for connector 1 (the cable), and sends a Heartbeat every 60 seconds. On my charger the heartbeat is the only keep-alive: there are no WebSocket pings. The server read timeout has to account for that, otherwise it closes a perfectly healthy connection. I allow two missed heartbeats plus 30 seconds.

That is all it takes to “register” a charger. There is no enrolment and no certificate: a charger that knows the URL, its ID and the password is in.

Asking the charger what it can do

The charger exposes its settings as a flat list of key/value pairs. Three seconds after each connection, the service reads all of them with GetConfiguration. Mine returns 60 keys, and a few of them matter:

yaml
SupportedFeatureProfiles: Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger
ChargingScheduleAllowedChargingRateUnit: Current
ChargeProfileMaxStackLevel: "10"
MaxChargingProfilesInstalled: "30"
MeterValueSampleInterval: "10"
MeterValuesSampledData: Energy.Active.Import.Register,Power.Active.Import,Current.Import,Current.Offered,Voltage

The last two are not what the Wallbox ships with. By default it reports only the energy register, every 300 seconds, so there is no power and no current in its readings. That is fine for billing, but useless to regulate anything. So on connect the service changes both with ChangeConfiguration:

json
[2, "7", "ChangeConfiguration", {"key": "MeterValueSampleInterval", "value": "10"}]
[3, "7", {"status": "Accepted"}]

Finally the service sends two TriggerMessage requests, for a StatusNotification and a MeterValues, so it knows the current state immediately instead of waiting for the next change.

A charging session, message by message

This is where OCPP gets interesting. Here is what happened this afternoon when I plugged in the car and pressed Charge now in the frontend, straight from the service logs:

sequenceDiagram
    participant U as Frontend
    participant S as Central system
    participant W as Wallbox

    Note over W: 16:56:11 car plugged in
    W->>S: StatusNotification Preparing
    S-->>W: confirmation
    Note over S: no sun, SOLAR mode waits
    S->>W: SetChargingProfile TxDefaultProfile 0 A
    W-->>S: Accepted

    Note over U: 16:56:36 Charge now
    U->>S: PUT /api/v1/control/charge-now
    S->>W: SetChargingProfile TxDefaultProfile 13 A
    W-->>S: Accepted
    S->>W: RemoteStartTransaction idTag smarthome
    W-->>S: Accepted
    W->>S: StatusNotification SuspendedEV
    S-->>W: confirmation
    W->>S: StartTransaction meterStart 8196759 Wh
    S-->>W: Accepted, transactionId 12
    S->>W: SetChargingProfile TxProfile 13 A on transaction 12
    W-->>S: Accepted
    W->>S: StatusNotification Charging
    S-->>W: confirmation
    Note over W: 16:56:44 the car draws current

    loop every 10 s
        W->>S: MeterValues power, current, voltage, energy
        S-->>W: confirmation
    end

A few things deserve an explanation.

The car does not start charging by itself. My Wallbox has AuthEnabled=true, and the app shows the charger as “Locked”. In that state a plugged-in car stays in Preparing until someone authorizes the session, either with an RFID card or with a RemoteStartTransaction from the central system. This is actually what I want: the car only charges when the service decides so. The service sends the remote start with its own idTag, smarthome, retries every minute if no transaction follows, and gives up after five attempts until the next plug-in. If the car or I stop a transaction, it is not restarted until the car is unplugged.

The central system owns the transaction ID. The charger sends a StartTransaction with the connector, the idTag, the meter reading at the start and a timestamp, and the answer contains the ID it must use from then on:

json
[2, "42", "StartTransaction", {
  "connectorId": 1, "idTag": "smarthome",
  "meterStart": 8196759, "timestamp": "2026-11-26T16:56:40Z"
}]
[3, "42", {"idTagInfo": {"status": "Accepted"}, "transactionId": 12}]

The IDs come from a SQLite sequence in the service. The charger keeps the ID it was given and sends it in every MeterValues and in the final StopTransaction, and that ID can outlive a restart of the service in the middle of a session. If the counter started again at 1 after a restart, the service could hand out an ID the charger already uses for an older session, so the counter lives in the database. The meterStart is the lifetime energy counter of the charger in Wh: 8.2 MWh, most of it from before I took over.

The meter values are a bit verbose. Each reading is a list of sampled values, some per phase, with units that can be W or kW:

json
[2, "57", "MeterValues", {
  "connectorId": 1, "transactionId": 12,
  "meterValue": [{
    "timestamp": "2026-11-26T17:06:20Z",
    "sampledValue": [
      {"measurand": "Energy.Active.Import.Register", "unit": "Wh", "value": "8198157"},
      {"measurand": "Power.Active.Import", "unit": "W", "value": "9094"},
      {"measurand": "Current.Import", "phase": "L1", "unit": "A", "value": "13.0"},
      {"measurand": "Current.Import", "phase": "L2", "unit": "A", "value": "13.1"},
      {"measurand": "Current.Import", "phase": "L3", "unit": "A", "value": "13.0"},
      {"measurand": "Current.Offered", "unit": "A", "value": "13"},
      {"measurand": "Voltage", "phase": "L1-N", "unit": "V", "value": "232.7"}
    ]
  }]
}]

The service normalizes this at the edge: units to W, Wh, A and V, per-phase currents and voltages averaged, per-phase powers summed when there is no total. Current.Offered is the most useful one: it is the current the charger actually offers to the car, so it is the proof that a limit has been applied.

The session ends with the cable. When the car is full, the status goes to SuspendedEV: the charger offers current, the car does not take it. The transaction only ends when the car is unplugged, with a StopTransaction carrying the final meter reading and the reason, EVDisconnected for all my sessions so far. Then Finishing and back to Available.

Setting the charging current

The current is controlled with SetChargingProfile, from the SmartCharging profile. A charging profile is a schedule: a list of periods, each with a start offset and a limit, in amperes or in watts. OCPP is designed for complex things like “16 A until 7:00, then 32 A”, but I only need one period that starts now:

json
[2, "91", "SetChargingProfile", {
  "connectorId": 1,
  "csChargingProfiles": {
    "chargingProfileId": 101,
    "transactionId": 12,
    "stackLevel": 1,
    "chargingProfilePurpose": "TxProfile",
    "chargingProfileKind": "Relative",
    "chargingSchedule": {
      "chargingRateUnit": "A",
      "chargingSchedulePeriod": [{"startPeriod": 0, "limit": 13, "numberPhases": 3}]
    }
  }
}]
[3, "91", {"status": "Accepted"}]

There are three purposes, and choosing the right one took me some reading:

  • ChargePointMaxProfile limits the whole charger. I do not use it: the hardware maximum is set by a switch inside the Wallbox, at 13 A for my installation, and the charger never goes above it anyway.
  • TxDefaultProfile applies to any transaction that does not have its own profile, including the next one. This is the one to use before a session starts.
  • TxProfile applies to one running transaction, identified by its ID, and disappears with it.

The service uses TxDefaultProfile when there is no transaction and TxProfile during one, with fixed profile IDs (100 and 101) so that each new profile replaces the previous one instead of piling up. The order in the session above matters: the limit is installed first, then the remote start is sent, so the transaction starts at the current the service wants and not at the charger’s default. A remote start can also carry a TxProfile directly in its payload; I kept the two steps separate so the same code path sets the limit with or without a remote start.

The stackLevel decides which profile wins when several of the same purpose apply: the highest level. The charger announces its maximum in ChargeProfileMaxStackLevel (10 here), and since the service is the only one sending profiles, level 1 is enough.

Pausing is a limit of 0 A. The charger keeps the transaction open, offers no current, and the car waits. Setting 6 A again later resumes the charge in the same session.

Two traps to watch for:

  • Accepted does not mean applied. It only means the charger accepted the profile. The real proof is Current.Offered in the next meter values, and GetCompositeSchedule tells what the charger thinks its effective schedule is.
  • After a reconnect, the charger state is unknown. The service does not try to guess whether the profile survived: on each reconnect it forgets what it sent and applies the limit again. It also re-sends it every five minutes, which is cheap and covers anything I did not think of.

And one message I deliberately never send: UnlockConnector. The name suggests “unlock the charger”, the “Locked” of the app, but it only releases the cable latch, and stops the running transaction on the way.

Driving it from a service

All the OCPP code lives in one Go package, internal/ocpp, the only one that imports ocpp-go. ocpp-go is still pre-1.0, and I wanted to be able to replace it without touching the rest. Incoming messages are turned into plain domain events (charger connected, status changed, transaction started, meter sample) and handed to a session manager that stores them. Outgoing commands are methods like SetCurrentLimit, RemoteStart or ChangeConfiguration.

The library API is asynchronous, with callbacks. A small generic wrapper turns each command into a synchronous call with a timeout, which makes the control code much easier to read and to test:

go
func call[T any](ctx context.Context, s *Server, chargerID, action string,
	send func(cb func(T, error)) error) (T, error) {
	var zero T
	if !s.Connected(chargerID) {
		return zero, ErrNotConnected
	}
	ctx, cancel := context.WithTimeout(ctx, s.opts.CommandTimeout)
	defer cancel()

	type result struct {
		v   T
		err error
	}
	ch := make(chan result, 1)
	if err := send(func(v T, err error) { ch <- result{v, err} }); err != nil {
		return zero, err
	}
	select {
	case r := <-ch:
		return r.v, r.err
	case <-ctx.Done():
		return zero, fmt.Errorf("%s: %w", action, ctx.Err())
	}
}

On top of that, a control loop runs every second, decides which current the car should get, and calls SetCurrentLimit when the decision changes. It knows four modes: SOLAR, MAX_POWER (always 13 A), MANUAL (a fixed current) and a Charge now override that charges at full power until the car is unplugged, or for 12 hours at most.

The service exposes a small REST API to the rest of the house:

method path what
GET /api/v1/status everything: charger, energy flows, decision, limits
GET /api/v1/summary a small version for widgets
PUT /api/v1/control mode, battery priority, manual current
PUT /api/v1/control/charge-now start or stop the override
GET /api/v1/sessions past sessions, with energy and stop reason
GET /api/v1/events Server-Sent Events stream of all changes

Every call needs a Keycloak token: ev-user can look and press Charge now, ev-admin can change the settings. The Vue frontend has an EV card with the live power, the applied limit and the Charge now button, and the Android app reads /summary for its home screen and tiles.

The EV card of the smarthome frontend
The EV card during the Charge now session of this post: 9.1 kW and 13.1 A for a 13 A limit, no PV, and the house, car included, drawing 12.4 kW from the grid. The frontend is in French, like the rest of the house.

The whole thing runs as one pod on the Kubernetes cluster, built by Woodpecker and deployed by ArgoCD like the other backends. The charger connects to wss://ocpp.<base domain>/ocpp, Traefik terminates TLS and forwards the WebSocket to the pod.

And the sun?

The reason for all this is the solar production. The house has PV panels, a Sonnen battery and, between them, a lot of energy that goes to the grid for little money in the afternoon, while the car charges from the grid in the evening. The service reads the Sonnen local API every minute, which gives the grid power measured at the house connection, the battery power and the production.

From that, the SOLAR mode computes how many amperes the car could take without importing from the grid. A setting decides whether the battery or the car gets the surplus first.

Everything else in this post is the plumbing for that loop. How it behaves with real clouds, how the battery and the car share the surplus, and what I had to tune will be the subject of the next post. It will need some sun first: today at the time of the writing, the panels produced 0 W and since the service went live in October, every session was a Charge now as the solar production was never high enough to ensure a steady charge.

What I take away

OCPP 1.6J looked intimidating from the specification, but the part needed to run a home charger is small: a WebSocket, a dozen messages, and one schedule with one period. The difficulties were not in the protocol but in the behaviour of a real charger around it: a locked charger that waits for a remote start, meter values that say nothing until they are configured, no WebSocket pings, and answers that say Accepted without promising anything.

The charger now talks to my lab. It also means that if the service is down, there is no smart charging at all, which is the price of owning the backend.

The next posts of the series will look at the other pieces: the solar loop in detail, and how the battery and the car share the surplus.