I don’t know what to try with mqtt_consumer and tasmotta

Hi,
I’ve been trying to understand telegraf and mqtt_consumer for several hours now and I don’t know what to try.
TASMOTA sends these frames Mqtt to mosquitto:
23:28:00.981 MQT: teleinfo/tele/SENSOR = {“Time”:“2023-08-13T23:28:00”,“ENERGY”:{“TotalStartTime”:“1970-01-01T00:00:00”,“Total”:41049.000,“Yesterday”:0.000,“Today”:17.434,“Period”:0,“Power”:2483,“ApparentPower”:2855,“ReactivePower”:1409,“Factor”:0.87,“Voltage”:236,“Current”:12.097},“IP”:“192.168.1.110”,“Net”:“Wifi”,“Wifi-mac”:“08:3A:F2:59:2D:F4”,“Eth-mac”:“00:00:00:00:00:00”}
23:28:01.124 MQT: teleinfo/tele/SENSOR = {“Time”:“2023-08-13T23:28:01”,“METER”:{“PH”:1,“ISUB”:30,“PSUB”:6000,“PMAX”:6000,“U1”:236,“P1”:2855,“W1”:2483,“I1”:12.0,“C1”:null}}
23:28:01.379 MQT: teleinfo/tele/SENSOR = {“Time”:“2023-08-13T23:28:01”,“TIC”:{“ADSC”:“021861892978”,“VTIC”:“02”,“DATE”:“E230813232809”,“NGTF”:“H PLEINE/CREUSE”,“LTARF”:“HEURE CREUSE”,“EAST”:“041049002”,“EASF01”:“023019543”,“EASF02”:“018029459”,“EASF03”:“000000000”,“EASF04”:“000000000”,“EASF05”:“000000000”,“EASF06”:“000000000”,“EASF07”:“000000000”,“EASF08”:“000000000”,“EASF09”:“000000000”,“EASF10”:“000000000”,“EASD01”:“018168115”,“EASD02”:“014951121”,“EASD03”:“004851426”,“EASD04”:“003078339”,“IRMS1”:“012”,“URMS1”:“236”,“PREF”:“06”,“PCOUP”:“06”,“SINSTS”:“02855”,“SMAXSN”:“E230813131655 04520”,“SMAXSN-1”:“E230807222245 06550”,“CCASN”:“E230813230000 02888”,“CCASN-1”:“E230813223000 02364”,“UMOY1”:“E230813232000 235”,“STGE”:“003A0000”,“MSG1”:“PAS DE MESSAGE”,“PRM”:“02371924724278”,“RELAIS”:“001”,“NTARF”:“01”,“NJOURF”:“00”,“NJOURF+1”:“00”,“PJOURF+1”:“0000C001 06068002 1606C001 NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUT”}}

I want to send in Influxdb 1.8 the data transmitted by the “TIC” object either as a string like “DATE”, “VTIC”, “NGTF”, “LTARF”,…
either as an integer such as “EAST”, “EASF01”, “EASF02”, “EASD01”, “EASD02”, …
and ignore “EASF03”, “EASF04”…

currently, in telegraf.conf I added

[[inputs.mqtt_consumer]]

The IP address of your MQTT broker.

servers = [“tcp://192.168.X.X:1883”]
topics = [
“teleinfo/tele/SENSOR”
]

data_format = “json_v2”
[[inputs.mqtt_consumer.json_v2]]
measurement_name = “tasmota”
timestamp_path = “Time”
timestamp_format = “2006-01-02T15:04:05”
[[inputs.mqtt_consumer.json_v2.object]]
path = “TIC”

and I find in influxdb 1.8

select * from tasmota WHERE time >= ‘2023-08-13T23:45:00Z’
name: tasmota
time ADSC CCASN CCASN-1 DATE EASD01 EASD02 EASD03 EASD04 EASF01 EASF02 EASF03 EASF04 EASF05 EASF06 EASF07 EASF08 EASF09 EASF10 EAST IRMS1 LTARF MSG1 NGTF NJOURF NJOURF+1 NTARF PCOUP PJOURF+1 PREF PRM RELAIS SINSTS SMAXSN SMAXSN-1 STGE UMOY1 URMS1 VTIC host topic


2023-08-13T23:45:01Z 021861892978 E230813233000 02878 E230813230000 02888 E230813234509 018168394 014951121 004851426 003078339 023019821 018029459 000000000 000000000 000000000 000000000 000000000 000000000 000000000 000000000 041049280 002 HEURE CREUSE PAS DE MESSAGE H PLEINE/CREUSE 00 00 01 06 0000C001 06068002 1606C001 NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUT 06 02371924724278 001 00457 E230813131655 04520 E230807222245 06550 003A0000 E230813234000 238 240 02 iotstack teleinfo/tele/SENSOR

Who can help me improve my telegraf.conf ?

The difficulty here is that you get three different message formats in one topic. The config below should work:

[[inputs.mqtt_consumer]]
  ...

  data_format = "xpath_json"

  xpath_allow_empty_selection = true
  xpath_native_types = true

  # Configuration matching the first (ENERGY) message
  [[inputs.mqtt_consumer.xpath]]
    metric_name = "'energy'"
    metric_selection = "//ENERGY"
    timestamp = "/Time"
    timestamp_format = "2006-01-02T15:04:05"
    field_selection = "*"

    [inputs.mqtt_consumer.xpath.fields]
        ip = "/IP"
        net = "/Net"
        wifi_mac = "/Wifi-mac"
        eth_mac= "/Eth-mac"

  # Configuration matching the second (METER) message
  [inputs.mqtt_consumer.xpath]]
    metric_name = "'meter'"
    metric_selection = "//METER"
    timestamp = "/Time"
    timestamp_format = "2006-01-02T15:04:05"
    field_selection = "*"

  # Configuration matching the last (TIC) message
  [[inputs.mqtt_consumer.xpath]]
    metric_name = "'tic'"
    metric_selection = "//TIC"
    timestamp = "/Time"
    timestamp_format = "2006-01-02T15:04:05"
    field_selection = "*"

This will generate the metrics

> energy,host=Hugin ApparentPower=2855,Current=12.097,Factor=0.87,Period=0,Power=2483,ReactivePower=1409,Today=17.434,Total=41049,TotalStartTime="1970-01-01T00:00:00",Voltage=236,Yesterday=0,eth_mac="00:00:00:00:00:00",ip="192.168.1
> meter,host=Hugin I1=12,ISUB=30,P1=2855,PH=1,PMAX=6000,PSUB=6000,U1=236,W1=2483 1691969281000000000
> tic,host=Hugin ADSC="021861892978",CCASN="E230813230000 02888",CCASN-1="E230813223000 02364",DATE="E230813232809",EASD01="018168115",EASD02="014951121",EASD03="004851426",EASD04="003078339",EASF01="023019543",EASF02="018029459",EASF03="000000000",EASF04="000000000",EASF05="000000000",EASF06="000000000",EASF07="000000000",EASF08="000000000",EASF09="000000000",EASF10="000000000",EAST="041049002",IRMS1="012",LTARF="HEURE CREUSE",MSG1="PAS DE MESSAGE",NGTF="H PLEINE/CREUSE",NJOURF="00",NJOURF+1="00",NTARF="01",PCOUP="06",PJOURF+1="0000C001 06068002 1606C001 NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUT",PREF="06",PRM="02371924724278",RELAIS="001",SINSTS="02855",SMAXSN="E230813131655 04520",SMAXSN-1="E230807222245 06550",STGE="003A0000",UMOY1="E230813232000 235",URMS1="236",VTIC="02" 1691969281000000000

for the example-data you provided… Is this what you are looking for?

1 Like