Cambridge Audio CXA81 in Home Assistant with ESPHome (RS-232 + IR)

The Cambridge Audio CXA81 is a lovely amplifier with no network connection at all. I wanted it in Home Assistant: turn it on when the TV comes on, switch inputs from my phone, change the volume from the same scroll wheels that dim the lights, and, most of all, have Home Assistant know what the amp is doing when someone uses the remote instead.

It works now. An ESP32 the size of a sugar cube talks to the amp's RS-232 port for power, mute and input, and pretends to be the remote, over a wire, for volume. Soon it will live in a small printed box screwed onto the back of the amp; the case is on its way. This page has everything: the parts, the wiring, the protocol, the firmware, the case design, and everything that didn't work the first time.

The idea: two ports, two jobs

The back of the CXA81 has an RS232C socket and an IR in jack. Cambridge publishes the serial protocol (the CXA61 and CXA81 Serial Control Protocol, v1.0; my copy, in case that link moves), and it covers power, mute and input selection, but not volume: there is simply no volume command. Volume is an infrared-only affair. So the controller uses both: RS-232 for everything it can, and a wire into the IR input for volume.

How the pieces connectHome Assistant talks to an M5Stack ATOM Lite over Wi-Fi using the encrypted ESPHome API. The ATOM sits on an RS-232 base wired to the amplifier's RS232C socket, for power, mute, input and state. A second wire from the ATOM's G26 pin goes into the amplifier's IR in jack, for volume. The ATOM is powered over USB-C.Home Assistanton the home serverM5Stack ATOM LiteESP32 · ESPHomeon an AtomicRS232 Base(printed case: on its way)CambridgeAudio CXA81RS232CIR inWi-FiESPHome API(encrypted)RS-232power, mute,input ⇄ state3.5 mm monoRC-5: volumeUSB-C, 5 V
How it fits together. The ATOM is the only new device on the network; the amp never sees Wi-Fi.

The nice part of the serial port is that it is two-way. The amp announces changes on its own: press standby on the remote or turn the input knob, and a line comes down the cable a moment later. So Home Assistant always shows the real state, not a guess. Infrared is one-way and blind, which is fine for volume steps, since nothing needs to know the absolute volume.

Parts

PartWhy
M5Stack ATOM LiteESP32 (PICO-D4) in a 24 × 24 mm box, with a button, an RGB LED and a Grove port. Runs ESPHome.
M5Stack Atomic RS232 Base (A136)The ATOM clicks onto it. Proper RS-232 levels and a screw terminal for TX, RX and GND.
DB9 male to screw-terminal adapterPlugs into the amp's RS232C socket, screws on with its own long bolts. I took it out of its housing to fit the case.
3.5 mm mono (TS) plug with screw terminalsFor the IR in jack. Mono matters: tip is signal, sleeve is ground.
A few short wires, a USB-C cable and a 5 V USB power supplyThe ATOM runs from USB-C. Nothing is taken from the amp.
A Flipper Zero (optional)To read the remote's codes. Any IR receiver that decodes RC-5 works, or just use mine below.
The printed case (optional)Three parts, below. I don't own a printer, so I ordered it from Flintform. It hasn't arrived yet.

The serial protocol

9600 baud, 8 data bits, no parity, 1 stop bit (9600 8N1), plain ASCII. Every message looks like #group,number[,data] followed by a carriage return. Commands go out in one group and the amp answers in the next group up: amplifier commands are group 1 and their replies group 2, source commands group 3 and replies group 4.

Anatomy of a CXA81 serial messageThe command #1,02,1 followed by a carriage return means: group 1, amplifier commands; number 02, set power; data 1, on. The amplifier answers #2,01,1: group 2, amplifier replies; number 01, power state; data 1, on. It sends the same reply by itself when someone uses the remote.You send:#1,02,1⏎startgroupnumberdata\rgroup 1 = amplifier commands02 = set powerdata 1 = on (0 = standby)\r ends every messageThe amp answers:#2,01,1⏎startgroupnumberdata\rgroup 2 = replies to group 101 = power statedata 1 = onalso sent unasked (remote, knob)
One command and its reply. The same reply also arrives unasked when someone uses the remote or the front panel.

The full command list is in Cambridge's CXA61 and CXA81 Serial Control Protocol (PDF, 5 pages; there's a backup copy here). The handful I use:

SendMeansReply
#1,01What's the power state?#2,01,1 on, #2,01,0 standby
#1,02,1 / #1,02,0Power on / standby#2,01,…
#1,03Is it muted?#2,03,1 or #2,03,0
#1,04,1 / #1,04,0Mute / unmute#2,03,…
#3,01Which input?#4,01,NN
#3,04,NNSelect input NN#4,01,NN
#13,02Firmware version#14,02,… (mine: 04000G01A61E)

Input codes: 00–03 are A1–A4, 04–06 D1–D3 (digital), 14 Bluetooth, 16 USB Audio, 20 A1 Balanced. Errors come back in group 0: #0,01 unknown group, #0,02 unknown number, #0,03 bad data, #0,04 not available right now.

Wiring

WiringTop: the Atomic RS232 Base's TX goes to pin 2 of the DB9 adapter, RX to pin 3 and GND to pin 5; 12V is left unconnected. Bottom: the ATOM's Grove port G26 goes straight to the tip of a 3.5 mm mono plug and GND to its sleeve, with no resistor; the plug goes into the amplifier's IR in jack.Atomic RS232 BaseTXRXGND12Vnot connectedDB9 adapter(pins seen from the front, into the amp's RS232C)123456789TX → pin 2RX → pin 3GND → pin 5no answer? swap the wires on 2 and 3ATOM Grove portGND5VG26G323.5 mm mono (TS) plug+−sleeve (−)tip (+)→ into the amp's IR inG26 → tip, no resistorGND → sleeve
Top: RS-232, three wires. Bottom: infrared, two wires. Nothing else.

RS-232. TX, RX and ground, nothing else; leave the base's 12 V terminal alone. The protocol document doesn't say which pin the amp transmits on, so it's a coin toss: I started with TX on pin 3 and got nothing back, not a single byte. Swapping pins 2 and 3 fixed it immediately. Swapping is harmless, so if your amp doesn't answer, that's the first thing to try.

Infrared. G26 from the Grove port goes to the tip, GND to the sleeve, and the plug goes into IR in (not the Control Bus sockets next to it). No resistor: see the next section. Since the tip brushes the sleeve contact as a plug goes in, plug it in before powering the ATOM.

Volume over infrared, by wire

First, the codes. Pointing the original remote at a Flipper Zero (Infrared → Learn New Remote) decoded them straight away: RC-5, address 0x10, command 0x10 for volume up and 0x11 for volume down. RC-5 is Philips' old protocol: 14 bits, Manchester coded, each bit two halves of 889 µs, on a 36 kHz carrier.

Then the hard part: what does an "IR in" jack actually want? A remote's LED flashes a 36 kHz carrier; an IR receiver strips the carrier and outputs a clean signal that is high when idle and goes low during each flash. A wired IR input might want either, and Cambridge doesn't say. So I tried them, one firmware update over Wi-Fi each, pressing volume up and watching the knob:

TrySignalSeries resistorResult
136 kHz carrier, normal polarity1 kΩnothing
236 kHz carrier, inverted1 kΩnothing
3no carrier, inverted (like a receiver's output)1 kΩnothing
436 kHz carrier, invertednonethe volume went up

The resistor was the problem all along. I'd added 1 kΩ in series out of habit, to protect the pin. But the input pulls itself up, and through 1 kΩ the ATOM could not drag the line low enough for the amp to see a signal. Without it, the inverted, carrier-modulated signal works every time.

The infrared signal on the wireThe first eight RC-5 bits of the volume-up command: two start bits, the toggle bit and the start of address 0x10. Top: the logical signal, where a mark is when a remote's LED would be on. Bottom: what goes into the IR in jack, inverted: the line idles high and every mark is a burst of 36 kHz carrier pulling it low.What the remote's LED does (mark = light on)11010000starttoggleaddress 0x10 (continues…)889 µsWhat goes into IR in: inverted, idles high, each mark is a 36 kHz burst3.3 V0 VA frame is 14 bits (≈ 25 ms), repeated per volume step with a 120 ms gap.The carrier is drawn about 6× slower than it is, or it would be a solid block.
The first eight bits of volume up, as a remote sends them (top) and as the ATOM puts them on the wire (bottom).

One honest caveat: I only tried the other formats with the resistor fitted. One of them may also work without it. Inverted with the carrier works, so I stopped there.

The ESPHome firmware

Everything is in one ESPHome file, cxa81.yaml. The interesting parts:

Sending. Commands go through a queued script that adds the carriage return and waits 150 ms, so the amp gets one thing at a time and has time to answer.

cxa81.yamluart:
  id: amp_uart
  tx_pin: GPIO19    # Atomic RS232 Base
  rx_pin: GPIO22
  baud_rate: 9600   # 8N1 is the default

script:
  - id: amp_send
    mode: queued
    max_runs: 20
    parameters:
      cmd: string
    then:
      - lambda: |-
          std::string msg = cmd + "\r";
          id(amp_uart).write_str(msg.c_str());
      - delay: 150ms

Listening. Every 50 ms a small parser reads whatever has arrived, splits it into lines on \r, then into group, number and data, and publishes the state. Because this runs for every line, replies to our own commands and the amp's own announcements are handled the same way. That is the whole trick to staying in sync.

cxa81.yamlif (group == 2 && number == 1) {
  id(amp_power).publish_state(data == "1");
} else if (group == 2 && number == 3) {
  id(amp_mute).publish_state(data == "1");
} else if (group == 4 && number == 1) {
  // source code -> "A1", "D2", "Bluetooth", ...
}

At boot, and every 60 seconds as a safety net, it asks for power, mute, input and firmware. The power and mute switches use restore_mode: DISABLED, so a reboot of the ATOM never sends anything to the amp. I learned that one when the first boot put the amp into standby.

Volume. One remote_transmitter on G26, inverted, and two scripts that each send one RC-5 frame followed by a 120 ms gap, so the amp sees separate presses rather than one long hold:

cxa81.yamlremote_transmitter:
  id: ir_tx
  pin:
    number: GPIO26
    inverted: true          # idle high, bursts pull low
  carrier_duty_percent: 50% # the RC-5 action sets 36 kHz

script:
  - id: ir_volume_up
    mode: queued
    then:
      - remote_transmitter.transmit_rc5:
          address: 0x10
          command: 0x10      # 0x11 = volume down
      - delay: 120ms

An action for Home Assistant. volume_step takes a signed number of steps (capped at 20), so an automation can say "louder by 3" in one call:

cxa81.yamlapi:
  encryption:
    key: !secret cxa81_api_key
  actions:
    - action: volume_step
      variables:
        steps: int
      then:
        - repeat:
            count: !lambda "return std::min<int>(abs(steps), 20);"
            then:
              - if:
                  condition:
                    lambda: "return steps > 0;"
                  then:
                    - script.execute: ir_volume_up
                  else:
                    - script.execute: ir_volume_down
              - script.wait: ir_volume_up
              - script.wait: ir_volume_down

To build it yourself, put cxa81.yaml next to a secrets.yaml (start from secrets.example.yaml), flash it once over USB with esphome run cxa81.yaml, and after that over Wi-Fi.

In Home Assistant

Home Assistant finds the ATOM on its own (Settings → Devices & services → ESPHome, with the API key from secrets.yaml). It shows up as Amplifier:

EntityDoes
switch.amplifier_powerOn / standby, follows the remote
switch.amplifier_muteMute, follows the remote
select.amplifier_sourceA1–A4, D1–D3, Bluetooth, USB Audio, A1 Balanced
button.amplifier_volume_up / _downOne volume step
esphome.cxa81_volume_stepAction: several steps at once, negative for quieter
binary_sensor.amplifier_buttonThe ATOM's own button, which toggles the amp's power
sensor.amplifier_firmware, sensor.amplifier_wifi_signalDiagnostics

For example, an automation step that turns it up by three:

action: esphome.cxa81_volume_step
data:
  steps: 3   # -3 for quieter

Turning the amp on from standby over RS-232 works fine with the normal standby mode. I haven't tried it in Eco standby, where the amp may switch its serial port off.

The case

Status: not built yet. The parts are printing at Flintform and haven't arrived. Everything in this section is the design and the plan: nothing has been test-fitted, so a measurement may still be off. I'll update this post once it's on the amp.

A bare circuit board with wires hanging off the back of a nice amp is not a look. The goal: a small closed box where you see only the DB9 plug going into the amp and one cable leaving the side. Two things made it fiddly. The ATOM on its base is 56 mm long, more than the box could be deep, so it lies across the case on a shelf. And the DB9 adapter only fits once its plastic housing is removed, so the case holds the bare board by its metal flange.

Render of the printed case: closed from the DB9 end, closed from the back, and exploded into body, shelf and lid
Rendered from the same script that makes the STL files: closed from the DB9 end, from the back, and exploded.

Seen from above with the lid off:

          +---------------------------------------+
          |  o  bolt heads (outside, at back)  o  |
          |  +-------------------------------+ :: |
   USB-C ==  | ATOM + RS232 base, on a shelf | :: |   :: gap for the RS-232
    + IR ==  +-------------------------------+ :: |      wires to go down
          |      (DB9 board under the shelf)      |
          +--------------[  DB9  ]----------------+

The adapter's own long bolts go in from the back, through the case and the flange, into the amp's socket. So the case is screwed to the amp, and comes off again, without opening it.

It's designed in code rather than a CAD program: a Python script using manifold3d builds the parts from measured dimensions, writes the STL files and draws the preview above. Change a measurement at the top and run it again. One bug worth sharing: an early version hollowed the body before cutting the lid off, which left a skin of zero thickness across the top opening. Invisible in the preview, very visible to a slicer. Hollow after splitting.

pip install manifold3d trimesh numpy matplotlib
python cxa81_dongle.py    # writes the three STLs and the preview

The plan for assembly: board in (flange into the front slot), screw the RS-232 wires to its terminals, bolts in from the back, shelf in with the wires up through its slot, ATOM on the shelf, plug in USB-C and the IR lead (both cables leave through one notch in the side), lid on.

What I'd tell myself first

  1. Silence on RS-232 means swap 2 and 3. Before anything else.
  2. No series resistor on the IR wire. The IR input pulls itself up; with 1 kΩ in line, the ATOM couldn't pull it low enough.
  3. Inverted, with the carrier. For the CXA81's IR in, at least.
  4. Never let a reboot send commands. restore_mode: DISABLED on anything that talks to the amp.
  5. Read the state, don't remember it. Parse every line the amp sends, not just the replies you expect.
  6. Wait after an OTA update. ESPHome rolls back a new firmware if the device restarts too soon after installing it. Give it a minute before unplugging anything.

Files

Everything needed to build your own:

FileWhat
cxa81.yamlThe ESPHome firmware (10 kB)
cambridge-audio-cxa61-cxa81-serial-control-protocol.pdfCambridge Audio's serial protocol, v1.0 (627 kB). A copy of the original.
secrets.example.yamlThe secrets it expects
cxa81_dongle.pyThe case, as a Python script (17 kB)
cxa81_case_body.stlCase body, ready to print (231 kB)
cxa81_case_shelf.stlShelf for the ATOM (6 kB)
cxa81_case_lid.stlLid (102 kB)
cxa81_case_preview.pngThe render above, full size

Built over a few evenings with Claude Code as my pair: it wrote most of the YAML and the case script and read the ESPHome logs while I held the wires. Questions, or did it work on your amp? Sign the guestbook or get in touch.