REGEX - Help

Hey All,

I need some help with my REGEX.
I have the following item:

Switch Mute_Item "Mute_Item"			{ http=">[ON:GET:http://SPEAKER_IP/UIC?cmd=%3Cname%3ESetMute%3C/name%3E%3Cp%20type=%22str%22%20name=%22mute%22%20val=%22on%22/%3E] >[OFF:GET:http://SPEAKER_IP/UIC?cmd=%3Cname%3ESetMute%3C/name%3E%3Cp%20type=%22str%22%20name=%22mute%22%20val=%22off%22/%3E] <[http://SPEAKER_IP/UIC?cmd=%3Cname%3EGetMute%3C/name%3E:5000:REGEX(<mute>(.*?)<\/mute>)]" }

With this item I can read and write the mute state of my wireless speaker.
The item file will give the following error:

19:10:16.452 [WARN ] [del.core.internal.ModelRepositoryImpl] - Configuration model 'Items.items' has errors, therefore ignoring it: [12,52]: mismatched character '/' expecting set null
[12,413]: mismatched input 'mute' expecting RULE_STRING
[14,1]: mismatched input '<EOF>' expecting '}'

When I remove the REGEX part, the item file is loaded.
Weird, because the regular expression is right and tested with https://regexr.com/

When I don’t escape the ‘/’ before mute (as the example of the http binding says), the item file is loaded but the the HTTP binding gives the following error:

19:09:57.872 [ERROR] [ab.core.service.AbstractActiveService] - Error while executing background thread HTTP Refresh Service
java.util.IllegalFormatConversionException: c != java.util.Date
        at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4302) [?:?]
        at java.util.Formatter$FormatSpecifier.printCharacter(Formatter.java:2869) [?:?]
        at java.util.Formatter$FormatSpecifier.print(Formatter.java:2757) [?:?]
        at java.util.Formatter.format(Formatter.java:2520) [?:?]
        at java.util.Formatter.format(Formatter.java:2455) [?:?]
        at java.lang.String.format(String.java:2940) [?:?]
        at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:144) [266:org.openhab.binding.http:1.12.0]
        at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:144) [209:org.openhab.core.compat1x:2.3.0]
        at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:166) [209:org.openhab.core.compat1x:2.3.0]

I hope someone has a solution.

  • Jordo

Firstly, if the HTTP binding works like the MQTT binding, you need to match the whole HTML document.

.*<mute>(.*?)</mute>.*

You do not need to escape a /.

Next, is the text between the mute tags always ON or OFF (case matters)? If then they are not appropriate for a Switch Item.

Finally, the error doesn’t have anything to do with this Item. This error appears to be for a DateTime Item, not a Switch and the error is telling you that “c” is not an appropriate date time string.

Thanks foy your reply!

Hmm, that makes sense, i’ll change that.

Yes, the reply is always on or off, but not with capital letters.
So maybe that is a problem?

That is weird, the error only occures when this item is added to the item file.
I can’t find where it could come from then.

  • Jordo

That is A problem. I can’t say whether it is THE problem. The error is talking about a DateTime, not a Switch.

Do you have any DateTime Items populated by the HTTP binding?

Not that I know…
But I will check it.
Hope that I can find the fault :slight_smile:
Otherwise I will use a rule instead.

Thanks for helping!

  • Jordo