MQTT FLOAT AND PAYLOAD MIXED Help to Config

Hello all,

I have a working Telegraf MQTT configuration.

I have added a Shelly 3PM which passes its data via MQTT in JSON format.

With JSON in Telegraf, I am still new and do not know the syntax.

How can I include the JSON in my existing configuration?

[global_tags]
 user = "${USER}"

[[outputs.influxdb_v2]]
  ## The URLs of the InfluxDB cluster nodes.
  ##
  ## Multiple URLs can be specified for a single cluster, only ONE of the
  ## urls will be written to each interval.
  ## urls exp: http://127.0.0.1:8086
  urls = ["http://2.2.2.2:8086"]

  ## Token for authentication.
  token = "XXXXXXX"

  ## Organization is the name of the organization you wish to write to; must exist.
  organization = "XXXX"

  ## Destination bucket to write into.
  bucket = "VH_Messwerte"


  [[inputs.mqtt_consumer]]
  #
  # MQTT broker URLs to be used. The format is scheme://host:port, schema can be tcp, ssl, or ws.
    servers = ["tcp://1.1.1.1:1883"]
    connection_timeout = "90s"
  #
  # Topics to subscribe to.
   topics = [
      "Energie/#",
      "Heizen/#",
      "PV/#",
      "Umwelt/#",
      "shellypro3em-c8f09e87ad5c/status/em:0#",
      ]
  #

 persistent_session = true
 client_id = "Telegraf_Client"
  # Username and password.
    username = "MQTT"
    password = "password"
  #
  # Needed only if your payload type is string, since Telegraf does not forward data of this type by default.
#    json_string_fields = ["uplink_message_frm_payload"]
  #
  # Define the message format.
  data_format = "value"
  data_type = "float"

[[outputs.file]]
 files = ["stdout"]

Topic: shellypro3em-c8f09e87ad5c/status/em:0

JSON PAYLOAD:

{
"id":0,
"a_current":0.028,
"a_voltage":235.9,
"a_act_power":0.3,
"a_aprt_power":6.5,
"a_pf":1.00,
"b_current":0.215,
"b_voltage":237.6,
"b_act_power":47.2,
"b_aprt_power":51.0,
"b_pf":0.93,
"c_current":0.030,
"c_voltage":236.9,
"c_act_power":1.1,
"c_aprt_power":7.1,
"c_pf":1.00,
"n_current":null,
"total_current":0.273,
"total_act_power":48.584,
"total_aprt_power":64.683, 
"user_calibrated_phase":[],
"errors": ["no_load"]
}

Thank you.

Hi guys,
can anyone help?

I don’t understand the queston.

So, you want to save the field values and every value should be float.

that JSON object is the data that you are recieving? if it is in JSON format, then you need to parse it.

use parse plugin an JSON format. I just added the links to the doc in this thread:

How to make a python plugin that changes incoming data before it’s sent to influxdb - Telegraf - InfluxData Community Forums

@matze1708 Telegraf comes with several data-parsers used to decode the payload from different endpoints. In your case you probably want the JSON parser by specifying

...

[[inputs.mqtt_consumer]]
  ...
  data_format = "json"

...

Hello,
thank you for your answers.

I have attached my current configuration here.

With this configuration, I get no error in the LOG.
But also no content from the JSON into my InfluxDB.

The “old” part still works though.

I have absolutely no idea how to adjust this.

 [[inputs.mqtt_consumer]]
  #
  # MQTT broker URLs to be used. The format is scheme://host:port, schema can be tcp, ssl, or ws.
    servers = ["tcp://10.100.124.24:1883"]
    connection_timeout = "90s"
  #
  # Topics to subscribe to.
   topics = [
      "Energie/#",
      "Heizen/#",
      "PV/#",
      "Umwelt/#",
      ]
  #

 persistent_session = true
 client_id = "Telegraf_Client"
  # Username and password.
    username = "MQTT"
    password = "password"
  #
  # Needed only if your payload type is string, since Telegraf does not forward data of this type by default.
#    json_string_fields = ["uplink_message_frm_payload"]
  #
  # Define the message format.
  data_format = "value"
  data_type = "float"

  [[inputs.mqtt_consumer]]
  #
  # MQTT broker URLs to be used. The format is scheme://host:port, schema can be tcp, ssl, or ws.
    servers = ["tcp://10.100.124.24:1883"]
    connection_timeout = "90s"
 #
  # Topics to subscribe to.
   topics = [
     " shellypro3em-c8f09e87ad5c/status/em:0"
      ]
  #

  persistent_session = true
  client_id = "Telegraf_Client_JSON"
  # Username and password.
    username = "MQTT"
    password = "password"


  data_format = "json_v2"
  [[inputs.mqtt_consumer.topic_parsing]]
    topic = "+/+/+"
    measurement = "_/_/em_id"

   [[inputs.mqtt_consumer.json_v2]]
    [[inputs.mqtt_consumer.json_v2.field]]
        path = "a_voltage"
        rename = "L1 Spannung"
        type = "float"


[[outputs.file]]
 files = ["stdout"]

Did you try

[[inputs.mqtt_consumer]]
  servers = ["tcp://10.100.124.24:1883"]
  connection_timeout = "90s"
  topics = [
    "Energie/#",
    "Heizen/#",
    "PV/#",
    "Umwelt/#",
  ]
  persistent_session = true
  client_id = "Telegraf_Client"
  username = "MQTT"
  password = "password"

  data_format = "json"

[[outputs.file]]
  files = ["stdout"]

with --debug?