OH3 HTTP-BINDING StateTransformation for Switches

You need a capturing group in your regex.

I tried to add round brackets, but it doesn’t run.


If I test the regex without round bracket on an online tester, it finds a group:

Please, could you suggest the right syntax to add a capturing group?

Could you provide an example of the input string and the snippet you want to extract?

1 Like

Now, it’s just to test it.
The page test_http.php returns the string “STATUSOK”.
I have upload it on a pubblic domain, you can try it at this link with GET the parameter out_stato
basic URL:
State URL Extension:

The output url for request become: http://www.igtek.eu/test_http.php?out_stato
string test 04

I’ll be happy to extract anything, even the entire string, like without REGEX. After I have verified the functioning of any regex, I’ll go to modify the web page to return the status of the system and I’ll write the necessaried regexs.

I’m afraid that there are problems in my openhab 3 installation.

Well, let’s assume you like to get the “OK” in a capure group, just use:

Group 1 will be:

Please, could you test it on your openhab?

I tested it, but I can’t capture anything.

If I remove the regex from stateTransformation, it captures the entire string “STATUSOK”.

It is like the RegEx Transformation Service doesn’t work on my openhab.

Is there anything in the log?

There are several warnings like these ones:

2021-01-22 13:42:05.331 [WARN ] [.transform.SingleValueTransformation] - Transformation service REGEX for pattern STATUS(…) not found!
2021-01-22 13:42:05.339 [WARN ] [ttp.internal.http.RefreshingUrlCache] - Splitting header ‘out_stato’ failed. No ‘=’ was found. Ignoring
2021-01-22 13:42:06.039 [WARN ] [.transform.SingleValueTransformation] - Transformation service REGEX for pattern . not found!
2021-01-22 13:42:10.329 [WARN ] [ttp.internal.http.RefreshingUrlCache] - Splitting header ‘out_stato’ failed. No ‘=’ was found. Ignoring

You don’t have the REGEX Transformation Service installed.

If you think you do, uninstall it, then reinstall it.

Thank you a lot to everyone, I am a beginner.

After install the RegEx Transformation, it’s running properly.
Now I can go on!

Thanks for that example

In a bidirectional channel (send & receive) the onValue/offValue is used in both cases (directions). I was MAPing the stateTransformation to ON and OFF and wondered why my switch-item kept UNDEF. I ignored the onValue/offValue because I thought it is just used when sending… this took me 2 hours even though I read your post 3 which tells exactly this. Shame on me =(

Brilliant, thanks, that solved exactly the problem I had been having, where I first used JSONPATH: to read the 0/1 state of a window contact, and the transformed it to ON / OFF as you described:

Type switch : FensterOG "Fenster OG" [ stateTransformation="JSONPATH:FensterOG", onValue="1", offValue="0"]

Just as a sidenote: I bet you use textual config. Because the UI won‘t allow you to save the config if the required values are not set.

You read that via http Binding? What brand is that?

No particular brand, really. This is a homebrew solution. Basically our house used to have a proper (but very old school) alarm system, which at some point fell into disuse. All the windows have some sort of reed contact, grouped per floor, with a wire in and a wire out of the alarm system for each floor. At some point I figured out I could connect these to the Raspberry’s GPIO pins to read the state of the window contacts. This approach had been working quite reliably with OH2.

Now with OH3 there is not yet an updated GPIO binding available, and for now I could not get to work the new GPIO binding that is supposedly going to be rolled out with 3.1. So to create an interim solution I wrote a small nodejs script that sets up a server which queries the respective GPIO pins (using the onoff package) and serves the result as json. And that is where I need the http binding on the OH side to ingest the json result.