for a plant sensor:
{“Time”:“2021-05-06T12:09:21”,“Flora6caa96”:{“mac”:“c47c8d6caa96”,“Temperature”:22.2,“Illuminance”:1092,“Moisture”:33,“Fertility”:226,“Battery”:null,“RSSI”:-82}}
My goal:
Determine the thing by the value after time,
and in my thing use the other values as channels
Not really. Let’s say you want plant sensor thingy ‘Moisture’.
Use a REGEX to filter for text “Flora6caa96”, then chain to a JSONPATH for “Moisture” value.
This will ignore the “ESP32” messages.
It’s up to you to find the filter keywords -“Temperature” for example will not do.
Thanks to some fine help I received yesterday and the day before I can positively say this is not a problem.
Create the MQTT thing to connect to the broker. Do not configure channels on it.
Create a new ‘thing’ for each device (Just one?)
For each sensor on the ‘device’ thing you created, configure a channel.
In the channel configure the MQTT State Topic (‘tele/SerreScanner/SENSOR’ in your case) and under the advanced section add an input transform as a REGEX. e.g.
Note that OH REGEX’s are ‘unique’ in that you have to match the WHOLE input line (i.e. prefix and postfix with .*). You an see from the transport I use that it matches a MAC address… Which is the identifier for each sensor I have on my 1 mqtt topic. (I actually have two REGEX’s for each sensor. Temp and Humid so you can pull multiple data from each entry just by configuring a separate channel) - I did wonder if you can pull two items per channel, but haven’t investigated how I’d do that yet and 2x channels works anyway.
Add an item to the channel. Make sure you select ‘default’ for the items profile or the item won’t get the read value set.
Check the event logs to make sure it’s updating…I found OH’s REGEX’s a PITA to debug TBH so don’t try to change too much at once. Get one thing working and go from there.
so If i read your post correct,
you are not using jsonpath,
If i indeed want to make a thing for every ‘thing’ that sends info to my ‘collector’ which broadcasts it over mqtt it’s enough to filter on the name on every channel i add too.
I’m absolutly no hero in the regex department i just hope it wont be to complex given al the brackets and stuff on my plant sensors. always welcome to chip in
I’ve never understood why people use MQTT like this (it’s not you, it’s who ever implemented the firmware). One of the guiding principles of MQTT is that you should not impose a processing burden on your subscribers. Sending such diverse messages that need to be processed just to figure out whether or not you care about the message is imposing pretty heavily on the subscribers. At a minimum each sensor should have its own topic. Even better would be to skip the JSON and publish each piece of data on its own topic.
Anyway, assuming you can’t fix this at the source, the overall pattern for a REGEX filter is as follows:
REGEX:(.*unique string.*)∩JSONPATH:$.field
where “unique string” is the unique sequence of characters that identifies this as a message the Channel cares about and $.field is the JSONPATH to the JSON field to extract. Pay close attention to the nesting in the JSON.
Given the examples above you would use something like
to extract the temperature from that specific Flora device.
When things don’t work, break it down. Create a String Channel and set it up with the REGEX filter. Does it only capture the messages that match? Once you have that working then try adding the JSONPATH transform. But do it little by little.
Thx lots, seems i made a typo on rossko57’s last post,
he posted the answer to.
you expression seems to do what i wanted it to do,
but i must say I agree on the mqtt thing it would have been easier for everyone if they just lengthened the topic, even just doing tele/SerreScanner/SENSOR/flora1 and tele/SerreScanner/SENSOR/esp32
would make it so much easier, and more inline with the whole topic logic,
anyways thanks alot all for the help