Hello @banzaay I double-checked my typo “substringBetween” but I’m unfortunately not able to use the function “substringBetween” in my Rules after the upgrade from openab 2.5 to openhab 3.0. What did you configure to use the org.apache.commons.lang.StringUtils package and it’s function substringBetween? Thanks a lot!
I have a rule that stat with a custom commad where I pass some information to add in a mail.
On 2.5 I have substringBetween:
val String object = receivedCommand.toString.substringBetween("(",")")
val String message = receivedCommand.toString.substringBetween("[","]")
Now on 3.0 I have moved to function String.split:
val String[] receivedCommandSplit = receivedCommand.toString.split("#")
val String object = receivedCommandSplit.get(0)
val String message = receivedCommandSplit.get(1)
SOLVED:
I’m reading periodially my power-meter and want to parse the different measures to different items. As the result is in one String I have to parse the string an read values that are between the ID and in this case “kWh”.
I’m interested in the kWh of the current day which are here in the ID’s 1.8.1(00001821.483kWh) and 1.8.2(00001321.076kWh)
to get only the consumed energy 00001821.483 and 00001321.076, I wrote the following lambda Function:
val Functions$Function3<String, String, String, String> getTextBetween = [
String text,
String textFrom,
String textTo |
var result = "";
// Cut the beginning of the text to not occasionally meet a
// 'textTo' value in it:
result =
text.substring(
text.indexOf(textFrom) + textFrom.length(),
text.length())
// Cut the excessive ending of the text:
result =
result.substring(
0,
result.indexOf(textTo))
return result
]
so now I can read the power-meter and apply the lambda-function:
var energyNT = Double::parseDouble(getTextBetween.apply(meter_payload,"1.8.1(", "*kWh)"))
var energyHT = Double::parseDouble(getTextBetween.apply(meter_payload,"1.8.2(", "*kWh)"))
and have then the desired values energyNT= 1821.483 and energyHT=1321.076.
Just for those looking for a replacment of the substringBetween() function.