Skip to content

fix(telegraf): keep full decision text in sample config - #449

Merged
MaStr merged 2 commits into
mainfrom
copilot/bugfix-telegraf-decision-truncated
Oct 9, 2026
Merged

MaStr merged 2 commits into
mainfrom
copilot/bugfix-telegraf-decision-truncated

Conversation

@MaStr

@MaStr MaStr commented Oct 8, 2026

Copy link
Copy Markdown
Owner

Problem

The new /decision topic arrived in InfluxDB as a single word. The topic was consumed by the catch-all house/batcontrol/+ input, which uses data_format = "value". Telegraf's value parser splits the payload on whitespace and keeps only the last token:

batcontrol,topic=house/batcontrol/decision decision="reserve"

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] with pivot_field = ["decision"] on the catch-all input, so the truncated field is never produced.
  • A dedicated consumer for house/batcontrol/decision using the grok parser (%{GREEDYDATA:decision}), which takes the payload as a whole. Measurement: batcontrol-decision.
  • A commented-out json_v2 consumer for /decision/attributes, which exposes the stable reason code as a tag and mode as an int field - more useful for Grafana than the free text. optional = true because decided_by is null until the first decision with a decisive step.

Verification

telegraf 1.31 against a local mosquitto, file output:

batcontrol-decision,topic=house/batcontrol/decision decision="Charge from Grid 1250 W - usable energy (900 Wh) is below the 2500 Wh reserved for upcoming expensive hours"
batcontrol,topic=house/batcontrol/SOC SOC=42.5
batcontrol,topic=house/batcontrol/control_source control_source="optimizer"

Full sentence, written once, no truncated duplicate, other topics unchanged. The config loads without unknown-option warnings (all 4 consumers).

Notes

  • Single-word string topics such as control_source keep working through the value parser; decision was the only multi-word payload. Future free-text topics need the same treatment.
  • Grafana panels pointing at batcontrol.decision have to be switched to the batcontrol-decision measurement.
  • Sample-config only, no code change, so no test is added. There is no docs/ page covering the Telegraf/InfluxDB setup today - happy to add one as a follow-up.

🤖 Generated with Claude Code

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>
Copilot AI balanced review requested due to automatic review settings October 8, 2026 19:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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] with pivot_field = ["decision"] to the catch-all consumer so the truncated decision field is never emitted.
  • Add a dedicated mqtt_consumer for house/batcontrol/decision using the grok parser (%{GREEDYDATA:decision}), writing to measurement batcontrol-decision.
  • Add a commented-out json_v2 consumer for /decision/attributes exposing reason as a tag and mode as 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.

Comment thread config/telegraf.sample.conf Outdated
Clarify optional fields in configuration comments.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 9, 2026 05:54
@MaStr
MaStr merged commit 2c2dda0 into main Oct 9, 2026
11 checks passed
@MaStr
MaStr deleted the copilot/bugfix-telegraf-decision-truncated branch October 9, 2026 05:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

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.

2 participants