Hello openHab community.
Seems like my brain it too limited when it comes to apply regex to filter incoming MQTT messages.
I’d really appreciate your help on this!
Here’s my setup and what I’m trying to achieve:
A device (Shelly Pro 4PM) is sending data/status changes (power meter values) via MQTT.
It only sends data that has changed (different to many other shelly devices MQTT),
Example: if a power measure on one of it’s for power sensors changed it only sends this single dataset.
This is an example MQTT message (excerpt) for a changed power measurement on sensor with ID/name “switch:2”:
{
"src": "shellypro4pm-c8f09e87eec8",
"dst": "shellypro4pm-c8f09e87eec8/events",
"method": "NotifyStatus",
"params": {
"ts": 1695195688.41,
"switch:2": {
"id": 2,
"apower": 36.1
}
}
}
In my openHab MQTT thing file I have a channel representig power-measurement for switch:2 (and additional channels for switch:0, switch:1 and switch:3).
Here’s my question;
how do I apply a filter for my channel switch:2 to only consider MQTT messages that are for switch:2 and represend power-measurements (key-word: “apower”)?
Basically I only want to consider MQTT messages containing the strings switch:2 as well as apower .
I did a lot of research in this and other forums and tried several variants I’ve found without success such as:
Type number: power2 "Verbrauch 2" [stateTopic="shellypro4pm-c8f09e87eec8/events/rpc", transformationPattern="REGEX:(.*switch:2.*)∩REGEX:.*apower.*)∩JSONPATH:$.params.switch:2.apower"]
rersult: no value being received on this channel any longer.
Without any regex filter (only JOSANPATH) the value is being correctly received on the channel (but I get all these fail-warnings in the log for MQTT-messages which do not contain the JSON elements specified in the JSON-path of the channel (JSONPATH:$.params.switch:2.apower" which I want to avoid).
Any help is highly appreciated!
Thanks and kind regards,
Ralph…
P.S.: I do not want to use the shelly binding first because I had several problems with it after upgrading to OH 4 especially with Generation 2 / PRO devices (stability) and second because I do have several other devices useing MQTT in my system (consistency).