Skip to content

feat(ha): take Home Assistant's MQTT broker from the app - #2096

Merged
frahlg merged 1 commit into
masterfrom
onboarding-ha-mqtt-service
Nov 28, 2026
Merged

frahlg merged 1 commit into
masterfrom
onboarding-ha-mqtt-service

Conversation

@frahlg

@frahlg frahlg commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Paired with srcfl/home-assistant-addons#56 (the app side; the stable app in #57 uses the same recipe). Neither PR needs the other to be safe: without this one the app's variables are ignored, and without the app PR Core sees no variables.

Problem

In the Home Assistant app, FTW's entities need four MQTT fields typed by hand: broker, port, user and password. Home Assistant already knows its broker. The onboarding review (row 8) counts this among the steps a new user should not have.

Change

  • The app asks Supervisor for the broker (services: mqtt:want) and passes it in FTW_HA_MQTT_HOST, _PORT, _USERNAME, _PASSWORD. Core reads them only when FTW_BUNDLE=home_assistant_addon (go/cmd/ftw/ha_bundle_broker.go).
  • An enabled bridge with an empty saved broker uses that broker and its login. A broker the owner typed still wins.
  • A site that never set up the bridge starts it. The default lives in memory and is saved only when the owner saves settings, so Settings → Integrations shows Enabled and the switch still turns it off. A bridge the owner turned off stays off.
  • The broker password never enters saved settings or the API.
  • docs/ha-integration.md says the app needs no broker typed.
  • Changeset: minor, since the HA app changes a default (the bridge now starts by itself there). Owner approval needed.

Outside the Home Assistant app nothing changes. Files touched: go/cmd/ftw/ha_bundle_broker.go (new), ha_bridge_owner.go (fills the broker in Apply), main.go (8 lines where the owner is built), the test file, the doc and the changeset.

Evidence

  • make verify passes locally (vet, tests, build).
  • go test -race -run 'TestHABundle|TestHABridgeOwner' ./cmd/ftw/ passes. The new tests cover the variables, the fill and default rules, the owner, and a real (mochi) broker that requires a login and receives homeassistant/sensor/forty_two_watts/grid_power/config with no bridge settings at all.
  • Local run, both arches: the app image from the paired PR with this Core overlaid, a stub Supervisor that answers /services/mqtt, and Mosquitto 2.1.4 with a password. FTW announced 30 sensors, forty-two-watts/status read online, /api/ha/status through ingress said connected to core-mosquitto:1883, /api/config showed enabled: true, broker: "", and the broker password was in neither state.db nor config.yaml. amd64 ran under emulation.

Not tested

  • No real Home Assistant OS, Supervisor or Mosquitto broker app. The /services/mqtt answer was a stub with the documented shape.
  • A broker that needs TLS: the bridge has no TLS, so the app passes no broker then and logs why.
  • /api/ha/status still shows ? for the broker in the short time before the first connect, because it reads the saved (empty) broker.

Refs srcfl/home-assistant-addons#25

🤖 Generated with Claude Code

The Home Assistant app now asks Supervisor for Home Assistant's broker
(`services: mqtt:want`) and passes it in FTW_HA_MQTT_HOST, _PORT,
_USERNAME and _PASSWORD. Core reads them only when FTW_BUNDLE is
home_assistant_addon.

- An enabled bridge with an empty saved broker connects to that broker
  with its login. A saved broker still wins.
- A site that never set up the bridge starts it, in memory. The
  default is saved only when the owner saves settings, so Settings
  shows Enabled and the switch still turns it off.
- The broker and its password never enter the saved settings or the
  API.

Tests cover the variables, the fill and default rules, the owner, and
a real broker that receives discovery with no settings at all.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
frahlg added a commit that referenced this pull request Nov 28, 2026
A newcomer met version history first and had to copy a tag from Releases
into a twelve-line block. With #2095 the installer picks the
release itself, so every install page now gives one line:

    curl -fsSL https://ftw.energy/install.sh | bash -s -- --fresh-host

README opens with five lines: Home Assistant, a Linux computer, what FTW
runs on, what a home needs, and the iPhone app. docs/before.md holds the
2.x/3.x, old Docker, second-card and old Home Assistant app material; each
first-install page links to it in one line.

The Home Assistant pages describe the app after
srcfl/home-assistant-addons#56 and #2096: FTW (beta) opens inside
Home Assistant behind its login, port 8080 is closed, entities need no
broker typed, and a stable app named FTW follows the first stable.

The Pi guides in five languages run the line in step 11, show the printed
address and list what the setup page asks. native-beta.md and update-sv.md
change only their install section, the hardware line and the app rows.

scripts/test_install_docs.py now requires the one line, exactly once, on
each page that installs, and no other --fresh-host block in README or
docs/. CI runs it when those pages change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
@frahlg
frahlg marked this pull request as ready for review November 28, 2026 05:52
@frahlg
frahlg merged commit 61691d5 into master Nov 28, 2026
22 checks passed
@frahlg
frahlg deleted the onboarding-ha-mqtt-service branch November 28, 2026 05:52
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-28T05:53:36.393291Z c2e3fd0 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

frahlg added a commit that referenced this pull request Nov 28, 2026
…wn page (#2002)

* docs: a short first-install path, with Home Assistant first

A newcomer met the architecture first, then a warning about 2.x and 3.x,
and reached the install command on line 170 of a 541-line guide.

README now opens with what FTW does, a dashboard screenshot and Get
started: Home Assistant, then Raspberry Pi or Linux. docs/install.md is
the first-install page, with a Swedish copy. The switch guide keeps the
old-version material and is not changed here.

The Home Assistant guide describes the app as shipped: Open web UI goes
to port 8080. Core has an ingress mode, but the app does not turn it on
yet. Both guides gain the one-click "add repository" button.

The paragraphs about the bundled driver pin move from README to
docs/device-repository.md. The install-docs test now checks that the new
pages carry the same native block as docs/native-beta.md.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

* docs: one install line, and old versions on their own page

A newcomer met version history first and had to copy a tag from Releases
into a twelve-line block. With #2095 the installer picks the
release itself, so every install page now gives one line:

    curl -fsSL https://ftw.energy/install.sh | bash -s -- --fresh-host

README opens with five lines: Home Assistant, a Linux computer, what FTW
runs on, what a home needs, and the iPhone app. docs/before.md holds the
2.x/3.x, old Docker, second-card and old Home Assistant app material; each
first-install page links to it in one line.

The Home Assistant pages describe the app after
srcfl/home-assistant-addons#56 and #2096: FTW (beta) opens inside
Home Assistant behind its login, port 8080 is closed, entities need no
broker typed, and a stable app named FTW follows the first stable.

The Pi guides in five languages run the line in step 11, show the printed
address and list what the setup page asks. native-beta.md and update-sv.md
change only their install section, the hardware line and the app rows.

scripts/test_install_docs.py now requires the one line, exactly once, on
each page that installs, and no other --fresh-host block in README or
docs/. CI runs it when those pages change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

---------

Signed-off-by: Fredrik Ahlgren <[email protected]>
Co-authored-by: Claude Fable 5.2 <[email protected]>
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