I try to read out a (number) value from a website via http binding. The response is only in html/xml available.
With the regex add-on I’m able to extract the desired value as a string.
However, now I’m stuck as how to convert this value into a number. I think I would like to do it by concatenating another state transformation as the cleanest solution, but can’t find how to do it. Most examples use json.
Another way should be to link additional items performing the transformation? But I’m not sure if this is a good solution, and where this is best implemented.
(Additional difficulty: The value string is “german”, the decimal delimiter is “,” and not “.”)
When concatenating transformations, it doesn’t matter what the transforms are. They all work the same.
But assuming you’ve extracted a parsable number from the HTML, why not just change the Channel type to a number and let OH worry about parsing the string? Or is the number not parsable and you need to do further modifications to it to make it parsable?
Your REGEX has two matching groups. Only the first one gets returned. Regex doesn’t work quite like the standard in OH in that regard.
I would probably be easier to use a simple JS transform after the REGEX to replace the , with .. As of OH 3.2, JS supports “inline” configs and since 3.2. So if you used the regex to extract the number with the comma then you should be able to chain that to JS:|input.replace(',', '.')
I simplified the REGEX a tad to make it shorter and clearer. The first (.*) is the only thing that gets returned. If nothing matches nothing gets returned I think (though that might just be the MQTT binding).
However, your shortened regex works as well, at least for the key “VORLAUFTEMP” but not with “RÜCKLAUFTEMP”, which is another key. My version works with both… I’ll have a look into this later.
But thanks every one for setting me up
You are running 3.2 for sure? Based on the docs for the JS transform, that’s how to define an inline JS transform (using the | to tell it you’ve not passed it a file. There might be something going on with the way the HTTP binding interprets the string.
You’re right, there seems to be a difference. Now it works also with JS transformation.
Unfortunately, a search for JS in the UI only finds “JSScripting”. You have to manually look for it in the “other” category…