Can not parse input relay6ON to match command OFF on item Light_Test the given regular expression '^relay6ON$' doesn't contain a group. No content will be extracted and returned! Can not parse input relay6ON to match command ON on item Light_Test
And the same for the relay6OFF command received.
Why does it read the “^” at the beginning and the “$” at the end?
If in the item file I use dounble brackets for the REGEX:
A string like “relay6ON” cannot be converted to an OnOffType. The extra parentheses in a REGEX transformation are a regular expression match group. Only the matched group will be returned from the REGEX transformation. In your case, REGEX(relay6(ON)) and REGEX(relay6(OFF)) should work. See Java regex documentation for more details.
Thanks Steve for your prompt reply.
I’ll go studying the Java regex documentatio.
In the meanwhile your suggestion works even if in the log I see rivers of errors whenever a UDP commands arrive to OH:
2016-01-04 16:19:43.733 [WARN ] [t.protocol.internal.UDPBinding] - Can not parse input relay6ON to match command OFF on item Light_Test 2016-01-04 16:19:43.744 [ERROR] [t.protocol.internal.UDPBinding] - transformation throws exception [transformation=null, response=relay6ON] java.lang.NullPointerException: null at java.util.regex.Matcher.getTextLength(Matcher.java:1283) ~[na:1.8.0] at java.util.regex.Matcher.reset(Matcher.java:309) ~[na:1.8.0] at java.util.regex.Matcher.<init>(Matcher.java:229) ~[na:1.8.0] at java.util.regex.Pattern.matcher(Pattern.java:1093) ~[na:1.8.0] at org.openhab.binding.tcp.protocol.internal.UDPBinding.splitTransformationConfig(UDPBinding.java:236) [bundlefile:na] at org.openhab.binding.tcp.protocol.internal.UDPBinding.transformResponse(UDPBinding.java:254) [bundlefile:na] at org.openhab.binding.tcp.protocol.internal.UDPBinding.parseBuffer(UDPBinding.java:150) [bundlefile:na] at org.openhab.binding.tcp.AbstractDatagramChannelBinding.parseChanneledBuffer(AbstractDatagramChannelBinding.java:998) [bundlefile:na] at org.openhab.binding.tcp.AbstractDatagramChannelBinding.execute(AbstractDatagramChannelBinding.java:1505) [bundlefile:na] at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:156) [org.openhab.core_1.7.1.jar:na] at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:173) [org.openhab.core_1.7.1.jar:na]
Hi Andrea
Sorry for that.
Even if the expression is correct (will return either ON or OFF depending on the response), I must admit that I haven’t used Regexp in Openhab myself. So there might be another problem.
It’s not clear to me that this is the problem with spaces vs. commas between binding subconfigs. Are there any errors in the log? Which binding version is being used?
The incoming parts do not begin with ON or OFF (see the example at the bottom of the wiki page). Also, the incoming parts have to result in strings ON or OFF in order to update a Switch item. Your REGEX transformations do not capture the input, and even if they did (by doing REGEX((.*value 30.*)) for example), they don’t result in an ON or OFF. If the complete incoming message is the same every time, you might be able to use a MAP transformation like
lightMap.map
ON=value 30
OFF=value 0
but that would have to be the entire incoming message. Another alternative would be to use a JavaScript transformation, where you can have more logic in what produces the ON or OFF you’re after. Something like
lightValue.js:
(function(str){
if (str.includes("value 30")) return "ON";
if (str.includes("value 0")) return "OFF";
return "UNDEF";
})(input)