How to use the tagdrop filter to exclude a particular topic

I have been struggling with this for a couple of days without success.

I have a device which generates following MQTT topics:

<devcename>/voltage/get <integervalue>
<devcename>/current/get <integervalue>

and so on
but with one exception
<devcename>/energycounter_clear_date/get <string>

I have configured mqtt_consumer plugin to process only float values:

   topics = [ "+/+/get" ]
  data_format = "value"
  data_type = "float"

When tested I get the following error due to the string value in the payload
2023-01-22T16:59:12Z E! [inputs.mqtt_consumer] Error in plugin: strconv.ParseFloat: parsing "10:48:31": invalid syntax

I tried adding the following directive for tagdrop but the error is still encountered:

[inputs.mqtt_consumer.tagdrop]
#topic = ["*energycounter_last_hour*"]
topic = ["*energycounter_clear_date*"]

The above filtering works fine for messages which contain the float values.
However I am unable to filter the odd one out which contains the string payload.

My conlusion is that the error is hit before coming to this part of the configuration.

Can anybody suggest to me on how to exclude following topic:

<devcename>/energycounter_clear_date/get <string>

I’d say keep the value as string and filter the metrics with tagdrop as you’ve already tried ([inputs.mqtt_consumer.tagdrop])

Then apply the processor converter to cast the datatype to float. If you have multiple inputs you may want to add tagpass (or whatever selectors you find appropriate) in order to apply the cast only to those data

Thanks Giovanni_Luisotto!

I managed get it working following way as you have suggested:

[[inputs.mqtt_consumer]]

  topics = [ "+/+/get" ]
  data_format = "value"
  data_type = "string"
[inputs.mqtt_consumer.tagdrop]
topic = ["*energycounter_clear_date*"]
[[inputs.mqtt_consumer.topic_parsing]]
        topic = "+/+/get"
        # the field label will be picked up here "new_field"
        tags = "site/new_field/_"
[[processors.pivot]]
    # value=xxxx becomes new_field=xxxx.
    tag_key = "new_field"
    value_key = "value"
# # Convert values to another metric value type
[[processors.converter]]

#   ## Fields to convert
#   ##
#   ## The table key determines the target type, and the array of key-values
#   ## select the keys to convert.  The array may contain globs.
#   ##   <target-type> = [<field-key>...]
   [processors.converter.fields]
#     tag = []
#     string = []
#     integer = []
#     unsigned = []
#     boolean = []
#  use glob * to catch all field names
     float = ["*"]
1 Like

Well I thought that I got it right but not quite:

How do you setup the

[[processors.converter]]

to operate within the context of a particular instance of mqtt_consumer plugin?

Can a name_override be applied like below?

[[processors.converter]]
        name_override = "plug"

You should be able to use any selector (name_override, tagdrop, tagpass, etc) in there