Explainer
Why Telegraf writes MQTT float values into the string measurement
Short answer
MQTT payloads are untyped bytes and the broker routes on the topic alone, so two mqtt_consumer instances on the same filter each receive every message. Numeric text parses both as a float and as a string, which puts every float into the string measurement; status text fails the float parse and appears only as a string. Make the two topic filters mutually exclusive, or publish Line Protocol and parse it with one consumer set to the influx data format.
On this page
Both of your mqtt_consumer instances subscribe to mydevice/#, and an MQTT payload is an untyped byte sequence: the broker routes on the topic alone, so every publication is delivered once to each subscription. Numeric text such as 23.7 is valid as a float and as a string, so the float parser stores a number in mqtt_consumer while the string parser stores the same digits as text in mqtt_consumer_string — that is the duplicate. A status word fails the float parse, is logged and dropped, so status topics appear only in the string measurement. The fix is to make the two topic filters mutually exclusive, or to publish Line Protocol and parse it with a single consumer set to data_format = "influx".
One message, two parsers, two measurements #
The MQTT specification keeps the payload opaque to the broker: matching is a topic-filter comparison, and every subscription whose filter matches receives its own copy. Two instances on the same filter therefore mean two deliveries by design, not a resend.
[[inputs.mqtt_consumer]]
servers = ["mosquitto:1883"]
qos = 0
topics = ["mydevice/#"]
data_format = "value"
data_type = "float"
[[inputs.mqtt_consumer]]
name_override = "mqtt_consumer_string"
servers = ["mosquitto:1883"]
qos = 0
topics = ["mydevice/#"]
data_format = "value"
data_type = "string"
Each instance parses its copy independently. With the value data format, the parsed scalar lands in a field named value, the topic is kept as a tag, and the measurement takes the plugin name unless name_override replaces it — the same mapping described in turn an MQTT topic into InfluxDB fields with Telegraf. If both measurements come up empty instead of duplicated, the fault sits earlier in the pipeline; Telegraf MQTT consumer connects but writes no data to InfluxDB covers that case.
Why numeric text passes both parsers #
The float parser accepts a payload that is a number — sign, digits, decimal point, exponent — and rejects everything else. The string parser accepts everything: any byte sequence is a valid string. Numeric text therefore passes both.
| Payload | Float instance | String instance | Stored result |
|---|---|---|---|
23.7 on a numeric topic |
parses as float | parses as text | twice, once per measurement |
run on a status topic |
parse error, dropped | parses as text | once, string only |
Two consequences follow. Status strings never reach mqtt_consumer because each one produces a parse error in the float instance's log — those error lines confirm the diagnosis. And a digit-only status code, such as 12 meaning idle, passes the float parser too: a type decision based on how a payload looks is wrong by construction. The type has to be owned by the topic contract or by a structured payload.
What the overlap costs #
Take an example plant with 8 numeric topics and 4 status topics under one branch, each publishing one message every 10 s, and both consumers on the shared filter:
- Broker deliveries: 12 topics × 2 subscriptions = 24 messages per 10 s.
- Stored by the float instance: 8 points per 10 s; the 4 status messages are dropped with parse errors.
- Stored by the string instance: 12 points per 10 s.
- Total: 8 + 12 = 20 points per 10 s where 12 are needed — 8 redundant, and 8 ÷ 12 ≈ 0.67, about 67 % more rows. Every numeric topic also exists as two series.
The redundant share is numeric topics ÷ all topics, so it climbs toward 100 % as numeric topics dominate, which is the typical plant. Over one day that is 8,640 ten-second windows × 20 = 172,800 rows instead of 8,640 × 12 = 103,680. The string copy also breaks analysis: a mean over the text field fails, and a dashboard pointed at the wrong measurement shows a value that will not aggregate.
Fix one: mutually exclusive topic filters #
Two value consumers are fine; two value consumers on one filter are not. Split by topic so each parser sees only its own type. If the publisher can change its paths, publish numbers under one branch and status under another, for example mydevice/value/# and mydevice/status/# — a wildcard selects a branch and cannot test payload type. If the paths are frozen, enumerate the topics per instance from a topic inventory and keep the two lists apart.
[[inputs.mqtt_consumer]]
servers = ["mosquitto:1883"]
qos = 0
topics = ["mydevice/value/#"]
data_format = "value"
data_type = "float"
[[inputs.mqtt_consumer]]
name_override = "mqtt_consumer_string"
servers = ["mosquitto:1883"]
qos = 0
topics = ["mydevice/status/#"]
data_format = "value"
data_type = "string"
Cross-check both filters against both groups before deployment: one leftover broad subscription on either instance recreates the overlap exactly. Keep name_override = "mqtt_consumer_string" on the string instance in this pattern — not because two instances need distinct names, but because both write a field named value, and InfluxDB holds one type per field per shard, so float and string in a single value field would collide as field type conflicts. The override keeps the two types in separate measurements.
Fix two: Line Protocol and a single consumer #
If the publisher and its subscribers can take a structured payload, publish Line Protocol and run one consumer:
[[inputs.mqtt_consumer]]
servers = ["mosquitto:1883"]
qos = 0
topics = ["mydevice/#"]
data_format = "influx"
The message then declares its measurement, tags and typed fields:
press,cell=2 force=4.6
press,cell=2 state="run"
An unquoted numeric literal is a float field; a quoted literal is a string field. One message gets exactly one parse, so the overlap cannot arise, and numeric and status data can share a measurement under distinct field names.
Two rules for this pattern. Remove name_override, because it replaces the measurement name on every metric the instance emits, including the one parsed from the payload — which is why a test with the override still in place saw everything collapse into mqtt_consumer. And do not re-add it to separate instances: multiple instances of one input coexist without distinct measurement names, and renaming the measurement is the only thing the override does. The cost sits at the publisher: a mobile app or websocket client subscribed to the same topics now receives a structured line instead of a bare scalar.
Why all-strings is not the answer #
Collecting everything as strings removes the parse errors and keeps a single consumer, but a number stored as text stays text in InfluxDB. Aggregations that only compare values — count, mode — still run; anything that computes — mean, rate, sums — fails on the field. Every dashboard, alert and report needing the number must convert it first, and one forgotten conversion reproduces the original problem in a worse place. The type boundary belongs in the publisher's topic contract or payload, not in every query.
The decision #
- Publisher can change topic paths: split numeric and status into separate branches and point one float consumer and one string consumer at them, keeping the override on the string instance. This is the default choice, because every other subscriber keeps its bare scalar values.
- Publisher and subscribers can take structured payloads: Line Protocol with one
data_format = "influx"consumer and no measurement override. - Topic paths frozen with mixed types inside one branch: explicit, mutually exclusive topic lists per instance, maintained with the device inventory.
- Reject the all-strings shortcut: the conversion debt lands in every query.
- Never leave two fixed-type consumers on one shared filter — the duplication is structural and applies to every numeric message.
Questions asked
Does MQTT have a payload type field that Telegraf could use?
MQTT 3.1.1 messages carry only a topic and opaque bytes, so nothing in the message says float or string. MQTT 5 added optional per-message properties, a payload format indicator and a content type, but Telegraf's value parser applies the single data_type configured on the instance to every message it receives. Those properties do not remove the need for exclusive topic filters or a structured payload.
Would a higher qos stop the double delivery?
No. Each matching subscription gets its own delivery, and qos only sets the guarantee for that single delivery. At qos 1 or 2 a broker may redeliver after a reconnect, which can add same-type duplicates inside one measurement. It never routes a message to only one of two matching consumers, so changing it cannot fix the overlap.
Can the string copies be converted back to numbers after storage?
InfluxQL has no cast, so with the 1.x query language the conversion has to run in a Kapacitor TICKscript or a Telegraf processor. Newer query languages and dashboard transformations can convert a text column, but every panel, alert and report must repeat that conversion, and a single missed one reproduces the failure. Fix the type boundary instead.
How do I prove the duplicate comes from the two parsers and not a broker resend?
Compare field types in the database schema: the same topic and timestamp stored as a float in one measurement and as a string in the other proves two parsers ran on one delivery. A broker resend would repeat the same type inside one measurement. The cross-measurement pair, not a repeat, is the signature of the shared filter.