REGEX and MQTT Binding

Hello

I have a little problem with REGEX and the MQTT binding.

The MQTT binding and switch works great without regex.

{mqtt="<[mqtt1:RFLinkR:state:20;2A;Chuango;ID=b1b978;SWITCH=02;CMD=ON;]"}

I think the regex transformation also work fine … when i type a invalid regex i get an error.

But both i cant get to work :frowning:

My MQTT message: 20;2A;Chuango;ID=b1b978;SWITCH=02;CMD=ON;

I simple want to look after: Chuango;ID=b1b978

So if Chuango;ID=b1b978 is in the message turn the switch on.

My MQTT for the Item:
{mqtt="<[mqtt1:RFLinkR:state:ON:REGEX(.(Chuango);(ID=b1b978).)]"}

I have tried:
.(Chuango);(ID=b1b978).
.(Chuango;ID=b1b978).
…(Chuango;ID=b1b978)…

And much more valid regex strings but it dosent work.

I have also tried it with state and command.

I get no error and the switch wont switch …

Thanks and sorry for my bad english …

I figured out that the regex work to …

When i use the mqtt string without the ON i get the following warning:
given new state is NULL, couldn’t post update for ‘AL_WHGT’

So i used:
{mqtt="<[mqtt1:RFLinkR:state:REGEX(.(Chuango);(ID=b1b978).)]"}

not

{mqtt="<[mqtt1:RFLinkR:state:on:REGEX(.(Chuango);(ID=b1b978).)]"}

So i think the regex will work to but why i dosent work with the on state …

thanks

Ok now i found the solution thanks :slight_smile:

You cant use the REGEX to switch item states only for number or string items …

To switch item states you have to use regex_filter !

First i thougt it will be the same but it isnt and there is no example in the mqtt binding description …

The difference just simple write the regex without the REGEX in front.

So you have to use for switches or switchable items:

{mqtt="<[mqtt1:RFLinkR:state:ON:.*(Chuango);(ID=b1b978).*]"}

For Numbers, Strings etc. you have to use something like this to get a part of the message:

{mqtt="<[mqtt1:RFLinkR:state:REGEX(.*(Chuango);(ID=b1b978).*)]"}

Thanks