[SOLVED] Using regex with Aqara wireless button

Good evening.

I’m running into a few issues, most likely because I’m terrible at Regex.

Here’s the issue, I have a switch that can report 5 different things, the payload from Zigbee2MQTT looks like this:


Generally I would use jsonpath to find the action, however the button switching between “click” and “action” in the payload makes this approach throw errors. Instead I wanted to use regex to just parse the entire payload and extract the relevant bit.

Here, my approach works: regexr.com/4p28c

But in openhab, this always returns null:

var action = "Placeholder"

rule "Wireless button press"
    Item WirelessSwitch_WirelessSwitchButton received update
    var action = transform("REGEX", "\bshake\b|\bdouble\b|\bsingle\b|\bhold\b|\brelease\b", WirelessSwitch_WirelessSwitchButton.state.toString)
    logInfo("debug", action)

    switch action{
        case action = "single":
         if( KontorLys_.state == ON ) {


Where am I going wrong?

In openHAB, your REGEX expression must match the full message and the part that get’s returned is in the first capture group (first set of parens).


You are a god among men, Rich.