Transform with REGEX in rules

Hello,

I’m new in openhab2.

I have installed a tasmota sonoff rf bridge. Everything works well with MQTT.

But within my rules I have a problem, maybe anyone can help me.

rule "RF Bridge sensor triggered"
when
    Item RF_BRIDGE received update
then
    logInfo("tasmota-rf", "received command: {}", RF_BRIDGE.state.toString)
    val String stateNew = transform("REGEX", ".*(\\d{50}).*", RF_BRIDGE.state.toString)
    logInfo("tasmota-rf", "transform: {}", stateNew)
end

The log looks like:

[INFO ] [se.smarthome.model.script.tasmota-rf] - received command: AA B1 03 0122 03DE 26FC 28190819090908190909081908190818181818181818190908 55
[INFO ] [se.smarthome.model.script.tasmota-rf] - transform: AA B1 03 0122 03DE 26FC 28190819090908190909081908190818181818181818190908 55

My target is to extract the String “28190819090908190909081908190818181818181818190908” from “AA B1 03 0122 03DE 26FC 28190819090908190909081908190818181818181818190908 55”. A test with https://regexr.com/ works fine.

What’s wrong? :-/

Thanks
Caesium

Try giving it more hints.

.*\\s(\\d{50})\\s.*

Thanks for reply. That does not help :frowning:

That’s odd, it works for me

then
    val String source="AA B1 03 0122 03DE 26FC 28190819090908190909081908190818181818181818190908 55"
    logInfo("tasmota-rf", "data [" + source + "]")
    val String stateNew = transform("REGEX", ".*\\s(\\d{50})\\s.*", source)
    logInfo("tasmota-rf", "transform: {}", stateNew)
end
2020-03-17 21:25:25.055 [INFO ] [se.smarthome.model.script.tasmota-rf] - data [AA B1 03 0122 03DE 26FC 28190819090908190909081908190818181818181818190908 55]
2020-03-17 21:25:25.057 [INFO ] [se.smarthome.model.script.tasmota-rf] - transform: 28190819090908190909081908190818181818181818190908

Have you installed the REGEX transformation service?

1 Like

Thank you very much! This was it!