Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
telegraf config to transform mbmd mqtt messages
# send messages with database-tag = mbmd to influxdb mbmd
[[outputs.influxdb]]
urls = ["http://influxdb.host:8086"]
database = "mbmd"
tagexclude = ["influxdb_database", "src", "measurement"]
[outputs.influxdb.tagpass]
influxdb_database = ["mbmd"]
###########################################################################################
# Read metrics from MQTT topic(s)
# and assign database-tag depending on topic
# mbmd/#
## add tag 'line' to with default value 'Total' to all mbmd messages
[[inputs.mqtt_consumer]]
servers = ["tcp://mqtt.thomo.de:1883"]
connection_timeout = "30s"
topics = ["mbmd/#"]
data_format = "value"
data_type = "float"
name_override = "mbmd"
[inputs.mqtt_consumer.tags]
influxdb_database = "mbmd"
line = "Total"
###########################################################################################
# name = mbmd
## put topic parts in tags
[[processors.regex]]
order = 30
namepass = ["mbmd"]
# set src tag
[[processors.regex.tags]]
key = "topic"
pattern = "^mbmd/([\\w-]+)/.*$"
replacement = "${1}"
result_key = "src"
# set name tag
[[processors.regex.tags]]
key = "topic"
pattern = "^mbmd/[\\w-]+/(\\w+)/?.*$"
replacement = "${1}"
result_key = "name"
# set line tag
[[processors.regex.tags]]
key = "topic"
pattern = "^mbmd/[\\w-]+/[\\w]+/(L.)$"
replacement = "${1}"
result_key = "line"
# name = mbmd
## revalue tags
[[processors.enum]]
order = 40
namepass = ["mbmd"]
# map src -> node
[[processors.enum.mapping]]
tag = "src"
dest = "node"
[processors.enum.mapping.value_mappings]
se1-1 = "inverter"
se1-1-1 = "energymeter"
# map src -> sensor
[[processors.enum.mapping]]
tag = "src"
dest = "sensor"
[processors.enum.mapping.value_mappings]
se1-1 = "SE15k"
se1-1-1 = "SE-MTR-3Y-400V-A"
# map src -> location
[[processors.enum.mapping]]
tag = "src"
dest = "location"
[processors.enum.mapping.value_mappings]
se1-1 = "pv"
se1-1-1 = "house-connection"
# map name -> measurement
[[processors.enum.mapping]]
tag = "name"
dest = "measurement"
[processors.enum.mapping.value_mappings]
ApparentPower = "power"
Cosphi = "cosphi"
Current = "current"
DCCurrent = "current"
DCPower = "power"
DCVoltage = "voltage"
Export = "work"
Frequency = "frequency"
Import = "work"
Power = "power"
ReactivePower = "power"
Voltage = "voltage"
# from node-red
PowerExport = "power"
PowerImport = "power"
PowerSelfConsumption = "power"
# name = mbmd
# set measurement to tag['name'] = value['value']
# e.g.
# before: mbmd name=PowerSelfConsumption,... value=242
# after : mbmd name=PowerSelfConsumption,... PowerSelfConsumption=242
[[processors.pivot]]
order = 50
namepass = ["mbmd"]
## Tag to use for naming the new field.
tag_key = "name"
## Field to use as the value of the new field.
value_key = "value"
# name = mbmd
# set name (not the tag 'name')
# e.g.
# before: mbmd measurement=power,... PowerSelfConsumption=242
# after : power ... PowerSelfConsumption=242
[[processors.converter]]
order = 60
namepass = ["mbmd"]
tagexclude = ["name", "topic", "src"]
[processors.converter.tags]
measurement = ["measurement"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.