Simple Question: TransformationPattern to remove brackets

I’m 20 minutes in looking for an example, but can’t find one.

A MQTT device returns a payload that looks like this:


I can grab that value as a string, but need to strip the brackets and store it as a number.

Is there an easy way to do this in the MQTT thing with TransformationPatterns? I suspect it is regex but I can’t find an example…

something like this, as JS transformation?

    return x.match(/\[([0-9]+)\]/)[1];

Appreciate it! I’m not sure if I can apply the JSON transformation and the JS transformation to a channel in a MQTT thing, but I think I’ll just add the JSON parsing to this code and use a single transformation.

Mqtt things file:

Thing topic <name> "<name>" {
  Type <type> : <name> "<name>"      [ stateTopic="<statetopic>", transformationPattern="JS:<transformationfile.js>" ]

Don’t forget to install the JS transformation service.

That part was hidden.

MQTT binding does allow a little magic; in the docs you will find chaining transformations.

neat… I’ll give this a try!

You can. See MQTT 2.5 M1+ How to implement the equivalent to MQTT1 REGEX filters for an example using PaperUI. You will need to find someone else to help translate that to .things files.

Also, a JS transform is way overkill for this. Just use REGEX:\[(.*)\] (assuming there is no white space around it).