Understanding REGEX and using it in ITEM with MQTT

Hi Guys

I am fairly new to openHAB, and I really love what everyone has been doing! I am using openHAB2.

My problem is around understanding REGEX. I have done quite a bit of research and just when I think I understand it, it does not work… Here we go:

In there a proper guide on REGEX and I think the flavour that works in openHAB. I have tried emulators that’s on the web, but that expression does not seem to work in openHAB.

I want to use regex in the Items file, which will avoid lots of scripts and rules. I have the following data from MQTT:

S:OPEN,P:1,N:"Workshop IR"
S:CLOSED,P:1,N:“Workshop IR”

And I need just the OPEN or CLOSED statements. I have tried various different one’s, but I am missing something. I have been using this site to test the expressions. https://regex101.com
Here is a sample of what I have tried:
String WorkshopIR “Workshop IR [%s]” (Alarm) {mqtt="<[mosquitto:Paradox/ZS/Z9:state:REGEX((OPEN)|(CLOSED))
Can’t remember the rest… but there has been plenty.

Please help? I would like to understand this, so I don’t have to ask…


Which paradox binding are you using? I’ve been playing with the v2 one, and have changed it to use logging, and also to output each zone to their own item (rather than requiring regex).

Paradox/Zone/Main Door ON
Paradox/Zone/Main Door OFF

So each sensor (as named in babyware) make their own Paradox/Zone/[zone name] entry meaning you can easily add each to a switch.

I’ve also added the partition arm/disarm to a similar item.

I think, looking at your entries of ZS etc you;'re using v1 of the paradox binding.

You are 100% correct, I am using V1. Question on V2, can you still use the iParadox app if the binding is connected to the system. As far as I have it when a user is connected, a second user can’t. That’s why I went for now with V1 as it binds to the web port. I have a 192Evo system.

The change you made to the logging, can it be done in V1 and how is it done?

I would still be happy to understand the regex, sure I will have to use it somewhere…

With the v2 I can use the iOS app and the script, but not the built in web site.

The login I replaced all the python print commands with logging.info etc


Can anyone please direct me in the right direction? I would really like to understand this.

Does this work?

String WorkshopIR "Workshop IR [%s]" (Alarm) { mqtt="<[mosquitto:Paradox/ZS/Z9:state:REGEX(S:(.*?),P.*)]"  }


I will try it tonight and update!

Hi Alpoy

Sorry for the time, but I only got to this now again.

I have tried with what you suggested but i get the following error:
2017-03-01 20:06:53.024 [ERROR] [.mqtt.internal.MqttMessageSubscriber] - Error processing MQTT message.
java.util.regex.PatternSyntaxException: Unmatched closing ‘)’ near index 8

With the ^ pointing to the last * in the code. I tried adding another closing bracket, but that makes it not match an opening bracket. I also tired removing the * and the ,P.* - No luck…

Any other ideas will be much appreciated?

Try adding a ? after the .* , like:

String WorkshopIR "Workshop IR [%s]" (Alarm) { mqtt="<[mosquitto:Paradox/ZS/Z9:state:REGEX(S:(.*?),P.*?)]"  }

Thanks Alpoy

No go, still get error: java.util.regex.PatternSyntaxException: Unmatched closing ‘)’ near index 9

I tried to your expression on : https://regex101.com/r/xeG3jr/1

And it resolve I think correctly, however openHAB does not think so. It said this:
Match 1
Full match
Group 1.
Group 2.

There is new documentation online now for the transformations:



Thanks, but I still don’t get it right… most of the stuff I tried gives me errors and I even added another “:” in the mqtt string, got a different error, but still no luck. 3hours later…

I got the map function working although i think this is not ideal

Any other ideas?

Try this:

Contact WorkshopIR "Workshop IR  [%s]"  (Alarm) {
  mqtt="<[mosquitto:Paradox/ZS/Z9:state:REGEX(.*(OPEN|CLOSED).*):.*Workshop IR.*]"

The REGEX(.*(OPEN|CLOSED).*) ought to capture that part of the string, which is directly usable by Contact items. The section after the next colon .*Workshop IR.* is meant to restrict the messages considered for this item to only those that match that RegEx, so this topic could be used for other IR devices as well.

1 Like


You are a star!! Thank you very much as this is working now!

Can I suggest that you add some more examples into the documentation link you added earlier? That would help.

I did try the (OPEN|CLOSED) part, but it was obviously missing lots…Is there anywhere where I can get more info on this?

1 Like

If you can think of improvements to the README.md files here, making sure the improvements are relevant to Eclipse SmartHome, please submit pull requests! :smile: