Hello!
I have a mqtt consumer configured to listen to homeassistant/rooms/#
. Now I receive messages in homeassistant/rooms/bedroom/window
and homeassistant/rooms/bedroom/weatherstation
.
The json I receive in homeassistant/rooms/bedroom/window
is following:
{
"battery": 67.5,
"battery_low": false,
"contact": true,
"linkquality": 196,
"tamper": false,
"voltage": 2900
}
Of this message only battery and contact are of interest for me.
And in homeassistant/rooms/bedroom/weatherstation
is this:
{
"temperature": 20.9,
"humidity":56.5,
"co2": 1345
}
I need all measurements of this message.
This is my current MQTT input configuration
[[inputs.mqtt_consumer]]
servers = ["tcp://mqtt:1883"]
topics = [
"homeassistant/rooms/#"
]
topic_tag = ""
username = "<Username>"
password = "<Password>"
data_format = "json_v2"
[[inputs.mqtt_consumer.json_v2]]
[[inputs.mqtt_consumer.json_v2.field]]
path = "contact"
rename = "isClosed"
type = "bool"
[[inputs.mqtt_consumer.json_v2.field]]
path = "battery"
rename = "battery"
type = "float"
[[inputs.mqtt_consumer.topic_parsing]]
topic = "homeassistant/rooms/+/+"
measurement = "_/_/measurement/_"
tags = "_/_/room/sensor"
As I started with the window sensor it works fine for it. The json is correctly parsed and I get the data in my influx db as I want it.
Of course this configuration won’t work for the second message as the path contact and battery are not present for it.
I have a really hard time understanding the configuration of telegraf so this might be an easy fix but I just cannot get it running.
I tried using various configurations of processors but I just couldn’t get a hang on it.
Hopefully some of you can help me!
TL;DR
I need a way to filter the messages by the topic they were received in and then parse the json I receive accordingly.