Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions docs/AUDIO_INVESTIGATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# C-Bus Audio (205) and Media Transport (192) — Investigation Notes

Where cgateweb stands on the C-Bus **Audio** application (app `205`, `$CD`) and the
**Media Transport Control** application (app `192`, `$C0`), what is still unknown, and
how to capture the data needed to close the gap. Tracks
[issue #172](https://github.com/dougrathbone/cgateweb/issues/172).

> **Status legend:** ✅ verified against real hardware · ⚠️ from the C-Gate manual only ·
> ❓ unknown / not captured.

## Current state

Nothing is decoded. What the bridge does today:

- Audio and Media Transport event lines are claimed by `src/audioEventHandler.js`, so they no
longer log "Could not parse event line" (their address has two segments, no group, which
`CBusEvent` cannot parse).
- Each line is passed to raw event capture. Set `cbus_raw_event_log_apps` to `[205, 192]` and
every line is logged verbatim and published to `cbus/read/{net}/{app}/raw`.
- The first line of each application also logs one INFO message saying how to capture.

Nothing is published to Home Assistant and no audio command can be written. That is deliberate:
see "Why not guess" below.

## What the C-Gate manual gives us (⚠️)

Audio commands (sections 4.5.16–4.5.35), addressed `audio <verb> <net>/205 …`:

| Verb | Arguments | Meaning per manual |
|---|---|---|
| `current_feed` | `mux zone feed gain` | Reports the current feed (`feed` 0..7, `gain` 0..4) |
| `set_feed` | `mux zone feed option` | Sets the zone's feed |
| `next_feed` / `previous_feed` | `mux zone` | Step the feed |
| `request_current_feed` | `mux zone` | Ask for `current_feed` |
| `mute` | `mux zone mode` | `0` amp off, `2` volume normal/speakers off, `5` volume preset/speakers off, `7` volume preset/speakers on, `255` volume normal/speakers on |
| `on` / `off` | `mux zone code` | Send an on/off operation |
| `ramp` | `mux zone code level rate` | Ramp a zone function to `level` 0..255; `rate` 0..15 (0 instant, 1 = 4 s … 15 = 17 min) |
| `terminateramp` | `mux zone code` | Stop a ramp |

`mux` is 0..2, `zone` 0..7. Every verb also has a `Z <function>` form where `function` (0..255)
replaces `mux zone`. Other verbs exist for labelling (`zone_descriptor_request`,
`zone_feed_label_request`), `high_priority`, `dynamic_1/2`, `next_language`,
`output_common_control`, `output_device_status_request` and `output_error_code`.

Media Transport commands (sections 4.5.99–4.5.118) take `app group [operation]`, where `group` is
the media-link group: `play`, `pause`, `stop`, `next_track`, `set_track`, `forward`, `rewind`,
`shuffle`, `repeat`, `source_power`, `status_request`, `enumerate`, `set_category`, and friends.

The manual's sample line for the event port shows the `#`-prefixed shape:
`# audio zone_feed_label_request //BOARD/254/205 1 2 #sourceunit=0 OID=…`

## What we do not know (❓)

These block a decoder. Each needs a real capture, or the audio protocol document
(*C-Bus Application Messages and Behaviour*, chapter 14, CBUS-APP/14), which is not in this
repository:

1. **What zone function `code` means.** `ramp`/`on`/`off` take a `code` 0..7. Volume is the
obvious candidate, but the manual does not say.
2. **Feed to source name.** `feed` is 0..7; nothing maps a number to "Tuner" or "CD". Labels come
from `zone_feed_label_request` traffic or the C-Gate database, and we have not seen either.
3. **Whether `mute` mode 0 is the only "power off".** Mode 0 turns the amplifier off, but
whether the amp reports state changes on the bus, and as which verb, is unobserved.
4. **Event grammar.** Which verbs a real amp or matrix emits unprompted, whether they arrive as
`audio …` or `#s# audio …`, and what `#sourceunit` identifies.
5. **Media Transport group semantics.** Which `group` values real players use, and whether state
(playing, track number) is reported or only commanded.

## Why not guess

The HVAC work (see [HVAC_INVESTIGATION.md](./HVAC_INVESTIGATION.md)) showed what a plausible
but unverified decoder does: it publishes confident nonsense that looks right until someone
checks it against a real device. Unknown semantics here fail closed, as in
`src/applicationDecoders/clockDecoder.js`.

## Home Assistant mapping constraint

Home Assistant's MQTT integration has **no `media_player` discovery platform**. The issue asks for
media players, which cannot be created through MQTT Discovery. What MQTT Discovery does support,
and what an audio zone maps onto once decoded:

| Zone capability | HA entity |
|---|---|
| Amplifier power / mute mode | `switch`, or a `select` over the `mute` modes |
| Source (feed) | `select` |
| Volume | `number` |
| Transport (play, pause, next) | `button` |

A true `media_player` would need a custom integration, which is out of scope for this bridge.
Whether to ship the entity set above is a decision for after the captures are in.

## How to capture (for testers)

1. Set `cbus_raw_event_log_apps` to `[205, 192]` (add-on option or `settings.js`).
2. Restart the bridge and, with the C-Bus audio hardware idle, work through each action on a
real keypad, touchscreen or the manufacturer's app: change source, change volume (note the
direction and rough amount), mute, unmute, power the zone off and on, and play, pause and skip
on any media-transport source.
3. Write down what you did next to each line. The log lines are the evidence; the notes tell us
what they mean.
4. Collect the `C-Gate raw capture [app 205]` / `[app 192]` log entries, or subscribe to `cbus/read/+/205/raw` and
`cbus/read/+/192/raw`. Keypad PINs are redacted, but check before sharing.
5. If you can, attach the C-Gate project's audio zone and feed labels as well.

## Plan

1. **Capture** (this change): claim the lines, make them capturable.
2. **Decode** once captures confirm the grammar: `audioDecoder.js` under
`src/applicationDecoders/` with fixtures taken verbatim from real captures, published as
read-only state.
3. **Discover** the entity set above, read-only first.
4. **Control**: command writes on `cbus/write/...`, only for operations confirmed on hardware.
2 changes: 1 addition & 1 deletion docs/SETTINGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ The add-on does this for you: its service script exports `LOG_LEVEL` from the `l

| Setting | Add-on option | Type | Default | Notes |
|---|---|---|---|---|
| `cbusRawEventLogApps` | `cbus_raw_event_log_apps` | number[] | `[]` | Applications whose raw C-Gate event lines are logged verbatim and republished to `cbus/read/{net}/{app}/{group}/raw`. For capturing ground-truth protocol samples before writing a decoder (e.g. `[172]`). Empty disables. Leave empty in normal operation — it is noisy. |
| `cbusRawEventLogApps` | `cbus_raw_event_log_apps` | number[] | `[]` | Applications whose raw C-Gate event lines are logged verbatim and republished to `cbus/read/{net}/{app}/{group}/raw` (`cbus/read/{net}/{app}/raw` for applications with no group address: Audio 205, Media Transport 192, Clock 223). For capturing ground-truth protocol samples before writing a decoder (e.g. `[172]`, or `[205, 192]` for audio). Empty disables. Leave empty in normal operation — it is noisy. |

---

Expand Down
6 changes: 6 additions & 0 deletions homeassistant-addon/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ If this add-on saves you time, you can [buy me a coffee](https://buymeacoffee.co

Releases before 1.22.0 are in the [changelog archive](https://github.com/dougrathbone/cgateweb/blob/master/homeassistant-addon/CHANGELOG-archive.md).

## [1.40.6](https://github.com/dougrathbone/cgateweb/releases/tag/v1.40.6) - 2026-11-21

### Added

- **Audio and Media Transport lines are now captured instead of reported as unreadable.** Set raw event logging to include applications 205 and 192 and share what your hardware sends. ([#172](https://github.com/dougrathbone/cgateweb/issues/172))

## [1.40.5](https://github.com/dougrathbone/cgateweb/releases/tag/v1.40.5) - 2026-11-21

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion homeassistant-addon/DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ Disable auto-discovery (`auto_discover_networks: false`) if:
| `cbus_clock_enabled` | boolean | `false` | Decode C-Bus Clock and Timekeeping (app 223) broadcasts as two diagnostic sensors on the network device, and ask C-Gate for a clock refresh on connect. Read-only: this never sets the network clock. Off by default. |
| `cbus_scene_module_enabled` | boolean | `false` | Accept MQTT `cbus/write/{network}/{app}/{set}/play` and `/record` (payload is the scene number) for a C-Bus Scene Module. Off by default: most installs use Trigger Control scenes, and a record write overwrites module memory. |
| `cbus_enable_control_app_id` | integer | (null) | C-Bus Enable Control application id (typically `203`) for extra MQTT writes: `cbus/write/{network}/{app}/{group}/set` (native 0–255, or ON/OFF), `/label` (group name, hex-encoded), and `/remove` (payload ON; deletes the C-Gate group object). Leave empty to disable. No Home Assistant entities. ON/OFF/RAMP on that application still work without this. |
| `cbus_raw_event_log_apps` | list | `[]` | C-Bus application IDs whose raw C-Gate event lines are logged and republished to `cbus/read/{network}/{app}/{group}/raw` for protocol capture. Empty disables. Noisy; leave empty in normal use. |
| `cbus_raw_event_log_apps` | list | `[]` | C-Bus application IDs whose raw C-Gate event lines are logged and republished to `cbus/read/{network}/{app}/{group}/raw` (`cbus/read/{network}/{app}/raw` for apps with no group, such as Audio 205 and Media Transport 192) for protocol capture. Empty disables. Noisy; leave empty in normal use. |
| `ha_bridge_diagnostics_enabled` | boolean | `true` | Publish bridge health/diagnostic entities to Home Assistant via MQTT Discovery |
| `ha_bridge_diagnostics_interval_sec` | integer | `60` | How often to refresh bridge diagnostic states (seconds) |

Expand Down
2 changes: 1 addition & 1 deletion homeassistant-addon/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "C-Gate Web Bridge"
version: "1.40.5"
version: "1.40.6"
slug: cgateweb
description: "Bridge between Clipsal C-Bus systems and MQTT/Home Assistant"
url: "https://github.com/dougrathbone/cgateweb"
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cgateweb",
"version": "1.40.5",
"version": "1.40.6",
"description": "Node.js bridge connecting Clipsal C-Bus automation systems to MQTT for Home Assistant integration",
"keywords": [
"cbus",
Expand Down
4 changes: 3 additions & 1 deletion src/applicationDecoders/appEventLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const PREFIX_WITH_SPACE = {
security: 'security ',
measurement: 'measurement ',
clock: 'clock ',
trigger: 'trigger '
trigger: 'trigger ',
audio: 'audio ',
mediatransport: 'mediatransport '
};

// Matches the keypad/hardware-native shape of a Trigger Control line, e.g.
Expand Down
81 changes: 81 additions & 0 deletions src/audioEventHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// @ts-check
'use strict';

const { isAppEventLine } = require('./applicationDecoders/appEventLine');

/**
* Claims C-Bus Audio ($CD / app 205) and Media Transport Control ($C0 /
* app 192) event lines.
*
* Neither application is decoded yet. The C-Gate manual documents the command
* names and argument ranges (sections 4.5.16-4.5.35 and 4.5.99-4.5.118) but
* not what the zone function codes mean, and there are no real captures in
* this repository, so writing a decoder now would be a guess (see the note in
* src/applicationDecoders/clockDecoder.js on why that is worse than a missing
* feature; docs/AUDIO_INVESTIGATION.md lists what is unknown). What this handler does instead:
*
* - Keeps the lines out of CBusEvent. Their address has two segments
* (`//PROJECT/<net>/<app>`, no group), so CBusEvent warns "Could not parse
* event line" on every one, and the `#`/`#s#`-prefixed form is dropped as a
* comment before anything else sees it.
* - Sends them to raw event capture, so a tester can set
* cbus_raw_event_log_apps to 205 and 192 and share what their hardware
* actually emits.
* - Says once, at INFO, that audio traffic is on the bus and how to capture
* it.
*/

const AUDIO_APP_ID = '205';
const MEDIA_TRANSPORT_APP_ID = '192';

/** @type {Array<{ prefix: 'audio'|'mediatransport', name: string, appId: string }>} */
const CLAIMED_APPLICATIONS = [
{ prefix: 'audio', name: 'Audio', appId: AUDIO_APP_ID },
{ prefix: 'mediatransport', name: 'Media Transport', appId: MEDIA_TRANSPORT_APP_ID }
];

class AudioEventHandler {
/**
* @param {Object} deps
* @param {{ info: Function, debug: Function }} deps.logger
* @param {(line: string) => void} deps.captureRaw - Raw event capture hook.
*/
constructor({ logger, captureRaw }) {
this.logger = logger;
this.captureRaw = captureRaw;
/** @type {Set<string>} */
this._hintedApps = new Set();
}

/**
* @param {string} line - Raw line from the C-Gate event stream.
* @returns {true|false} true when the line was audio or media transport
* traffic and has been consumed, false when it is neither.
*/
handleLine(line) {
const application = CLAIMED_APPLICATIONS.find((app) => isAppEventLine(line, app.prefix));
if (!application) return false;

this.captureRaw(line);
this._hintOnce(application);
return true;
}

/**
* Once per application, not once per line: an audio matrix reports every
* zone change and this is INFO.
* @param {{ name: string, appId: string }} application
* @private
*/
_hintOnce(application) {
if (this._hintedApps.has(application.appId)) return;
this._hintedApps.add(application.appId);
this.logger.info(
`C-Bus ${application.name} traffic seen but not decoded yet. To help add support, set `
+ `cbus_raw_event_log_apps to include ${application.appId} and share the captured lines `
+ `(https://github.com/dougrathbone/cgateweb/issues/172).`
);
}
}

module.exports = AudioEventHandler;
7 changes: 6 additions & 1 deletion src/cgateWebBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class CgateWebBridge {
/** @type {*} */
measurementEventHandler;
/** @type {*} */
audioEventHandler;
/** @type {*} */
stateResyncCoordinator;
/** @type {*} */
networkInterfaceMonitor;
Expand Down Expand Up @@ -600,6 +602,7 @@ class CgateWebBridge {
['security', () => this._handleSecurityLine(line)],
['measurement', () => this._handleMeasurementLine(line)],
['clock', () => this._handleClockLine(line)],
['audio', () => this.audioEventHandler.handleLine(line)],
['trigger', () => this._handleTriggerMinMaxLine(line)]
];
/** @type {Record<string, true|typeof LINE_UNPARSED|false>} */
Expand Down Expand Up @@ -848,7 +851,9 @@ class CgateWebBridge {
// Redacted like the log line above. Redacting one and not the
// other was the original 1.24.3 miss: this publishes off-box to
// every broker subscriber, so it is the worse of the two (#51).
`cbus/read/${target.network}/${target.application}/${target.group}/raw`,
target.group === null
? `cbus/read/${target.network}/${target.application}/raw`
: `cbus/read/${target.network}/${target.application}/${target.group}/raw`,
redactCgateLine(line),
RAW_CAPTURE_MQTT_OPTIONS
);
Expand Down
12 changes: 12 additions & 0 deletions src/cgateWebBridgeBuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const EventPublisher = require('./eventPublisher');
const AirconEventHandler = require('./airconEventHandler');
const SecurityEventHandler = require('./securityEventHandler');
const MeasurementEventHandler = require('./measurementEventHandler');
const AudioEventHandler = require('./audioEventHandler');
const StateResyncCoordinator = require('./stateResyncCoordinator');
const CommandResponseProcessor = require('./commandResponseProcessor');
const { CgateVersionReporter } = require('./cgateVersion');
Expand Down Expand Up @@ -50,6 +51,9 @@ class _CgateWebBridgeBuild {
/** @type {() => *} */
_createLineProcessor;

/** @type {(line: string) => void} */
_publishRawEventCapture;

/** @type {() => number} */
_getAdaptiveQueueIntervalMs;

Expand Down Expand Up @@ -274,6 +278,14 @@ class _CgateWebBridgeBuild {
getHaDiscovery: this._getHaDiscovery
});

// Audio (app 205) and Media Transport (app 192) are not decoded yet;
// the handler only keeps their lines out of the standard parser and
// routes them to raw capture.
this.audioEventHandler = new AudioEventHandler({
logger: this.logger,
captureRaw: (line) => this._publishRawEventCapture(line)
});

// Republishes state after a Home Assistant or MQTT broker restart
// (issue #44). Neither event restarts the bridge, so nothing else would.
this.stateResyncCoordinator = new StateResyncCoordinator({
Expand Down
2 changes: 1 addition & 1 deletion src/config/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,7 @@ const SETTINGS_SCHEMA = {
default: [],
unit: 'none',
exposure: 'both',
description: 'Apps whose raw C-Gate event lines should be logged verbatim (and published to cbus/read/{net}/{app}/{group}/raw) for protocol capture. Empty = off. Noisy; leave empty in normal operation.',
description: 'Apps whose raw C-Gate event lines should be logged verbatim (and published to cbus/read/{net}/{app}/{group}/raw, or cbus/read/{net}/{app}/raw for apps with no group such as Audio 205 and Media Transport 192) for protocol capture. Empty = off. Noisy; leave empty in normal operation.',
aliases: ['cbus_raw_event_log_apps']
}
};
Expand Down
17 changes: 12 additions & 5 deletions src/rawEventCapture.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@
/**
* Decide whether a raw C-Gate line should be captured for the configured apps,
* and extract its address. Returns null when capture is disabled, the line has
* no network/application/group triple, or the app is not in the capture list.
* no network/application address, or the app is not in the capture list.
*
* The address is the first numeric triple on the line, which holds for every
* known C-Gate event/status shape (e.g. "lighting on 254/56/4",
* group-addressed C-Gate event/status shape (e.g. "lighting on 254/56/4",
* "//CLIPSAL/254/56/10", "300 //HOME/254/203/5: level=128").
*
* Applications with no group (Clock 223, Audio 205, Media Transport 192) carry
* a two-segment address such as "clock time //CLIPSAL/254/223 21:13:21 0".
* Those fall back to network/application with a null group, so the capture
* feature can see the traffic a decoder has yet to be written for.
*
* @param {string} line - Raw C-Gate line.
* @param {Array<string|number>} apps - Configured application IDs to capture.
* @returns {{network: string, application: string, group: string}|null}
* @returns {{network: string, application: string, group: string|null}|null}
*/
function parseRawCaptureTarget(line, apps) {
if (!apps || apps.length === 0) {
Expand All @@ -29,7 +34,9 @@ function parseRawCaptureTarget(line, apps) {
return null;
}

const match = line.match(/(\d+)\/(\d+)\/(\d+)/);
const triple = line.match(/(\d+)\/(\d+)\/(\d+)/);
const pair = triple ? null : line.match(/(?:^|[\s/])(\d+)\/(\d+)(?=[\s:]|$)/);
const match = triple || pair;
if (!match) {
return null;
}
Expand All @@ -39,7 +46,7 @@ function parseRawCaptureTarget(line, apps) {
return null;
}

return { network: match[1], application, group: match[3] };
return { network: match[1], application, group: triple ? match[3] : null };
}

module.exports = { parseRawCaptureTarget };
Loading
Loading