JSONPATH and different content of json payload

  • Platform information:
    • Hardware: RPi 4
    • OS: Raspbian
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version: 3.3.0 in docker

I have a small problem which trying to solve with no success (so far) :wink:

I have Xiaomi/Auara wireless wall switch connected via zigbee2mqtt and when I click the button I have following payload:
payload '{\"action\":\"single\",\"battery\":100,\"device_temperature\":32,\"last_seen\":\"2022-07-04T12:46:30+02:00\",\"linkquality\":98,\"voltage\":3015}'"}

However the switch itself sends also the “status” message from time to time, but without action element:

In this case I am receiving the following warning, which I don’t like :wink:
2022-07-04 13:16:51.424 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.action' in '{"battery":100,"device_temperature":25,"last_seen":"2022-07-04T13:16:51+02:00","linkquality":98,"voltage":3055}'

The setup of my thing looks like this:

UID: mqtt:topic:mosquitto:X_Switch_S002
label: Switch 002
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:mosquitto
location: Corridor
  - id: SwitchCorridorAction
    channelTypeUID: mqtt:string
    label: Action
    description: null
      commandTopic: zigbee2mqtt/X_Switch_S002/set
      transformationPattern: JSONPATH:$.action
      stateTopic: zigbee2mqtt/X_Switch_S002
  - id: SwitchCorridorBattery
    channelTypeUID: mqtt:number
    label: Bateria
    description: null
      stateTopic: zigbee2mqtt/X_Switch_S002
      transformationPattern: JSONPATH:$.battery
      unit: "%"
  - id: SwitchCorridorLinkquality
    channelTypeUID: mqtt:number
    label: Siła sygnału
    description: null
      stateTopic: zigbee2mqtt/X_Switch_S002
      transformationPattern: JSONPATH:$.linkquality
  - id: SwitchCorridorLastChange
    channelTypeUID: mqtt:datetime
    label: Ostatnia zmiana
    description: null
      stateTopic: zigbee2mqtt/X_Switch_S002
      transformationPattern: JSONPATH:$.last_seen

Maybe this is not a big issue, but I have several such switches and don’t like to have errors and warnings in logs :wink:

Any ideas how to solve it?

Thanks in advance.

Step 1: install the REGEX Transformation Service.

Step 2: Add the following into line 14 your config:


so that it looks like:

transformationPattern: REGEX:(.*action.*)∩JSONPATH:$.action

This will now first use REGEX to see whether the word action is present in the string. If it is, it will then use the JSONPATH service to extract the value. If it isn’t, nothing happens.


Seems it works. No warnings for last 20 minutes :wink: