Telegraf: drop complete lines to insert when a value is 0 from MQTT in Json

Im sending data over mqtt, telegraf, influx grafana.

When 1 the “power0” field is 0, there is no need to store in the database for some devices.
For some others I need also the 0 values, otherwise the “mean” values are wrongly calculated in grafana.

I can use 2 different scripts, no issue, but i don’t know exactly how to use the starlark to drop the input.
This is my current telegraf config for devices storing all values.

[[inputs.mqtt_consumer]]
  servers = ["tcp://127.0.0.1:1883"]
  topics = [
	"EM/pw0",
	]
  username = "M"
  password = "M"
  data_format = "json_v2"

 [[inputs.mqtt_consumer.topic_parsing]]
    topic = "EM/pw1"

  [[inputs.mqtt_consumer.json_v2]]
        timestamp_path = "epoch"
      	timestamp_format = "unix"
	measurement_name = "Power1"
      [[inputs.mqtt_consumer.json_v2.tag]]
        path = "id"
        type = "string"
      [[inputs.mqtt_consumer.json_v2.field]]
        path = "power0"
        type = "float"

It is helpful to show what you have tried :wink: Essentially if that value is 0, then you can either drop that field, or remove the entire metric.

If you want to drop the entire metric, then I would suggest using the metricpass config option as it will be faster than starlark and let you have some logic around what metrics get by.

metricpass works like a charm for me!! Many thanks!!