Openhab 3 http-binding through UI

My parents got a new heating system from http://www.eta.co.at

I am able to get sensor-data via http-api calls like:

Result:

<eta xmlns="http://www.eta.co.at/rest/v1" version="1.0">
<value uri="/user/var/40/10021/0/11163/0" strValue="51,2" unit="°C" decPlaces="1" scaleFactor="10" advTextOffset="0">512</value>
</eta>

or

Result:

<eta xmlns="http://www.eta.co.at/rest/v1" version="1.0">
<value uri="/user/var/40/10021/0/0/12180" strValue="2,33" unit="bar" decPlaces="2" scaleFactor="100" advTextOffset="0">233</value>
</eta>

What would be the best way to transfer this into a Number-Value with correct scale and unit to use them in charts?

Perhaps JavaScript transformation.

First extract (e.g. by using a regular expression) the value, unit and scale, then calculate the correct „final value“ by multiplying value and scale and return a string with „value unit“. Take care that the unit is correctly formatted.

Yes, that is how I started.
I use a RegEx ( .strValue="(.?)".* ) to extract the strValue.
Then I link a Number-Item to use this in charts and so on.

My Problem with this appoach is, that a strValue like ‘4,23’ gets transformed to ‘423’ and the item is not using the unit.

Can this all be done in the Channel-Transformation or do I have to work with rules for each Channel?

As I said: Use the Javascript transformation and a regex in that, not the regex transformation. Something like


let value = /strValue="([\d,]+)"/.exec(input)[1].replace(",", ".");
let scale = /scaleFactor="(\d+)"/.exec(input)[1];
let unit = /unit="(.*?)"/.exec(input)[1];

return value/scale + " " + unit;