The OP implied a question about why the REGEX service (Is that the right word? Three days new to OpenHAB…) returns the whole string with an erroneous REGEX.
I’d like to expand on that question and ask, Why does OpenHAB update the item with the whole the string if the REGEX fails a match, and is there a way around it? (To the OP’s implied question, as best I can tell, a faulty REGEX which can’t be parsed causes a parse error in the openhab.log
file.)
My problematic use case involves the use of a Grid Insight AMRUSB-1 utility meter data receiver and my net meter, which reports as if it had three serial numbers. The strings look like this:
$UMSCM,12346668,8,41369*62
$UMSCM,12346669,8,18905*6F
$UMSCM,12346670,8,22463*63
My matches look like this:
String UtilityMeter68 "Power Meter 68" { serial="/dev/ttyACM0,REGEX(.*68,[0-9],([0-9]*).*)" }
String UtilityMeter69 "Power Meter 69" { serial="/dev/ttyACM0,REGEX(.*69,[0-9],([0-9]*).*)" }
String UtilityMeter70 "Power Meter 70" { serial="/dev/ttyACM0,REGEX(.*70,[0-9],([0-9]*).*)" }
which returns the last numeric group, meter reading (kWh*100), which I want to display for now, then maybe store someday.
Anyway, when one of the strings above arrives from the Grid Insight, all three attempt the match, and the one which matches is modified correctly. The other two, however, are updated incorrectly with the entire string, like so:
2015-12-31 20:50:14 - UtilityMeter70 state updated to $UMSCM,12346668,8,41369*62
2015-12-31 20:50:14 - UtilityMeter69 state updated to $UMSCM,12346668,8,41369*62
2015-12-31 20:50:14 - UtilityMeter68 state updated to 41369
I haven’t done any further processing with the data, but I imagine I’ll have to do something pretty major to update the sitemap with only the correctly-updated value because of what I perceive to be a not-great behavior of the serial REGEX service.
Any clues, anybody, on how to get around this problem?
Thanks,
Bill