Tasmota MQTT with InfluxDB

How to configure Telegraf to collect MQTT Tasmota messages

Posted by Greg Stephens on January 13, 2022 · 3 mins read

InfluxDB is an ideal time-series database to collect MQTT metrics. In this post I’ll show how to configure collection of MQTT metrics from Tasmota devices.

Telegraf is a general purpose collection agent that can send metrics to InfluxDB. It includes an mqtt_consumer and a recently enhanced json parser that makes collection of MQTT even easier. To use these features, you’ll need to be on Telegraf 1.21.x or later.

Tasmota Collection

I’m going to use the Tasamota MQTT SENSOR event for this example configuration.

Tasmota SENSOR events use a topic format of tele/%topic%/SENSOR. My devices are configured with a topic of tele/site/room/sensor and I have some BME280, CCS811 and SDS01 sensors that I’ll use in this example. Here’s some example json from my sensors:


Telegraf Config

Here’s the telegraf.conf config that is working for me. Note, that I’m parsing out the MQTT topic to set tags. You can read more about how this configuration works in Telegraf mqtt_consumer blog post and their json_v2 blog post.

  client_id = "telegraf"
  username = "myuser"
  password = "mypass"
  data_format = "json_v2"
  servers = [ "tcp://vernemq.mqtt:1883" ]
  topics = [ "tele/+/+/+/SENSOR" ]

    measurement_name = "tasmota"

      topic = "tele/+/+/+/SENSOR"
      tags = "_/site/room/sensor/_"

    path = "TempUnit"
    path = "PressureUnit"

    path = "@this"
    disable_prepend_keys = true
    type = "float"
    excluded_keys = ["Time","TempUnit","PressureUnit"]

      path = "eCO2"
      type = "int"
      path = "TVOC"
      type = "int"

You can test the configuration file:

telegraf --config /etc/telegraf/telegraf.conf --test --test-wait 10 --config-directory /etc/telegraf/telegraf.d $TELEGRAF_OPTS