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.

  servers = ["tcp://"]
  topics = [
  username = "M"
  password = "M"
  data_format = "json_v2"

    topic = "EM/pw1"

        timestamp_path = "epoch"
      	timestamp_format = "unix"
	measurement_name = "Power1"
        path = "id"
        type = "string"
        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!!