Removing [ ] from a String

Hi all,

I 've a problem with a String-Item. The item get the values via curl from a txt-file.
curl -s -X PUT --header “Content-Type: text/plain” --header “Accept: application/json” -d “$i” "http://openhabianpi:8080/rest/items/VibSys_ETS10_
I need only a part of this value “[Vib-Sys_ETS-10]”.
How can I remove the square bracket? Do you have any ideas?

Many Thanks in advance
Dirk

Why curl instead of the HTTP binding?

You need to create a REGEX transform to only return the parts between the square brackets.

Hi Rich,

thanks for your answer.
Because I don’t have any experience with the http-binding.
I’m not a programmer and I don’t come from IT. I usually find the right scripts and try to adapt them and that was easy with curl :wink: Very much is try and error.
What could the call look like? The file is in the directory /home/pi/.
My script goes through the file line by line and pushed the content to the Openhab Rest interface.

Start with https://www.openhab.org/addons/bindings/http1/

The whole point is you don’t have to make the call. The binding will do it for you, either periodically or on command.

Hi Rich,
Thanks for the tip. I have now installed the HTML binding. Does the file to be read have to be in a certain directory? Do I need my script or does the binding do everything? I really don’t have a plan.

Thanks in advance
Dirk

The binding does what curl does. It fetches a url periodically (use the http cached config as described in the docs), or on demand (use an Item config as described in the docs).

Hi Rich,

now I’m one step further. But I get this error message. It works in the Online-Regex-Tester. Can you help me?
Thank you in advance
Dirk
Item :String Sascha_Test “Sascha test [%.1f ]” (gKabine) { http="<[http://192.168.10.122:8080/static/M1.txt:30000:REGEX(.*|\n)]" }

[ERROR] [el.item.internal.GenericItemProvider] - Binding configuration of type ‘http’ of item ‘Sascha_Test’ could not be parsed correctly.

org.eclipse.smarthome.model.item.BindingConfigParseException: bindingConfig '<[http://192.168.10.122:8080/static/M1.txt:30000:REGEX(.*|

)]’ doesn’t contain a valid binding configuration

at org.openhab.core.binding.internal.BindingConfigReaderDelegate.processBindingConfiguration(BindingConfigReaderDelegate.java:51) ~[?:?]

at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:397) ~[?:?]

at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:366) ~[?:?]

at org.eclipse.smarthome.model.item.internal.GenericItemProvider.processBindingConfigsFromModel(GenericItemProvider.java:229) ~[?:?]

at org.eclipse.smarthome.model.item.internal.GenericItemProvider.modelChanged(GenericItemProvider.java:432) ~[?:?]

at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.notifyListeners(ModelRepositoryImpl.java:301) ~[?:?]

at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:139) ~[?:?]

at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.checkFile(FolderObserver.java:227) ~[?:?]

at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.processWatchEvent(FolderObserver.java:291) ~[?:?]

at org.eclipse.smarthome.core.service.WatchQueueReader.lambda$3(WatchQueueReader.java:323) ~[?:?]

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]

at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:?]

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:?]

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]

at java.lang.Thread.run(Thread.java:748) [?:?]

Caused by: org.openhab.model.item.binding.BindingConfigParseException: bindingConfig '<[http://192.168.10.122:8080/static/M1.txt:30000:REGEX(.*|

)]’ doesn’t contain a valid binding configuration

at org.openhab.binding.http.internal.HttpGenericBindingProvider.parseBindingConfig(HttpGenericBindingProvider.java:143) ~[?:?]

at org.openhab.binding.http.internal.HttpGenericBindingProvider.processBindingConfiguration(HttpGenericBindingProvider.java:119) ~[?:?]

at org.openhab.core.binding.internal.BindingConfigReaderDelegate.processBindingConfiguration(BindingConfigReaderDelegate.java:49) ~[?:?]

... 16 more

The error states that your binding config on the item is malformed. The problem has nothing to do with the regex per se. Compare what you have with the examples in the docs and those you can find in this forum. You are missing something or have a steady character that needs to be escaped or something.

Hi Rich

thanks for your patient.
Now I have defined my 6 Items:

String VibSys_ETS10_1 “Name: " (gKabine) { http=”<[http://192.168.10.122:8080/static/Vib-Sys_ETS-10.sid:5000:REGEX(.(Vib-Sys_ETS-10).)]" }
String VibSys_ETS10_2 “Zuletzt aktualisiert " (gKabine) { http=”<[http://192.168.10.122:8080/static/Vib-Sys_ETS-10.sid:5000:REGEX(.Aktualisiert=(.).)]" }
String VibSys_ETS10_3 “Status” (gKabine) { http="<[http://192.168.10.122:8080/static/Vib-Sys_ETS-10.sid:5000:REGEX(.Status=(.).
)]" }
String VibSys_ETS10_4 “Modus: " (gKabine) { http=”<[http://192.168.10.122:8080/static/Vib-Sys_ETS-10.sid:5000:REGEX(.Mode=(.).)]" }
String VibSys_ETS10_5 “Zeit vergangen: " (gKabine) { http=”<[http://192.168.10.122:8080/static/Vib-Sys_ETS-10.sid:5000:REGEX(.Verstrichen=(.).
)]" }
String VibSys_ETS10_6 “Zeit verbleibend: " (gKabine) { http=”<[http://192.168.10.122:8080/static/Vib-Sys_ETS-10.sid:5000:REGEX(.Verbleibend=(.).*)]" }

Vib-Sys_ETS-10 .txt (125 Bytes)

and the the following widget:

The first and the last one contain the correct values, but the others contain the correct value + the complete rest of the text file.
I tested the Regex definition at https://regex101.com/ and it works there.


In my opinion the .* at the end is responsible for it, but without it the item gets no value.
Do you have an idea?

REGEX in openHAB have to match the full text and you use parens to express which part you want to return.

So your (.*) in OH means everything after “Aktualisiert=” which includes the whole rest of the text. You need to tell it to only get the text up to the end of the line. Something like:

.*Aktualisiert=(.*)\n.*

Hi Rich,

many thanks for your fast answer, but I get an error.
I have to do something wrong because as soon as I use a \ the color in the editor becomes bright yellow and the characters are ignored.


2019-03-05 17:08:57.523 [ERROR] [el.item.internal.GenericItemProvider] - Binding configuration of type ‘http’ of item ‘Sascha_Test’ could not be parsed correctly.

org.eclipse.smarthome.model.item.BindingConfigParseException: bindingConfig '<[http://192.168.10.122:8080/static/Vib-Sys_ETS-10.sid:5000:REGEX(.Aktualisiert=(.)

.*)]’ doesn’t contain a valid binding configuration

at org.openhab.core.binding.internal.BindingConfigReaderDelegate.processBindingConfiguration(BindingConfigReaderDelegate.java:51) ~[?:?]

at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:397) ~[?:?]

at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:366) ~[?:?]

at org.eclipse.smarthome.model.item.internal.GenericItemProvider.processBindingConfigsFromModel(GenericItemProvider.java:229) ~[?:?]

at org.eclipse.smarthome.model.item.internal.GenericItemProvider.modelChanged(GenericItemProvider.java:432) ~[?:?]

at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.notifyListeners(ModelRepositoryImpl.java:301) ~[?:?]

at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:139) ~[?:?]

at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.checkFile(FolderObserver.java:227) ~[?:?]

at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.processWatchEvent(FolderObserver.java:291) ~[?:?]

at org.eclipse.smarthome.core.service.WatchQueueReader.lambda$3(WatchQueueReader.java:323) ~[?:?]

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]

at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:?]

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:?]

Caused by: org.openhab.model.item.binding.BindingConfigParseException: bindingConfig '<[http://192.168.10.122:8080/static/Vib-Sys_ETS-10.sid:5000:REGEX(.Aktualisiert=(.)

.*)]’ doesn’t contain a valid binding configuration

at org.openhab.binding.http.internal.HttpGenericBindingProvider.parseBindingConfig(HttpGenericBindingProvider.java:143) ~[?:?]

at org.openhab.binding.http.internal.HttpGenericBindingProvider.processBindingConfiguration(HttpGenericBindingProvider.java:119) ~[?:?]

at org.openhab.core.binding.internal.BindingConfigReaderDelegate.processBindingConfiguration(BindingConfigReaderDelegate.java:49) ~[?:?]

You may need to double escape the newline.

\\n

thanks a lot Rich, this was the right way. This is the right definition:
grafik

Have a nice evening