Repository navigation
fix(telegraf): keep full decision text in sample config - #449
Conversation
The /decision topic was consumed by the catch-all "house/batcontrol/+"
input, which uses the "value" parser. That parser splits the payload on
whitespace and keeps only the last token, so a decision such as
"Charge from Grid 1250 W - usable energy is below the reserve" reached
InfluxDB as decision="reserve". The MQTT payload itself is correct (other
consumers such as iobroker show the full line).
Drop the decision topic from the catch-all input via tagdrop and add a
dedicated consumer that parses it with grok (%{GREEDYDATA}), so the whole
sentence is stored as measurement batcontrol-decision. Also add a
commented-out json_v2 consumer for /decision/attributes, which exposes the
stable reason code as a tag and the mode as an int field.
Verified against telegraf 1.31 with a local mosquitto: the full sentence is
written once, no truncated duplicate, other topics unchanged.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
There was a problem hiding this comment.
🔵 Needs a closer look
Correctness depends on Telegraf runtime parser semantics (grok/tagdrop/json_v2) that cannot be executed and verified here, and it introduces a downstream Grafana measurement rename that warrants human confirmation.
1 open finding
What changed in this PR
This PR fixes a data-truncation problem in the sample Telegraf config. The catch-all house/batcontrol/+ MQTT consumer uses Telegraf's value parser, which keeps only the last whitespace-separated token of a payload. The new /decision topic publishes a full sentence, so it was being stored in InfluxDB as a single word. The change routes the /decision payload through a dedicated grok consumer so the full text is preserved, and suppresses the truncated duplicate from the catch-all consumer. This is a sample-config-only change and aligns the ingestion path with the retained Decision sensor topics published by mqtt_api.publish_status_change().
Changes:
- Add a
[inputs.mqtt_consumer.tagdrop]withpivot_field = ["decision"]to the catch-all consumer so the truncateddecisionfield is never emitted. - Add a dedicated
mqtt_consumerforhouse/batcontrol/decisionusing the grok parser (%{GREEDYDATA:decision}), writing to measurementbatcontrol-decision. - Add a commented-out
json_v2consumer for/decision/attributesexposingreasonas a tag andmodeas an int field.
| File | Description |
|---|---|
| config/telegraf.sample.conf | Drops the truncated decision field from the value-parser consumer, adds a grok consumer for the full decision text, and provides an optional json_v2 consumer for the machine-readable attributes. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Clarify optional fields in configuration comments. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
It is a low-risk, well-verified sample-config change whose Telegraf parser paths and topic handling correctly match the actual MQTT decision payload structure with no code impact.
0 open findings
1 resolved since last review
🧠 Review effort: Balanced

Problem
The new
/decisiontopic arrived in InfluxDB as a single word. The topic was consumed by the catch-allhouse/batcontrol/+input, which usesdata_format = "value". Telegraf's value parser splits the payload on whitespace and keeps only the last token:The MQTT payload itself is fine - other consumers (iobroker) show the full line, so
mqtt_api.publish_status_change()is not involved.Fix
[inputs.mqtt_consumer.tagdrop]withpivot_field = ["decision"]on the catch-all input, so the truncated field is never produced.house/batcontrol/decisionusing the grok parser (%{GREEDYDATA:decision}), which takes the payload as a whole. Measurement:batcontrol-decision.json_v2consumer for/decision/attributes, which exposes the stablereasoncode as a tag andmodeas an int field - more useful for Grafana than the free text.optional = truebecausedecided_byisnulluntil the first decision with a decisive step.Verification
telegraf 1.31 against a local mosquitto, file output:
Full sentence, written once, no truncated duplicate, other topics unchanged. The config loads without unknown-option warnings (all 4 consumers).
Notes
control_sourcekeep working through the value parser;decisionwas the only multi-word payload. Future free-text topics need the same treatment.batcontrol.decisionhave to be switched to thebatcontrol-decisionmeasurement.docs/page covering the Telegraf/InfluxDB setup today - happy to add one as a follow-up.🤖 Generated with Claude Code