OH3 http binding round readed values before they are placed to item value

I have an device which I can request a html response.

Therefore I created a HTTP URL Thing like that

if my understanding now is right after this I have to create channels

which I did like that

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"

<title> Address List </title>
<style type="text/css">
body { background-color:#C0C0C0; color:#0000FF; }


<h2>Liste der ausgew&auml;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>

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


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.

I need to get a rounded value, because otherwise I have every 30s a changed entry in the influxdb which will consume a lot of space.

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 guess you should use a number channel if you want a number.

It’s okay to link a string channel to a Number Item using a profile (so long as the profile produces a numeric result).

But that’s not the case here. OP should use the REGEX in the stateTransformation and use a number channel. Pretty sure it works then.

No, it’s absolutely fine to use REGEX profile in this way with a Number Item.

Applying the transformation internally in the binding and output via number type channel is an equally valid alternative, where the binding allows.

Either way, the formatting for display should be applied to the Item metadata.

That seem to be exactly my problem.

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°.

My item is created as Number,

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”

Is there an regex option where I could round the mached number before it is transfered to the item value?

That’s right. That’s why it doesn’t work.

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 change the regex now to


so it machtes “20”, “20.1” and “20.23” more digits will not be matched.
This is not rounding it is only cutting of what is useless.

I will try to use the javascripting, but I realy did not get the first clue how to start with that quickly.

I started with creating a script

But how and where can I call it now?

I really don’t understand why you make it so difficult. Why don’t you use the stateTransformation and a number channel?

This would still need extra work to round before updating Item state.

It does seem to be a lot of effort to avoid recording data, which doesn’t cost much

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 think I got now a little bit further,

I created a script called


(function(i) {
  return 12;

I placed it in the UI under scripts

I found out that I had to install the javascript transformation Addon

And I have now the possibility to add the script in the channel item

I would expect now to get allways the value “12” but nothing happens.

So something is still wrong on my way to get a running profile script.

This was a god hint. Thnak you for that, I did not know that I have to place “REGEX:” before to get the transform running.

I did this now.

and indeed, this is working, but

as you you can see the string value, as well as the number value shows both the same value!

The number value I defined like that

now I would expect, that the state formatter “%.1f” would work before the regular expression matches.

As result I would expect “17.9” as value.

So I still missunderstand something.

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?

There is nothing wrong, the result actual is the same I had in my profile as well.

In both cases we just cut off all unnecessary digits. But we do not round!!.

In your case I thought now the frmatter would work, as now we realy have a string number which we should be able to format.

I will keep this now like it is, but I would ask you what is the better way in configuring my thing.

At the moment I have two configured things

The first one asks my device to give all items + values it has.

As in the response string I get all on the device configured items. Here I cant use the state transformation and I have to keep with the profile.

The charm of your way is that I can use the channels as readonly, readwrite and so on.
On the thing definition I only use the baseurl

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.

Thank you, I will give it a look later.

I now tried to get a setpoint to work.
I configured the channel like that

Where do I get the value from and how do I place it behind the “nv=”


I supose I have to enter something into command transform, but what?

And it should be executed onchange and not when the 30s timer is reading again

I found the solution

I only had to append.


The only thing is an error within the log now, but it is working

2021-11-01 01:08:53.322 [WARN ] [p.internal.http.HttpResponseListener] - Requesting 'http://ac40/cgi-fga/fga/fgacmd/TL300E02D01?pw=0123456789&nv=18' (method='GET', content='null') failed: Total timeout 3000 ms elapsed

But when I try it in the browser it never finishes as well, so I think the device is not responding.

But it works