feat: add Home Assistant MQTT Discovery integration - #26
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Build commands
```bash
Device
cargo run --release --features home-assistant
make flash-ha
Simulator
cargo simha
make sim-ha
```
Test plan