On of my tuYa measurement device exposes value as integer (e.g. temperature is not 23.4C by 234), pH value is 721 instead of 7.21
I tried to applied a regex transformation to the channel s/(\d{2})(\d)/$1.$2/g
that one should take first two digits add a dot and than third digit (regex version of div / 10).
However it does nothing and the presented value remain the same “721”
When I change an item type to String instead of Number than I have “72.1.0” … so regex works but an additional suffix is added “.0”.
Am I doing something wrong, or is it a bug in the regex transformation plugin?
The REGEX transformation is primarily designed to extract a single value for a larger String or document. As such it has limitation and restrictions which make it non-standard.
The expression must match the entire String or document, not just one line or part of a line. You’ll usually see expressions bracketed by .* to create that.
The first matching group (i.e. set of parens) is what is extracted from the String or document and returned.
If the expression doesn’t match the String or the first matching group is not found then the transform returns null and the update is effectively ignored.
I suspect 2 is getting in the way here.
You will probably have better luck using the Offset profile which you appear to have installed and was created expressly for doing these sorts of simple operations (see the Modbus docs for details).
Or use a SCRIPT transform to implement the division in code.
It depends on where you added this. Not everywhere you can apply a transform supports a formatting like that. It’s also important to understand that the result of all transformations is a String. So, unless the add-on handles it, the only formatting that makes sense is %s.
That string gets sent to the Item as an update and it’s at that time that the string is parsed and converted into something the Item supports. That means it’s not a number until after it gets to the Item. The profile stands between the Channel and the Item so at that level you are working with strings.
What kind of binding is used?
e.g. if using mqtt, it’s very simple to change the unit (here *.things file notation):
Type number : temp "temperature" [ stateTopic="my/topic/to/temperature", unit="d°C" ]
d°C is “Deci degree Celsius”, so 234 will result in 23.4 °C.
Certainly, you’ll end in using a Number:Temperature Item (and maybe set the Item metadata unit to °C)
It’s a TuYa device so I’m using a plugin “SmartHome/J Tuya Binding”. Maybe it’s not so obvious to change it there.
Anyway I sorted everything out with regex as well as I removed files from persistence/rrd4j for those devices so I won’t see totally different values on the same chart.