Problems on long http request in rules


I want to use Openhab to trigger an action-recording on a synology Surveillance Station depending on the state of a moving-detection sensor. The trigger is a http request like that:"Trigger"&version=1&eventId=1&eventName="This is external event1"&account="{account}"&password="{password}"

I have big problems to generate this http String in openhab. My first try was using of sendHttpPostRequest and URLEncoder::encode. So I did this:

		var String entry = "" + URLEncoder::encode("SYNO.SurveillanceStation.ExternalEvent", 'UTF-8')
		var String method = "method=" + URLEncoder::encode("\"Trigger\"", 'UTF-8')
		var String version = "version=1"
		var String eventId = "eventId=1"
		var String eventName = "eventName=" + URLEncoder::encode("\"Bewegung_Eingang\"", 'UTF-8')
		var String account = "account=" + URLEncoder::encode("\"account \"", 'UTF-8')
		var String password = "password=" + URLEncoder::encode("\"password \"", 'UTF-8')
		var String escape = "&"
		logInfo( "FILE", "Trigger:"  + entry + escape + method + escape + version + escape + eventId + escape + eventName + escape + account + escape + password)
		var String out = sendHttpPostRequest(entry + escape + method + escape + version + escape + eventId + escape + eventName + escape + account + escape + password)
		logInfo( "FILE", out)

This is genering that http String:

This string works inside of a browser and in the systems console (curl) but not in Openhab. The return value from synology is an error, code 101. It seems it is not correctly sending the %22 (") chars. But they have definitly be there because without and with an escape of " as ("\"") sendHttpPostRequest is not accepting it.
Ok, so I thought I will use the http binding as next. So I created an Item:

Switch DSTrigger1 		"Diskstation Trigger 1"	(gSecurity) { http=">[ON:POST:]"}

But this is not working, too. I get the exception:

`2020-05-03 19:09:41.131 [WARN ] [] - EventAdmin: Exception during event dispatch [org.osgi.service.event.Event [topic=openhab/command/DSTrigger1] {item=DSTrigger1, bridgemarker=true, command=ON, timestamp=1588525781129} | {, org.osgi.service.event.EventHandler}={, service.bundleid=226, service.scope=bundle, event.topics=openhab/*,,,} | Bundle(org.openhab.binding.http_1.14.0 [226])]
java.util.UnknownFormatConversionException: Conversion = '2'
        at java.util.Formatter.checkText( ~[?:1.8.0_212]
        at java.util.Formatter.parse( ~[?:1.8.0_212]
        at java.util.Formatter.format( ~[?:1.8.0_212]
        at java.util.Formatter.format( ~[?:1.8.0_212]
        at java.lang.String.format( ~[?:1.8.0_212]
        at org.openhab.binding.http.internal.HttpBinding.formatAndExecute( ~[?:?]
        at org.openhab.binding.http.internal.HttpBinding.internalReceiveCommand( ~[?:?]
        at org.openhab.core.binding.AbstractBinding.receiveCommand( ~[?:?]
        at ~[?:?]
        at org.apache.felix.eventadmin.impl.handler.EventHandlerProxy.sendEvent( [bundleFile:?]
        at org.apache.felix.eventadmin.impl.tasks.HandlerTask.runWithoutBlacklistTiming( [bundleFile:?]
        at org.apache.felix.eventadmin.impl.tasks.SyncDeliverTasks.execute( [bundleFile:?]
        at org.apache.felix.eventadmin.impl.tasks.AsyncDeliverTasks$ [bundleFile:?]
        at java.util.concurrent.Executors$ [?:1.8.0_212]
        at [?:1.8.0_212]
        at java.util.concurrent.ThreadPoolExecutor.runWorker( [?:1.8.0_212]
        at java.util.concurrent.ThreadPoolExecutor$ [?:1.8.0_212]
        at [?:1.8.0_212]

It seems this binding is interpreting the %22 as replacement for a " as a float value…

The only working solution now is this:


But I don’t really like it because I cannot see any return json code and it somehow strange to use a executeCommandLine for sending of a http reqest.

So my question is, how is this possible send this html code to synology without executeCommandLine and the EXEC Binding? Do you have some ideas?


Probably you need to use ‘%%’ as your ‘%2’ is being taken as a formatting sequence.

Are you sure you want to use the sendHttpPostRequest? Seems like that should be sendHttpGetRequest. It looks like a GET, not a POST.

HTTP binding trying to interpret your % as parameter substitution,like %2, you’d need to escape those.

You didn’t ask for any.
val response = executeCommandLine('curl ...)