# MQTT to influx - How to translate topics into fields

**URL:** <https://community.influxdata.com/t/mqtt-to-influx-how-to-translate-topics-into-fields/14703>\
**Category:** Telegraf\
**Tags:** telegraf\
**Created:** [June 7, 2020, 10:00am UTC](https://community.influxdata.com/t/mqtt-to-influx-how-to-translate-topics-into-fields/14703 "2020-06-07T10:00:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkeipp](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/dkeipp/32/5084_2.png) [@dkeipp](https://community.influxdata.com/u/dkeipp)\
**Post date:** [June 7, 2020, 10:00am UTC](https://community.influxdata.com/t/mqtt-to-influx-how-to-translate-topics-into-fields/14703/1 "2020-06-07T10:00:55Z")

</div>

Hi,

I get stuck in translating mqtt topics to fields wit telegraf.  
Here I have a example of MQTT topics that I want to translate into corresponding fields

```
MQTT Topics to capture:
t5s/pac/power/all
t5s/pac/power/L1
t5s/pac/power/L2
t5s/pac/power/L3

```

and also the same on t5s/pacws/power/+

```
MQTT subscribtion for this should be:
t5s/+/power/+

```

Tamplate pattern:  
`samplrate.measurement.field.field`

(samplerate should be a tag set, tag\_key=samplerate tag\_value=t5s. Later I want to use this information to select the correct RP)

At the moment I can write some Data into influxdb, but telegraf uses “mqtt\_consumer” as measurement and the whole topic as field.  
I used data\_format = “value” and data\_type = “float” to convert the value, that worked just fine.  
I thought using “templates” wous as easy as converting the value, but it has no effect. Reading the docs again I recognized that templates works only on telegraf metrics (dot delimited).  
So I get stuck at this stage.  
Can someone tell me if this conversion of the topic is possible in anyway with telegraf? or do i need an extra script to do this?

---

<div class="post-metadata">

**Author:** ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)\
**Post date:** [June 8, 2020, 7:20pm UTC](https://community.influxdata.com/t/mqtt-to-influx-how-to-translate-topics-into-fields/14703/2 "2020-06-08T19:20:42Z")

</div>

Hello @dkeipp,  
Welcome!  
Perhaps a look at `# topic_tag = "topic"` option will be useful to you.

> **[telegraf/plugins/inputs/mqtt\_consumer at master · influxdata/telegraf](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/mqtt_consumer)**
>
> master/plugins/inputs/mqtt\_consumer

Maybe this merged PR?

> <https://github.com/influxdata/telegraf/pull/6266>
>
> Add a new option \`topic\_tag\` to the mqtt\_consumer input. When unset the default… is \`topic\` in order to preserve backwards compatibility, when set to \`""\` no topic tag is added, otherwise the value is used for the topic tag. This is the basic pattern I would like to use for all inputs with parsers and want to add metadata.
> 
> In 2.0 we should change the default to not add the topic tag. We don't have a mechanism for changing the defaults yet, this is something that needs a plan.
> 
> closes: #6262
> 
> \### Required for all PRs:
> 
> \- \[x\] Signed \[CLA\](https://influxdata.com/community/cla/).
> \- \[x\] Associated README.md updated.
> \- \[x\] Has appropriate unit tests.

Thank you. Please let me know if that helps.
