REGEX transformation - please help!

Hello,

I am trying to get some values from my Smappee using the local API. Ill post the solution once I am done.

Im getting stuck with the REGEX part. From items/default.items:

String Smappee_Voltage "Value:[%s]" { http="<[smappeeCache:1000:REGEX(.*?voltage=(.*?) Vrms)]"}
String Smappee_Voltage_Test "Value:[%s]" { http="<[smappeeCache:1000:REGEX((.*))]"}

From CLI:

openhab> smarthome:status Smappee_Voltage
null
openhab> smarthome:status Smappee_Voltage_Test
{"report":"Instantaneous values:<BR>voltage=229.6 Vrms<BR>FFTComponents:<BR>Phase 1:<BR>\tcurrent=3.156 A, activePower=506.917 W, reactivePower=518.296 var, apparentPower=724.98 VA, cosfi=69, quadrant=0, phaseshift=0.0, phaseDiff=0.0<BR>\tFFTComponents:<BR>Phase 2:<BR>\tcurrent=4.757 A, activePower=842.494 W, reactivePower=695.908 var, apparentPower=1092.742 VA, cosfi=77, quadrant=0, phaseshift=0.0, phaseDiff=0.0<BR>\tFFTComponents:<BR>Phase 3:<BR>\tcurrent=3.309 A, activePower=518.838 W, reactivePower=555.68 var, apparentPower=760.246 VA, cosfi=68, quadrant=0, phaseshift=0.0, phaseDiff=0.0<BR>\tFFTComponents:<BR><BR><BR>Phase 1, peak active power 13678.86 W at 23/03/2016 18:23:50<BR>Phase 2, peak active power 12112.266 W at 29/12/2015 18:48:10<BR>Phase 3, peak active power 13926.443 W at 24/12/2016 15:49:25<BR>active energy RMS per phase mapping combination<BR>phase mapping 210=970.815 kWh [* -1/3]<BR>phase mapping 12=4326.499 kWh [ 1/1]<BR>phase mapping 21=857.74 kWh [ -1/2]<BR>phase mapping 102=968.657 kWh [ 1/0]<BR>phase mapping 120=5779.68 kWh [ -1/2]<BR>phase mapping 201=2534.757 kWh [ -1/2]<BR><BR>active energy RMS (solar) per phase mapping combination<BR>phase mapping 210=0.0 kWh [* -1/3]<BR>phase mapping 12=0.0 kWh [ 1/1]<BR>phase mapping 21=0.0 kWh [ -1/2]<BR>phase mapping 102=0.0 kWh [ 1/0]<BR>phase mapping 120=0.0 kWh [ -1/2]<BR>phase mapping 201=0.0 kWh [ -1/2]<BR><BR>"}
openhab>

But using https://regex101.com I get what I expected in group 1:

Group 1. 44-49 229.6

I seem to be missing something pretty basic!

Thanks in advance.

IIRC (and I could be wrong), the REGEX transformation must match the entire string. I’d at least try adding a .* to the end of the pattern.

Paul,

If I recall correctly, the REGEX transform brackets the regular expression supplied inside ‘(’ and ‘)’ with ‘^’ and ‘$’. That means your regular expression must match the entire line.

Give this a try:

String Smappee_Voltage "Value:[%s]" { http="<[smappeeCache:1000:REGEX(.*?voltage=(\\d+\\.\\d+) Vrms.*)]"}

I’m not in a position to try this at the moment, so the doubled \s may be wrong. What you’re after is ‘\d’.

You are correct. adding the .* sorted it.

Would propose to improve:

http://docs.openhab.org/addons/transformations/regex/readme.html#examples

Giving the advice for people to try RegEx on www.regex101.com (or similar) and add the ^expression$ to test.

In my case:

^.*?voltage=(.*?) Vrms.*$

Thanks for your quick reply!

Thanks Scott.

This did it:

String Smappee_Voltage "Value:[%s]" { http="<[smappeeCache:1000:REGEX(.*?voltage=(.*?) Vrms.*)]"}

As an aside regarding changing the value to a Number. This seems to work fine too:

Number Smappee_Voltage "Voltage[%.1f Vrms]" { http="<[smappeeCache:1000:REGEX(.*?voltage=(.*?) Vrms.*)]"}