Avoid error messages in logs with jsonpath transformation

I am using OpenHab with Zigbee2MQTT as Bridge to my zigbee devices.

As an example this remote control:

Thing topic tradfriRemote2 "Tradfri Remote 2" {
		Type string : tradfriRemote2	[stateTopic="zigbee2mqtt/remote-tradfri-2", transformationPattern="JSONPATH:$.action" ]
		Type number : battery		[stateTopic="zigbee2mqtt/remote-tradfri-2", transformationPattern="JSONPATH:$.battery" ]
}

Sometimes these zigbee things (or let it be zigbee2mqtt) don’t send the complete mqtt message, so e.g. sometimes it sends the battery status only, without a “action” part in the mqtt message. This causes error messages in the log everytime:

2024-10-17 12:06:27.025 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.action' in '{"battery":80,"linkquality":21,"update":{"installed_version":604241925,"latest_version":604241925,"state":"idle"}}'. Pattern: '$.action'. Value: '{"battery":80,"linkquality":21,"update":{"installed_version":604241925,"latest_version":604241925,"state":"idle"}}'

It does not harm anything but I generally don’t like error messages in my logfiles :wink: Do you have any idea how I could avoid these parsing issues?

MQTT 2.5 M1+ How to implement the equivalent to MQTT1 REGEX filters.

It’s an old post but this still works this way. TL;DR is to chain a REGEX filter that matches only those messages that you want to pass to the JSONPATH. If the REGEX doesn’t match it doesn’t return anything and the message is dropped.

1 Like

That’s working perfectly, thank you! (Had to copy paste that “∩” character :smile: )

For managed Things, you can put each transformation on a separate line instead of using the intersection operator.