[Solved]Help on REGEX

I created a skript which logs me on my Air-Heatpump and returns all relevant data, but no matter what expression I choose there is always an empty string for REGEX-transformation.
I have uploaded the return-string from the log
openhab2.log (17.9 KB)

I suspect your RegEx is faulty. You are looking for a line starting with body as first word ignoring the < and <.
Maybe this is what you are looking for:
<body>([\s\S]*)<\/body>
But it’s only a wild guess. I don’t know what you actually want to achieve and I’m no expert for Regex-transformations in OpenHAB.

https://regex101.com/ is a really helpful tool to understand the individual tokens in your RegEx and check if they are working as intended.

Thank you for the advice.
But every expression that worked in online validators gives me error in openhab.log:
the given regex '^<body>([\s\S]*)<\/body>$' doesn't match the given content
Maybe the problem are the “” in the string from returnvalue?

Can you remove ^ and $ from the expression?

No, they come from the binding.

The openHAB RegEx Transformation Service is not standard regex, so do not entirely trust online validators.

The magical part is that your expression must match the whole string.


You’ll want to be using .* something like
.*<body>([\s\S]*)<\/body>.*
I think

Just found that, too.
[\s\S]*<body>([\s\S]*)<\/body>[\s\S]* works on regex101 but maybe RegEx is not the best solution here.

That is the trick.
Thank you very much.
Now i will try to get the values:

</tr>
  <tr class="odd">
    <td class="key">STROM INVERTER</td>
    <td class="value">0,0A</td>
  </tr>
  <tr class="even">
    <td class="key">SPANNUNG INVERTER</td>
    <td class="value">230,0V</td>
  </tr>

I didn’t look at the full return string, but it looks like it might be XHTML (i.e. HTML without beginning tags that are missing their ending tags). If that’s the case, the XPath or XSLT transforms ought to work.

@rlkoshak:
So I managed to get the most relevant data:
<tr class="even"> <td class="key">RÜCKLAUFTEMPERATUR</td> <td class="value">18,7°C</td> </tr> <tr class="odd"> <td class="key">VORLAUFTEMPERATUR</td> <td class="value">18,4°C</td> </tr> <tr class="even"> <td class="key">FROSTSCHUTZTEMPERATUR</td> <td class="value">24,9°C</td> </tr> <tr class="odd"> <td class="key">AUSSENTEMPERATUR</td> <td class="value">37,1°C</td> </tr> <tr class="even"> <td class="key">FORTLUFTTEMPERATUR</td> <td class="value">36,6°C</td> </tr> <tr class="odd"> <td class="key">VERDAMPFERTEMPERATUR</td> <td class="value">39,6°C</td> </tr> <tr class="even"> <td class="key">VERDICHTEREINTRITTSTEMPERATUR</td> <td class="value">37,6°C</td> </tr> <tr class="odd"> <td class="key">ZWISCHENEINSPRITZUNGSTEMP</td> <td class="value">40,4°C</td> </tr> <tr class="even"> <td class="key">HEISSGASTEMPERATUR</td> <td class="value">39,8°C</td> </tr> <tr class="odd"> <td class="key">VERFLÜSSIGERTEMPERATUR</td> <td class="value">27,2°C</td> </tr> <tr class="even"> <td class="key">ÖLSUMPFTEMPERATUR</td> <td class="value">43,1°C</td> </tr> <tr class="odd"> <td class="key">DRUCK NIEDERDRUCK</td> <td class="value">15,05bar</td> </tr> <tr class="even"> <td class="key">DRUCK MITTELDRUCK</td> <td class="value">15,32bar</td> </tr> <tr class="odd"> <td class="key">DRUCK HOCHDRUCK</td> <td class="value">22,84bar</td> </tr> <tr class="even"> <td class="key">WP WASSERVOLUMENSTROM</td> <td class="value">0,0l/min</td> </tr> <tr class="odd"> <td class="key">STROM INVERTER</td> <td class="value">0,0A</td> </tr> <tr class="even"> <td class="key">SPANNUNG INVERTER</td> <td class="value">231,0V</td> </tr> <tr class="odd"> <td class="key">ISTDREHZAHL VERDICHTER</td> <td class="value">0Hz</td> </tr> <tr class="even"> <td class="key">SOLLDREHZAHL VERDICHTER</td> <td class="value">0Hz</td> </tr> <tr class="odd"> <td class="key">LÜFTERLEISTUNG REL</td> <td class="value">0%</td> </tr> </table>

but for XPATH I have to prepend String "<table>" to the returnvalue via rule:
rule “WP”
when
Item Befehl_RCkgabewert changed
then
val String url = "<table>" + Befehl_RCkgabewert.state
val String res = transform(“XPATH”, “//td”, url)
logInfo(“WP”, "1 — : " + res)
end
Now I am wondering how to get those values into individual items.
Any suggestions?
Thanks in advance.

Assuming the table is always in the same order, keep on using XPATH in a Rule. Or use the REGEX transformation remembering the advice of rossko57 above.

You never say how you get this data into openHAB. If it’s using the HTTP binding you can use a caching configuration and define the expression on the Items and don’t need a Rule.

I use a script in Exec-binding and prepend <table> to the returnvalue in the above rule, so I can transform the result using XPATH.
Now I thought of something like
Item1=XPATH//td[1] and so on in the same rule but I don’t really know how to assign values to items using transformation in rules.

You already know how to save the result of the transform to a variable. Just postUpdate or sendCommand that variable to the Item. https://www.openhab.org/docs/configuration/rules-dsl.html#manipulating-item-states

Thank you very much.
So the state of an item is the same as the value of a variable?

I strongly recommend going back through the overview sections and perhaps the new user’s section of the documents. To be successful with openHAB you must know the difference between a variable, a Thing, a Channel, etc.

An Item represents a single value or control. An Item has a State. To change the State you issue updates or commands. So if you call MyItem.postUpdate(myVariable) the Item will change to use the value of myVariable as it’s state.