Skip to content

feat: add Home Assistant MQTT Discovery integration - #26

Merged
ololonly merged 8 commits into
mainfrom
feat/home-assistant-direct
Jun 8, 2026
Merged

feat: add Home Assistant MQTT Discovery integration#26
ololonly merged 8 commits into
mainfrom
feat/home-assistant-direct

Conversation

@ololonly

@ololonly ololonly commented Jun 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds `--features home-assistant` Cargo feature that enables direct HA MQTT Discovery publishing from the ESP32 — no Node-RED or any other bridge required
  • On MQTT connect the firmware publishes retained discovery configs; state updates flow at ~1 Hz alongside existing `mara/*` topics
  • Cup counter stays HA-managed; `docs/ha-automation.yaml` replaces the old Node-RED automation with a copy-paste HA automation YAML
  • Removes `docs/node-red-ha-bridge.json`

Build commands

```bash

Device

cargo run --release --features home-assistant
make flash-ha

Simulator

cargo simha
make sim-ha
```

Test plan

  • `cargo test --no-default-features --features simulator` — 35 tests pass
  • `cargo test --no-default-features --features simulator,home-assistant` — 35 tests pass
  • `cargo simha` launches simulator; on MQTT connect, `mosquitto_sub -t 'homeassistant/#' -v` shows retained discovery configs
  • Press Up (pump on) → `homeassistant/sensor/maratui_extraction_timer/state` increments each second
  • Press Down (pump off) → `homeassistant/sensor/maratui_last_extraction_duration/state` retained message published
  • `cargo sim` (without feature) still works normally — no HA traffic

ololonly added 8 commits June 3, 2026 13:09
Adds a new `home-assistant` Cargo feature that enables direct HA MQTT
Discovery publishing from the ESP32 — no Node-RED bridge required.

On every MQTT connect the firmware publishes retained discovery configs
to `homeassistant/{sensor,binary_sensor}/maratui_*/config`, then streams
state updates alongside the existing `mara/*` topics at ~1 Hz.

Changes:
- New `src/home_assistant.rs` module: enqueues discovery configs on
  connect, telemetry states per frame, event-derived states, and status
  states from DeviceInfo
- `MqttOutboundMessage` gains `retain` and `absolute` flags; publish
  functions in setup.rs / setup_simulator.rs handle retained and
  absolute-topic messages
- `GlobalAppState` gets `last_shot_ended_at` for the time-since-last-shot
  sensor; FSM sets it on ShotEnded / ShotAborted
- `app.rs`: `take_outbound_mqtt_messages` now returns the full struct
  instead of tuples; trait gains `enqueue_home_assistant`
- Build commands: `cargo run --release --features home-assistant`,
  `cargo simha`, `make flash-ha / sim-ha`
- Removes `docs/node-red-ha-bridge.json`
- Adds `docs/ha-automation.yaml` (cup counter HA automation, replaces
  the Node-RED automation)
- Updates `docs/home-assistant.md` for the new direct approach
State updates now publish to `{prefix}/ha/{id}` (e.g. `mara/ha/mode`,
`mara/ha/boiler_now`) instead of `homeassistant/sensor/maratui_*/state`.
Discovery configs are unchanged — `homeassistant/*/config` still points
to the correct state_topic, now under the device prefix.

Adds `GlobalAppState::mqtt_topic_prefix` (set on init from AppConfig) so
state-publishing functions have access to the prefix without needing it
passed as a parameter at every call site.
…or|binary_sensor/maratui/

Instead of a flat maratui_{id}/state per sensor, state topics are now
grouped under a shared device subtopic:
  homeassistant/sensor/maratui/{id}
  homeassistant/binary_sensor/maratui/{id}

Discovery config topics (homeassistant/sensor/maratui_{id}/config) are
unchanged.
…nfig topics

Change config topic format from homeassistant/sensor/maratui_{id}/config
to homeassistant/sensor/maratui/{id}/config (4-segment HA Discovery form).

Now config and state share the same base path:
  homeassistant/sensor/maratui/mode/config  <- discovery
  homeassistant/sensor/maratui/mode         <- state
Update documentation to explain how to enable native Home Assistant
integration using the `--features home-assistant` build flag. This
allows the firmware to publish discovery configurations directly,
eliminating the need for a Node-RED bridge.
Add a note regarding MQTT broker requirements and Home Assistant
configuration steps to ensure successful discovery.
@ololonly
ololonly merged commit c2fb09a into main Jun 8, 2026
3 checks passed
@ololonly
ololonly deleted the feat/home-assistant-direct branch June 18, 2026 11:09
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