Troubleshooting
Why two Telegraf MQTT inputs share one client ID and disconnect
Short answer
Both [[inputs.mqtt_consumer]] blocks carry client_id = "Telegraf", and the MQTT specification allows only one active connection per client identifier. Each connection displaces the other at the broker, producing the EOF and reconnect loop. Give each block a distinct client_id and leave the parsers and topics alone.

On this page
Both of your [[inputs.mqtt_consumer]] blocks carry client_id = "Telegraf", and that single setting is the fault. The MQTT specification allows only one active connection per client identifier, so each time your second input connects to tcp://myserver:1883 the broker drops the first, which logs connection lost: EOF and reconnects, which drops the second in turn. The result is the alternating error loop you see, roughly ten seconds apart. Give each block its own identifier, for example TelegrafZigbee2MQTT and TelegrafShelly, and both topic families flow to InfluxDB without touching the parsers.
One identifier, one connection #
Each [[inputs.mqtt_consumer]] block opens its own MQTT client connection. Two blocks inside the same Telegraf process, on the same server address, with the same credentials, are still two separate clients from the broker's point of view — nothing merges them into one session. The client identifier is how the broker tells sessions apart, and it is established before any subscription routing, so different topic lists do not prevent the clash. Different usernames and passwords do not prevent it either: two clients with different credentials still disturb each other when they present the same identifier.
Where the disconnect sits in the data path #
The failure point matters because it rules out everything downstream:
- Publisher to broker: both payload families — the JSON sensor topics and the scalar power topic — already arrive at the broker.
- Broker listener: both consumers reach the same plain TCP endpoint,
tcp://myserver:1883. - Consumer connection identity: both blocks claim the identifier
Telegraf, so the connections compete for one session. - Payload parsing:
jsonfor the sensor topics,valuewithfloatfor the power topic — these never run reliably because the connection keeps dying first. - Output to InfluxDB: writes sit downstream of receipt and parsing, so the database is not involved.
Each input working correctly when run alone is the confirming symptom: one connection holding the shared identifier has no rival, so the parsers and the output were never the problem.
Reading the EOF and Connected loop on tcp://myserver:1883 #
Take the timestamps from your own log and measure the cycle.
Inputs: three error lines at 20:36:41, 20:36:50 and 20:37:10, two Connected lines at 20:36:50 and 20:37:00, all from inputs.mqtt_consumer against tcp://myserver:1883, with both blocks set to client_id = "Telegraf".
Rule: the spacing between successive connection lost: EOF lines is the reconnect cycle — the time one input needs to notice it was dropped, reconnect, and displace the other input again.
Arithmetic:
- 20:36:50 − 20:36:41 = 9 s
- 20:37:00 − 20:36:50 = 10 s
- 20:37:10 − 20:37:00 = 10 s
- Mean cycle: (9 + 10 + 10) / 3 = 29 / 3 ≈ 9.7 s
Result: a steady alternation just under ten seconds long, with an immediate Connected after each EOF and no parse errors or write errors anywhere in the log.
Decision: when two inputs on one broker produce that steady few-second EOF-and-reconnect cadence and each input runs cleanly alone, treat it as an identity clash at the broker and compare the client_id of every concurrently connected client before touching any parser. The measured cadence reflects the reconnect timing of your installation; it is not evidence of a configured keepalive interval.
Assign a distinct client ID to each block #
Change only the duplicated identifier. The server address, credentials, topic lists and parsing settings already worked with each input alone, so leave them as they are and the fix has a single, verifiable cause.
- Locate every active
[[inputs.mqtt_consumer]]block, including any the service loads from additional configuration files. - Set
client_id = "TelegrafZigbee2MQTT"on the JSON sensor consumer andclient_id = "TelegrafShelly"on the scalar power consumer. - Check every other running client on that broker — a second Telegraf process, a script, a gateway — for either identifier, and give any other instance its own distinct ID or stop it.
- Keep each block's existing
usernameandpasswordvalues; authentication is not part of the fault. - Reload or restart Telegraf through your service mechanism and confirm two
Connectedlines followed by continuous metrics from both topic families.
The corrected configuration, with credentials omitted here rather than changed:
[[inputs.mqtt_consumer]]
servers = ["tcp://myserver:1883"]
topics = [
"zigbee2mqtt/Sensor1",
"zigbee2mqtt/Sensor2",
"zigbee2mqtt/Sensor3"
]
client_id = "TelegrafZigbee2MQTT"
data_format = "json"
[[inputs.mqtt_consumer]]
servers = ["tcp://myserver:1883"]
topics = ["shellies/shellyem-XXXXXXXXXXXX/emeter/0/power"]
client_id = "TelegrafShelly"
data_format = "value"
data_type = "float"
The XXXXXXXXXXXX portion stands for the device-specific part of the topic as your configuration holds it; subscribe with the exact topic the installed device publishes. The alternative json_v2 parser, with its explicit object and tag selection, is a choice about payload structure, not a connection repair — the fix above needs no parser change.
Keep each parser matched to its topic family #
With both connections stable, the data_format of each block decides how its subscribed payloads are read. Keeping the topic families in separate blocks is what makes two formats coexist at all.
| Consumer | Subscribed topics | Parser settings | Payload check |
|---|---|---|---|
| JSON sensors | zigbee2mqtt/Sensor1, zigbee2mqtt/Sensor2, zigbee2mqtt/Sensor3 |
data_format = "json" |
One message per topic is valid JSON with the expected fields |
| Power measurement | shellies/shellyem-XXXXXXXXXXXX/emeter/0/power |
data_format = "value", data_type = "float" |
The payload is a numeric scalar the float parser accepts |
A scalar power message reaching a JSON parser, or a JSON object reaching the scalar float parser, fails on every message — so never merge the two topic families into one block. If a connection is healthy but one input still yields nothing, the subscription itself is the suspect; the same reasoning applies when the MQTT consumer connects but writes no data to InfluxDB.
When EOF continues after the change #
EOF only means the client hit the end of the connection stream; it names the loss, not the cause. If the loop survives distinct identifiers, work through these in order:
- Recheck the whole broker, not just Telegraf. Any client anywhere presenting one of your two identifiers — an old test script, a backup instance, another edge box — reproduces the same takeover.
- Confirm the log source. With both inputs writing
EOFlines, theinputs.mqtt_consumerlabel alone does not say which block is failing; the metric names each block produces do. - Rule out the older reconnection defect. Some Telegraf releases had a separate bug where the MQTT consumer handled reconnection itself inside its gather routine and conflicted with the underlying client library's internal state, causing repeated disconnects even with unique identifiers; if your build predates that fix, update Telegraf.
- Check the network path last. A flaky link between the edge PC and the broker drops both inputs at the same instant and at irregular intervals, which does not match the steady alternating pattern the identifier clash produces.
With distinct client IDs on every concurrent client and a current Telegraf build, both the JSON sensors and the scalar power measurement stay connected and reach InfluxDB together.
Questions asked
Does a Telegraf plugin alias replace the MQTT client_id?
No. The alias names the plugin instance inside Telegraf and prefixes its measurements, but the broker identifies a session only by the MQTT client identifier the plugin sends. Two aliased blocks that still share client_id = "Telegraf" keep displacing each other exactly as before.
Why did queued messages stop arriving after I changed the client_id?
A new client_id is a new session identity at the broker. Persistent sessions and messages queued for the old identifier do not follow the new one, so a device that relied on queued delivery while Telegraf was offline loses that backlog once. Set the new identifiers once and keep them stable across ordinary restarts instead of changing them as a recurring workaround.
Do I need the json_v2 data format to run two MQTT consumers?
No. Multiple mqtt_consumer blocks coexist in one Telegraf configuration with either JSON parser. The json_v2 format exists for payloads that need explicit object selection and tag extraction, which is a payload-structure decision, not a connection repair. Fix the duplicated identifier first and change the parser only if the JSON structure demands it.
Both inputs show Connected but one produces no measurements. What now?
Check the subscribed topic string character by character against what the device actually publishes, and inspect one live payload from that topic for the fields the parser expects. A mistyped topic leaves a healthy connection that simply never receives a message, which is a subscription problem, not the alternating-disconnect pattern described here.


