To show the response I created a string item where I get the following response:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<META HTTP-EQUIV="Refresh" CONTENT="30">
<title> Address List </title>
<style type="text/css">
body { background-color:#C0C0C0; color:#0000FF; }
</style>
</head>
<body>
<h2>Liste der ausgewählten FG-Adressen:</h2>
----------------------------------------------------------------------------------------------------
<br><pre><b>TL300E02B01 </b>Zulufttemperatur Analogeingang mit Grenzwert
<br>31-10-21 17:33:14 <a href="fga/TL300E02B01 " target="_blank">20.77114 </a>
<br></pre>
</body>
</html>
What I need to get is the value “20.77114”. Therefore I create a number item to that channel with an regex profile and expression
.*\/TL300E02B01.*?[>](\d*\.?\d*).*
which exactly maches the number “20” or “20.1” or “20.34573”. If my thinking still is right, then the state formatter should be able format and round that number via “%.1f” to “20.x”.
This does not work, Why?
At the moment only “%s” is working, “%.1f” is not.
It’s a question of which formatter.
The one in your screen shot is about formatting the output of your HTTP channel before feeding it to your REGEX profile. And that output is just a string.
You’ll be wanting to format your Item state for display, that is about the Item’s metadata state description / pattern.
I need the value rounded before it is feeded into the item value.
You are telling me that the “%.1f” formatting is done before the regex matches the response string.
This does not make sense for me, as the state formatter has no chance to find the right “Number” within the html response string.
Only the regex would be and is capable to find the right number, Then the formatter should transform the Number for example “20.13466” to “20.1” and then transfer it to the item value.
The metadata state description pattern would work, but does not ommit that the changed value is written every 30s to the database.
I only want have written values to the database when they changed by 0.1° not by 0.0001°.
The value above you can see is the last value which was written with the “%s” state formatter option.
With “%.1f” the value does not change anymore. If I start with that option the value entry stays on “NULL”
REGEX is string manipulation, it doesn’t do rounding. You’re going to need a two-stage process, first extract the numeric, then round it.
One way to combine is with a JS javascript transformation, the one script can perform regex and then rounding.
This could be applied as link profile or as channel state transformation.
I realy don’t understand why it is so complicated.
I am exactly doing this. But I am using the UI and there a “stateTransformation” is not existend within the http Binding, I only have profiles
The problem of my temperatur from my external device is that this a “resitor” values, on every reading the digits are changed. If I read every 30s I will get for example “20.12643”, “20.11836”, “20.1453”, “20.13346”
All values are rounde exactly “20.1” °C so normaly only the first one is registered as change and stored in influxdb the follwing 3 will be omited. If the next one is then “20.1.6423” → “20.2” will be stored.
This is what i try to get work. I did it now by cutting of all digits beginning with the second one.
I never use .things files. I am 100% sure stateTransformation is available in the UI. The second picture in your first post even shows it’s there. You just need to enter something like REGEX:.*\/TL300E02B01.*?[>](\d*\.?\d{1}).*.
I don’t understand why you insist on using a profile. It’s all in the binding configuration. What’s wrong with using \d+\.\d{1} in the stateTransformation?
And now I have to define for every item it own channel using the state transformation. The advantage of this way is, that at the same time I also can define a command transformation and a command url. So I will be able to get/set my setpoint and also my command switches.
So I will continue this way it seems to be the better way in my opinion.
The next big question will then be how the mapping works.
The returned value of the device switches will be in string form “AUS” or “EIN1” “EIN2”,
the commanded value should be “off” or “on1” “on2”.
In OH this will be numbers or an ennumeration 0,1,2 I think.
How and where I will have to do the mapping?
There is no situation where the profile works and the stateTransfomation does not. In fact, the stateTransformation is more flexible, since you can path the result of the REGEX to a MAP or any other transformation just by adding that (have a look, it’s all in the documentation: HTTP - Bindings | openHAB). If you want rounding: There is a ROUND profile in the basic profiles addon (available at the community marketplace),
In general it’s better to make less requests, so if you can get multiple values at once, do that. Use a proper REGEX in each channels stateTransformation to extract what you need for that channel.
Unfortunately the mappings can’t be configured in the UI. You need to create a .map file in the transform folder for that. Please don’t ask me why this can’t be done via UI.