Skip to content

MQTT sink with Home Assistant discovery - #5

Closed
ichnograph wants to merge 2 commits into
masterfrom
mqtt-sink
Closed

MQTT sink with Home Assistant discovery#5
ichnograph wants to merge 2 commits into
masterfrom
mqtt-sink

Conversation

@ichnograph

Copy link
Copy Markdown
Contributor

Adds an MQTT sink that makes every source visible in Home Assistant with zero YAML on the HA side.

What it does

  • Publishes each reading as JSON under <TopicPrefix>/<measurement> (duco and solar inverters follow the same per-table split as the database sinks).
  • Announces retained HA discovery configs per meter: one device per meter serial, sensors with correct device_class/state_class/unit. Heat energy is published in kWh alongside GJ so the sensors work in the HA Energy dashboard, as do the gas readings (m3, total_increasing).
  • Availability via a last-will <prefix>/status topic; the broker connection registers as a readiness check; one shared client per process.
  • Config under MQTT (broker URL, credentials, prefix, discovery toggle and prefix, QoS 0/1, retain). Counts toward the at-least-one-sink rule.
  • Docs: full configuration section, topic scheme, a Home Assistant guide with a Mosquitto compose snippet.
  • New dependency: eclipse/paho.mqtt.golang, the standard Go MQTT client.

Bug fix included (first commit)

While aligning units, the QuestDB heat writer turned out to divide power by 1000 and max power by 100, left over from the milliwatt units of the pre-fork M-Bus library. Heat power in QuestDB has been three orders of magnitude too small since the gombus migration; the SQL sinks were already correct. Now fixed; existing QuestDB heat power history will show a step change.

Tested against a recording fake client (golden discovery payloads, retain/QoS, LWT lifecycle, error propagation). Coverage 82.7%, lint 0 issues, race suite green.

The writer divided power by 1000 and max power by 100, assuming the
milliwatt units of the M-Bus library used before the gombus migration.
The domain values have been plain watts since then, so QuestDB heat
power readings were three orders of magnitude off. The other sinks
already stored watts.
Publishes every reading as JSON under a configurable topic prefix and
announces retained Home Assistant discovery configs, so each meter
shows up as a device with typed sensors and the energy and gas
sensors slot into the Energy dashboard without any YAML. Availability
rides a last-will status topic; the broker connection registers as a
health check. One shared client per process, created lazily by the
first enabled sink builder.
@ichnograph

Copy link
Copy Markdown
Contributor Author

Rolled into the 1.4.0 PR.

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