Add dormant sml2mqtt power-meter bridge (phase 1 of moving HA off edge) #83

Merged
k.renner merged 1 commits from worktree-ha-meter-mqtt-bridge into master 2026-06-27 20:46:35 +00:00
Owner

Phase 1 of moving the resource-hungry Home Assistant pod off k8s-edge

HA (privileged, 8Gi limit, ~10k entities) is pinned to k8s-edge only because it reads the USB power meter (FTDI FT230X, /dev/ttyUSB0) via the built-in edl21 integration. This adds an sml2mqtt bridge that reads the meter and publishes OBIS values to the in-cluster Mosquitto broker; HA will then read it over MQTT and no longer need the USB device or the edge node.

Ships DORMANT (replicas: 0)

The meter's serial port is a single stream — sml2mqtt and edl21 cannot both read it without corrupting SML framing. So this is dormant; merging changes nothing at runtime. It just stages the infra. The runtime cutover (done separately, by me, end-to-end) is:

  1. Disable edl21 in HA (frees the serial port)
  2. Scale sml2mqtt to 1, --analyze once to learn the meter's device-id/OBIS, finalize topics
  3. Add HA mqtt: sensors reusing the existing entity_ids (sensor.smart_meter_positive_active_energy_total, …_negative_…, …_sum_active_instantaneous_power) with matching Wh unit + state_class → long-term-statistics history continues seamlessly (statistics are keyed by entity_id and survive integration removal)
  4. Drop HA's edge nodeSelector/toleration + USB mount → HA reschedules to a CP node

The utility meters in the homeassistant repo (packages/energy_monitoring.yaml) are untouched — their source entity_ids don't change.

Contents

  • sml2mqtt-deployment.yaml — edge-pinned, replicas: 0, spacemanspiff2007/sml2mqtt:3.6.0, runs as root (meter dev is root:root 0600; no privileged needed, unlike HA today), USB hostPath, init container renders the broker password into config.yml from a Secret (sml2mqtt has no env-var password override).
  • sml2mqtt-config.yaml — v3 config; Wh kept (not kWh) to match edl21 for history continuity; publishes to mosquitto:1883 as user sml2mqtt.
  • mosquitto — 4th broker user sml2mqtt (publish-only sml2mqtt/#): new bootstrap Job (generates mosquitto-sml2mqtt-credentials) + passwd/ACL/env entries. Mosquitto pod will recreate on merge (brief MQTT blip; clients reconnect).

Verification

kubectl kustomize kubernetes/apps/home-assistant builds; all resources render (config, dormant deployment, bootstrap Job, ACL/env). No Service (publish-only). No runtime effect until I begin the cutover after merge.

Generated with Claude Code

## Phase 1 of moving the resource-hungry Home Assistant pod off k8s-edge HA (privileged, 8Gi limit, ~10k entities) is pinned to k8s-edge **only** because it reads the USB power meter (FTDI FT230X, `/dev/ttyUSB0`) via the built-in `edl21` integration. This adds an `sml2mqtt` bridge that reads the meter and publishes OBIS values to the in-cluster Mosquitto broker; HA will then read it over MQTT and no longer need the USB device or the edge node. ### Ships DORMANT (`replicas: 0`) The meter's serial port is a single stream — `sml2mqtt` and `edl21` **cannot both read it** without corrupting SML framing. So this is dormant; **merging changes nothing at runtime**. It just stages the infra. The runtime cutover (done separately, by me, end-to-end) is: 1. Disable `edl21` in HA (frees the serial port) 2. Scale `sml2mqtt` to 1, `--analyze` once to learn the meter's device-id/OBIS, finalize topics 3. Add HA `mqtt:` sensors **reusing the existing entity_ids** (`sensor.smart_meter_positive_active_energy_total`, `…_negative_…`, `…_sum_active_instantaneous_power`) with matching **Wh** unit + `state_class` → long-term-statistics history continues seamlessly (statistics are keyed by entity_id and survive integration removal) 4. Drop HA's edge `nodeSelector`/toleration + USB mount → HA reschedules to a CP node The utility meters in the `homeassistant` repo (`packages/energy_monitoring.yaml`) are untouched — their source entity_ids don't change. ### Contents - **`sml2mqtt-deployment.yaml`** — edge-pinned, `replicas: 0`, `spacemanspiff2007/sml2mqtt:3.6.0`, runs as root (meter dev is `root:root 0600`; **no `privileged`** needed, unlike HA today), USB `hostPath`, init container renders the broker password into `config.yml` from a Secret (sml2mqtt has no env-var password override). - **`sml2mqtt-config.yaml`** — v3 config; **Wh kept** (not kWh) to match edl21 for history continuity; publishes to `mosquitto:1883` as user `sml2mqtt`. - **mosquitto** — 4th broker user `sml2mqtt` (publish-only `sml2mqtt/#`): new bootstrap Job (generates `mosquitto-sml2mqtt-credentials`) + passwd/ACL/env entries. Mosquitto pod will recreate on merge (brief MQTT blip; clients reconnect). ### Verification `kubectl kustomize kubernetes/apps/home-assistant` builds; all resources render (config, dormant deployment, bootstrap Job, ACL/env). No Service (publish-only). No runtime effect until I begin the cutover after merge. Generated with Claude Code
k.renner added 1 commit 2026-06-27 20:46:02 +00:00
First phase of moving the resource-hungry Home Assistant pod off k8s-edge.
HA is pinned to edge solely by the USB power meter (FTDI FT230X) it reads
via the built-in edl21 integration. This adds an sml2mqtt bridge that will
read the meter and publish to the in-cluster Mosquitto broker, so HA can
read it over MQTT and stop needing the USB device / the edge node.

Shipped DORMANT (replicas: 0): the meter's serial port is a single
stream, so sml2mqtt and HA's edl21 cannot both read it. Merging this
changes nothing at runtime. The cutover (separate steps) is: disable
edl21 -> scale this to 1 -> add HA MQTT sensors reusing the existing
entity_ids (preserves long-term-statistics history) -> evict HA from edge.

Contents:
- sml2mqtt-deployment.yaml: edge-pinned, replicas:0, runs
  spacemanspiff2007/sml2mqtt:3.6.0 as root (meter dev is root:root 0600;
  no privileged needed), USB hostPath mount, init container renders the
  broker password into config.yml from a Secret.
- sml2mqtt-config.yaml: v3 config; Wh kept (not kWh) to match edl21 so
  history is continuous; publishes to mosquitto:1883 as user sml2mqtt.
- mosquitto: 4th broker user `sml2mqtt` (publish-only sml2mqtt/#) via a
  new bootstrap Job + passwd/ACL/env entries.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
k.renner merged commit 38001465cb into master 2026-06-27 20:46:35 +00:00
Sign in to join this conversation.