OH3 HTTP-BINDING StateTransformation for Switches

I am somehow trying to migrate a similar thing from 2.5 (http v1) to 3.0

Before I used the following item to reboot my weatherstation webserver:
Switch LOCALWEATHER_observerreboot "Reboot Wetterstation" {http=">[ON:GET:http://192.168.1.5/msgreboot.htm] >[OFF:GET:http://192.168.1.5/msgreboot.htm]"}

Just firing this URL initates a reboot.
With the 3.0 http binding I would still like to keep it in a things file but struggle in migrating this.

any hints?

for anybody stumbling over this
I solved the above problem with:

Thing http:url:WeatherObserverReboot "WetterStationReboot" [ baseURL="http://192.168.1.5/", commandMethod="GET"] { 
	Channels: 
		Type switch : LOCALWEATHER_observerreboot [ commandExtension="msgreboot.htm",  onValue="ON", offValue="OFF"] 
}

Hi guys,

I am struggling here as well:
I got the http binding work to read my alarm-system’s state by using this config:

UID: http:url:AbusIP
label: HTTP Abus IP
thingTypeUID: http:url
configuration:
  authMode: BASIC_PREEMPTIVE
  ignoreSSLErrors: false
  baseURL: http://192.168.68.36:8060/
  password: xxx
  delay: 0
  refresh: 10
  commandMethod: GET
  contentType: text/plain
  timeout: 3000
  username: root
  bufferSize: 2048
channels:
  - id: AbusState
    channelTypeUID: http:switch
    label: Abus State
    description: ""
    configuration:
      onValue: Set
      stateExtension: getMode.cgi
      offValue: Unset
      stateTransformation: REGEX:Mode=(.*)

This is working fine and translates the states Set / Unset to ON / OFF.

However, the commands do not work and I tried this modified channel config:

channels:
  - id: AbusState
    channelTypeUID: http:switch
    label: Abus State
    description: ""
    configuration:
      onValue: Set
      stateExtension: getMode.cgi
      offValue: Unset
      stateTransformation: REGEX:Mode=(.*)
      commandExtension: setMode.cgi?Mode=

Because my previous OH2.5 item looked like this:

[ON:GET:http://192.168.68.36:8060/setMode.cgi?Mode=Set{Authorization=Basic xxx}[OFF:GET:http://192.168.68.36:8060/setMode.cgi?Mode=Unset{Authorization=Basic xxx}

Any suggestion?

You are not sending the value of your transformed command via the URL. Try:

commandExtension: setMode.cgi?Mode=%2$s

assuming you want to send Set or Unset after Mode=.

That’s it!
Awesome - You made my day :slight_smile:

By the way:
I love OH3 - even though the migration takes some time and causes significant effort, but the Main UI is much better and the option of merging 2 http items into one (command and state) is a great advantage (among others.

Thanks to @J-N-K for your help on the BASIC_PREEMPTIVE authentication topic

1 Like

It’s me again with an old issue.

From my Alarm-systems I get a string with \n like this:

InputCH1=OFF
InputCH2=OFF
InputCH3=OFF
InputVCH1=OFF
InputVCH2=DEACTIVATED
InputVCH3=DEACTIVATED
OutputCH1=OFF
OutputCH2=OFF
OutputWired=OFF
AlarmPowerFail=OFF
AlarmLowBattery=OFF
AlarmFault=OFF
AlarmFire=OFF
AlarmTechnical=OFF
AlarmBurglary=OFF
AlarmEntry=OFF
AlarmPanic=OFF

The first 3 lines (InputCh) are window contacts I would like to query using http.
(see also my problems with REGEX and http1 about this issue here:

So, when using AlarmPanic instead, it works just fine:

- id: Entrance
    channelTypeUID: http:contact
    label: Eingang
    description: ""
    configuration:
      stateExtension: getOverviewStatus.cgi
      stateTransformation: REGEX:.*AlarmPanic=(.*)
      openValue: ON
      closedValue: OFF

Using the right channel “InputCH1” does not (returns the intire string including the next lines.

My previous http config was this and worked just fine (even though it’s a mess):

{http="<[cacheAbusState:10000:REGEX(.*InputCH1=(.*)\\n.*\\n.*\\n.*\\n.*\\n.*\\n.*\\n.*\\n.*\\n.*\\n.*\\n.*\\n.*\\n.*\\n.*\\n.*\\n.*)]"}

But using the same REGEX structure does not work.

2021-01-02 09:04:47.194 [DEBUG] [.transform.SingleValueTransformation] - Transformation ChannelStateTransformation{pattern='.*InputCH1=(.*)\\n.*\\n.*\\n.*\\n.*\\n.*\\n.*\\n.*\\n.*\\n.*\\n.*\\n.*\\n.*\\n.*\\n.*\\n.*\\n.*', serviceName='REGEX'} returned empty res$
InputCH2=OFF
InputCH3=OFF
InputVCH1=OFF
InputVCH2=DEACTIVATED
InputVCH3=DEACTIVATED
OutputCH1=OFF
OutputCH2=OFF
OutputWired=OFF
AlarmPowerFail=OFF
AlarmLowBattery=OFF
AlarmFault=OFF
AlarmFire=OFF
AlarmTechnical=OFF
AlarmBurglary=OFF
AlarmEntry=OFF
AlarmPanic=OFF
.

So, obviously REGEX handling has changed (!?) and I wonder where the “.” at the end comes from?

Any suggestion how to get rid of the stuff after the next newline would be greatly appreciated.

EDIT:
I found a workaround - which is not pretty, but works:

REGEX:.*InputCH1=([A-Z]{2}).*

This will return ON / OF, which is mapped to OPEN / CLOSED.

.*InputVCH2=(.*?)\s

Should do. You need to make the group-matching-part non-greedy, that is done my appending ? to the quantifier. Otherwise .* will match everything as long as the rest can still me satisfied. Since . matches everything (including the EOL-characters), it’ll match everything until the last \n. You can test your regular expressions at Free Online Java Regular Expression Tester - FreeFormatter.com.

Another solution would be .*InputCH3=([A-Z]*).

Thanks a lot (again) for your support.

I tried this in the past (and again), but this does not work.
The \s seems to be ignored or better not even found by REGEX:

2021-01-02 10:39:17.592 [DEBUG] [.transform.SingleValueTransformation] - Transformation ChannelStateTransformation{pattern='.*InputVCH1=(.*?)\s', serviceName='REGEX'} returned empty result when applied to InputCH1=OFF
InputCH2=OFF
InputCH3=OFF
InputVCH1=OFF
InputVCH2=DEACTIVATED
InputVCH3=DEACTIVATED
OutputCH1=OFF
OutputCH2=OFF
OutputWired=OFF
AlarmPowerFail=OFF
AlarmLowBattery=OFF
AlarmFault=OFF
AlarmFire=OFF
AlarmTechnical=OFF
AlarmBurglary=OFF
AlarmEntry=OFF
AlarmPanic=OFF

.

The same with this:

2021-01-02 10:46:04.635 [DEBUG] [.transform.SingleValueTransformation] - Transformation ChannelStateTransformation{pattern='.*InputVCH1=([A-Z]*)', serviceName='REGEX'} returned empty result when applied to InputCH1=OFF
InputCH2=OFF
InputCH3=OFF
InputVCH1=OFF
InputVCH2=DEACTIVATED
InputVCH3=DEACTIVATED
OutputCH1=OFF
OutputCH2=OFF
OutputWired=OFF
AlarmPowerFail=OFF
AlarmLowBattery=OFF
AlarmFault=OFF
AlarmFire=OFF
AlarmTechnical=OFF
AlarmBurglary=OFF
AlarmEntry=OFF
AlarmPanic=OFF
.

That’s the frustrating part with REGEX in OH.
It does not work the same way like regex testers like REGEX101.com :frowning:

Well it does. But the regex needs to match the full response. REGEX:.*InputCH3=([A-Z]*).* works. .*InputVCH3=(.*?)\s.* also works. The missing .* at the end prevented the part after the matching group to match, why the regex did not match at all.

YES!
This works!
Thank you so much!

the new http 3.0 binding rocks!

Hello everyone,
I’m a beginer in OH. I’m using OH3 and I’d like to configure a http url thing to execute command and request the state to a web server, using get and post methods. I’m able to modify the php web files to test trought openhab.
I tested the get method to read and write an output at time. After this, I tried to modify the state request to read all status bits at a time to have best performance. But, when I introduce a regular expression in “State Trasformation” field, nothing changes: there is no error, but nothing is read anymore. Maybe it doesn’t match the regex.
To simplify the testing, I created a new channel of string type and configure it to read a string by get method. This example run correctly:

But when I add a regular expression, the linked point does not update. I tested a lot of regex, but always the same result.
This is a regex of the tested ones:

Where is the issue?
I forget to say that initially I’ve installed OH2 and later updated it to OH3.

If anyone wants to try it, I can upload the test_http.php page on a pubblic url.

You need a capturing group in your regex.

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

REGEX:.([A-Z])*

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:
http://www.igtek.eu/
State URL Extension:
“test_http.php?out_stato”

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:
STATUS(..)

Group 1 will be:
OK

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.