How to extract a string via the incoming value transformations in the MQTT Binding

Hi together,

i have a switch connected via zigbee2mqtt which multiple different states but only one state should leed the OH item to be interpreted as ON Value ( e.g. the mqtt topic value “direction_move_up”) while all other mqtt values like “stop_action_move” and “stop_bla_bla” should be interpreted as the OFF value(s) - so the values to set the item to OFF.
In the openhab channel configuration for the generic mqtt thing i now want to map that to a item by doing something like this:
Apply a “Incoming Value Transformation” on the channels mqtt topic value which removes everything from the value except a exact string, like “action”.
By this, i can than in the Custom On/Open Value paste in “action” and the “Custom Off/Closed Value” field can be left blank or?

I tried hours now by testing the regex and json transform settings of openhab but without access. For example, this is a try i died:

Please give me help - i am lost.
Thanks in advance, Tobi

An empty Custom Off/Closed Value leads to OFF as default value. So this is the wrong way to configure.
Instead simply use
Custom On/Open Value direction_move_up and Custom Off/Closed Value stop_action_move

If this is a read only switch, you can get away with that.

Hello Udo and great thanks for your quick reply. To be onest i have simplified the example above where i described my problem which ist why your suggestion might not work for me. In detail, the Switch (Ikea skybar) sends a value “press_button_left” If i Press the Button for a short time. I want the “press_button_left” topic value to be interpreted as the On Value while all other values (e.g. If i Press and hold the Button ITS state gets “hold_button_left”) should be interpreted as the Off Value.
Do you have a Suggestion on how to get it Work? Do you think my Idea of using the transformers is the right way?

Then better use a Trigger Channel. The Channel will provide every event to the bus as a channel triggerd. You then can use a simple rule (here DSL, but also possible through UI):

rule "switch reaction"
when
    Channel 'mqtt:topic:brokername:thingname:channelname' triggered
then
    if(receivedEvent == "press_button_left") {
        // do something
    } else {
        // do something else
    }
end

and if there are various actions, use switch():

rule "switch reaction"
when
    Channel 'mqtt:topic:brokername:thingname:channelname' triggered
then
    switch(receivedEvent) {
        case "press_button_left" : {
            // do something
        }
        case "hold_button_left" : {
            // do something
        }
        case "press_button_right" : {
            // do something
        }
        case "hold_button_right" : {
            // do something
        }
        default : logWarn("switch","Trigger {} unknown",receivedEvent)
    }
end

Thanks udo i will try it out.