Widget REGEX expression syntax help needed

Platform information:

  • Hardware: Raspberry Pi 2 Model B Rev 1.1/1GB/16GB SD card
  • OS: Raspbian GNU/Linux 10 (buster)
  • Java Runtime Environment: openjdk 11.0.10 2021-01-19 LTS
  • openHAB version: OpenHABian 3.0.1

I am having trouble getting REGEX transform going. I looked through docs and the community, but found no real help so far.
What I am trying to do is to get the energy output from my solar inverter. I created an HTTP URL Thing and I get the status in a channel, there are several lines and I created a regex and can read the relevant information with regex101.
However, I am unable to get it going in my setup. I have the regex transformation added, etc. However I cannot get the syntax going, not even in the widgets expression tester.
From what I read, the following simple example should work"

=transform("REGEX", "^[A-Z]",  "What") 

However, I get no output, much less a reformatted string.
Ultimately this is what I thought my final thing should look like:

UID: http:url:f1f558fa8e
label: HTTP URL Thing
thingTypeUID: http:url
configuration:
  authMode: BASIC
  ignoreSSLErrors: false
  baseURL: http://192.168.1.247/home.cgi
  refresh: 30
  commandMethod: GET
  contentType: text/plain
  timeout: 3000
  bufferSize: 2048
location: Garage
channels:
  - id: cZeverReturn
    channelTypeUID: http:string
    label: Return
    description: ""
    configuration:
      stateTransformation: REGEX:/^(?:[^\x20]*\x20){11}([0-9]*)\x20/

Any pointer or help much appreciated!

What info do you get from the url?

This is the info I am getting, the separators are x20, I checked with a hexeditor

1 1 EAB961990366 FGNAAFQN5QJKXMPG M11 18C20-817R+17829-719R 15:40 23/03/2021 0 1 ZD50000111990216 221 1.25 OK Error 

This is a good goal. I stuck the regex in the validator and it shows a match. I not sure why it is not working.

What you have is a string of data that you want to get into openHAB and I guess you want more than one value.

An easy way to achieve this is to just leave your channel as the full string. Create a String item and link it to that channel.

Then you can create a rule when the item updates it will trigger the rule.

The add action run a script and create a DSL script.

Here is an example to get it logging the data

var buffer = YOUR_STRING_ITEM_NAME.state.toString.split(" ")
logInfo("Value", buffer.get(12))

I assume the value is amps so you can then create another item for solar amps.

Item may be solar_amps
Add this to the end of the rule

solar_amps.sendCommand(buffer.get(12))

You can remove the loginfo line or turn it off using //

1 Like

Thanks very much, James,
it worked (had to wait until it is day again here in Australia to test :grinning:).
For completeness sake, had to use return(\n) as a separator, space (d32) was an artifact when I pulled the info via web browser.
Thanks again!

1 Like

Thanks much, James.

Will certainly try. Added to my todo list.

Cheers!
Ralf