Skip to content

feat: per-CPU temperature sensors over MQTT/Home Assistant#12

Merged
sethpjohnson merged 1 commit into
mainfrom
claude/yqkz8t1k-per-cpu-mqtt
Jul 18, 2026
Merged

feat: per-CPU temperature sensors over MQTT/Home Assistant#12
sethpjohnson merged 1 commit into
mainfrom
claude/yqkz8t1k-per-cpu-mqtt

Conversation

@sethpjohnson

Copy link
Copy Markdown
Owner

What

Breaks out per-CPU-socket temperatures over MQTT so Home Assistant shows one temperature sensor per physical CPU, not just a single aggregate. On a two-socket R730 (e.g. bandit) this turns 1 CPU sensor into 3: CPU 1, CPU 2, and the existing max.

Mirrors the per-GPU implementation shipped in v1.2.0.

Changes (all in internal/mqtt/)

  • State payload: new cpus array — one {index, temp} per socket, sourced from status.CPU.Temps (already read; only .Max was published before).
  • Per-CPU discovery: cpuN_temp HA sensors (0-based ids cpu0_temp/cpu1_temp, 1-based labels "CPU 1/2 Temperature"), device_class: temperature, °C, cold-start-safe default('') value_templates indexing value_json.cpus[i].temp.
  • Lazy publish: publishNewCPUDiscovery mirrors publishNewGPUDiscovery — mutex-guarded, gated on a successful state publish, cleared on reconnect (handles connect-before-first-read).
  • Aggregate preserved: cpu_temp (max) sensor unchanged in id/value key, relabeled "CPU Temperature (Max)" for parity with the GPU max sensor. Fan logic and existing HA history depend on it.
  • Scales to N sockets; nothing hardcoded. internal/controller untouched — control loop stays MQTT-unaware.

Test evidence

  • go vet ./... clean · CGO_ENABLED=1 go build ./cmd/controller ok · go test -race -count=1 ./... all 8 packages pass.
  • New/extended tests: buildStatePayload cpus population (2 & N sockets, nil when no reading), cpuDeviceSpecs ids/labels/device_class/template, lazy discovery once-per-index + reconnect re-announce, key-correspondence guard for cpus[].temp, aggregate relabel.
  • Acceptance: driven against a real mosquitto broker in --demo — observed "cpus":[{"index":0,"temp":41},{"index":1,"temp":42}], both cpuN_temp/config discovery messages with correct topics/labels, aggregate relabeled, values updating per tick, all confirmed as retained messages.

Task: dex yqkz8t1k

🤖 Generated with Claude Code

Publish one HA discovery sensor per CPU socket (cpu0_temp, cpu1_temp, ...)
alongside a cpus[] array in the retained state document, mirroring the
existing per-GPU implementation. The monitor already read both sockets into
CPUReading.Temps; only the max was ever published. The aggregate cpu_temp
sensor is preserved (fan logic and HA history depend on it) and relabeled
'CPU Temperature (Max)' for parity with the GPU max sensor. Per-CPU discovery
is published lazily on first successful state publish, mutex-guarded and
cleared on reconnect, matching the GPU cold-start handling. Scales to N
sockets. Confined to internal/mqtt; the control loop stays MQTT-unaware.

Task: dex yqkz8t1k — Per-CPU temperature sensors over MQTT/HA

Co-Authored-By: Claude <noreply@anthropic.com>
@sethpjohnson
sethpjohnson merged commit 01f69fc into main Jul 18, 2026
2 checks passed
@sethpjohnson
sethpjohnson deleted the claude/yqkz8t1k-per-cpu-mqtt branch July 18, 2026 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant