Telegraf mqtt output layout = "field" giving errors

Hi experts, please help me with this issue that is driving me nuts:

I have Telegraf configured to read my Modbus meters.
This works fine and I can output to Influx and get great reports.

Now I also want to publish the fields on mqtt, where each field gets its own topic and the tag is used as part of the base topic to indicate from which device the data is (my Solar pannels or Car charger).

My mqtt output section looks like this:

  servers = ["mqtt-test:1883"]
  qos = 2
  client_id = "telegraf-test"
  topic = 'telegraf/modbus/{{ .Tag "topic" }}'
  layout = "field"
  keep_alive = 30

However this gives the error:
Error running agent: Error loading config file /etc/telegraf/telegraf.conf: plugin outputs.mqtt: line 79: configuration specified the fields ["topic" "layout"], but they weren't used

If I reconfigure the mqtt output to not to use the layout=“field” and use JSON for the outputformat, this is the result showing that the output has proper fields and a “topic” tag;

  "fields": {
    "current/l1": 0.03324579447507858,
    "current/l2": 0,
    "current/l3": 0,
    "import": 12024.689453125,
    "power": 0,
    "power/l1": 0,
    "power/l2": 0,
    "power/l3": 0,
    "voltage/l1": 226.8418731689453,
    "voltage/l2": 225.91954040527344,
    "voltage/l3": 225.6832275390625
  "name": "modbus",
  "tags": {
    "topic": "car"
  "timestamp": 1707689620

This is the output from my modbus input in Influx-format:

modbus,topic=car voltage/l1=226.90048217773438,voltage/l2=228.7051239013672,voltage/l3=228.25982666015625,current/l1=0.0351824015378952,current/l2=0,current/l3=0,power/l1=0,power/l2=0,power/l3=0,power=0,import=12024.689453125 1707687980000000000

So, if the output has all the fields and a tag, then why this error?

I have found it!
I was dumb, using an older Docker image version of Telegraf that didn’t have the fields feature yet…
Case closed :wink: