0

I'm using telegraf to receive data via MQTT and output it to an InfluxDB. In my case its data from several Shelly PowerPlugs (for example). I only process specific topics but they include both float and string values. I currently have 2 inputs specified which lead to 2 measurements in InfluxDB:

[[inputs.mqtt_consumer]]
   servers = ["tcp://localhost:1883"]
   qos = 0
   connection_timeout = "30s"
   topics = [
      "shellies/+/sensor/temperature",
      "shellies/+/sensor/humidity",
      "shellies/+/sensor/battery",
      "shellies/+/relay/0/power",
      "shellies/+/relay/0/energy",
      "shellies/+/relay/0/overpower_value",
      "shellies/+/temperature",
      "shellies/+/overtemperature",
   ]
   persistent_session = true
   client_id = "telegraf"
   username = "telegraf"
   password = "..."
   data_format = "value"
   data_type = "float"
[[inputs.mqtt_consumer]]
   servers = ["tcp://localhost:1883"]
   qos = 0
   connection_timeout = "30s"
   topics = [
      "shellies/+/relay/0",
   ]
   persistent_session = true
   name_override = "mqtt_consumer_string"
   client_id = "telegraf_string"
   username = "telegraf_string"
   password = "..."
   data_format = "value"
   data_type = "string"

I find it rather bad design to have two measurments, one with floats and one with strings. I also find it a bad idea to store the floats as strings. I came up with the idea to maybe have 2 value fields in one measurement. Something like "value_float" and "value_string" - and one input writes its value into one field and the other its value into the other field....

I just didn't found a way to specifiy the field name which is used. It seems that it will always use "value" - hence why I have two measurements right now.... Is there a way to override the field name which is sent to my influxdb?

Right now I have:

> select topic,value from mqtt_consumer limit 3;
name: mqtt_consumer
time                topic                                       value
----                -----                                       -----
1570836859339370843 shellies/shellyht-E01455/sensor/temperature 20.25
1570836859339411723 shellies/shellyht-E01455/sensor/humidity    72.5
1570836859339435163 shellies/shellyht-E01455/sensor/battery     98
> select topic,value from mqtt_consumer_string limit 3;
name: mqtt_consumer_string
time                topic                                value
----                -----                                -----
1605801371512111496 shellies/shellyplug-s-16822E/relay/0 on
1605801401512760387 shellies/shellyplug-s-16822E/relay/0 on
1605801431520199346 shellies/shellyplug-s-16822E/relay/0 on
>

I'd like to have smth like that instead:

time                topic                                       value_float    value_string
----                -----                                       -----          -----
1570836859339370843 shellies/shellyht-E01455/sensor/temperature 20.25
1570836859339411723 shellies/shellyht-E01455/sensor/humidity    72.5
1570836859339435163 shellies/shellyht-E01455/sensor/battery     98
1605801371512111496 shellies/shellyplug-s-16822E/relay/0                       on
1605801401512760387 shellies/shellyplug-s-16822E/relay/0                       on
1605801431520199346 shellies/shellyplug-s-16822E/relay/0                       on

Any idea on how to achive that?

Olli
  • 689
  • 1
  • 6
  • 13

0 Answers0