How to use REGEX in PAPER UI

I’m sorry, I tried to search in the forum for information about the use of regex function in PAPER UI enviroment, but results all refer to the configuration files mode:
RegEx Transformation Service

I receive this topic MQTT from my sonoff:

23:06:42 MQT: tele/sonoff_POW/SENSOR = {"Time":"2020-06-03T23:06:42","ENERGY":{"Total":1361.543,"Yesterday":7.146,"Today":4.744,"Period":1,"Power":221,"Factor":0.80,"Voltage":226,"Current":1.230}}

I’ve defined a thing channel named “LastUpdate” to retrieve the “Time” value: “2020-06-03T23:06:42”

I linked a string item to the channel:

LastUpdate” item value:

My issue:
I want to trasform the string:


into this one:

2020-06-03 23:33:10

With the regular expression below


I can extract what I want, but I need to understand how to use the regex function in PAPER UI.

Note: I’ve already installed the “RegEx Transformation” Service

Many thanks for your answer.

REGEX doesn’t work like that in openHAB. To use REGEX the pattern must match the entire String and only the first matching group is returned. So at best, that regular expression would only return the date part of the date time string.

To remove the T part you would need to use the JavaScript transformation and replace the T with a space.

In either case, because you are already using the JSONPATH transformation, you need to chain the new transformation. Click on “more…” under the Incoming Value Transformations and you will see an explanation for how to do that.

But note that that DT string is in ISO 8601 format so you can send it straight to a DateTime Item and you can control how the DT is displayed by configuring the label and you can actually use it as a DateTime in your Rules (e.g. see if something happens before or after that DT.

NOTE: That screen shot is of PaperUI’s Control tab. That tab is for administration purposes only. Any formatting applied to the state in the label will not appear there. There is little to no customization possible for stuff displayed in the Control tab.


I want to thank you for the answer, and for having clarified an important aspect for which initially, even if I set the type to datetime, I could not get what I wanted: the formatting has effect in the browser.
I managed to format the date even better than I originally wanted.

Very briefly, below is my solution, if in the future it can be useful to some beginner like me.

I set the format on the item label, in Paper UI.

Below is the thing channel associated with the Item. I named it “LastUpdate” (it contains the time string provided from the sonoff)

This is what I see in the brower
I’ve found more informations about Datetime formatting here:
Time and Date Formatting in openHAB
Java Class Formatter

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.