Hi,
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:
http://192.168.1.10:5000/webapi/entry.cgi?api=SYNO.SurveillanceStation.ExternalEvent&method="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 = "http://192.168.1.10:5000/webapi/entry.cgi?api=" + 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:
http://192.168.1.10:5000/webapi/entry.cgi?api=SYNO.SurveillanceStation.ExternalEvent&method=%22Trigger%22&version=1&eventId=1&eventName=%22Bewegung_Eingang%22&account=%22account%22&password=%22password%22
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:http://192.168.1.10:5000/webapi/entry.cgi?api=SYNO.SurveillanceStation.ExternalEvent&method=%22Trigger%22&version=1&eventId=1&eventName=%22Bewegung_Eingang%22&account=%22account%22&password=%22password%22]"}
But this is not working, too. I get the exception:
`2020-05-03 19:09:41.131 [WARN ] [org.apache.karaf.services.eventadmin] - 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.cm.ManagedService, org.osgi.service.event.EventHandler}={service.id=379, service.bundleid=226, service.scope=bundle, event.topics=openhab/*, service.pid=org.openhab.http, component.name=org.openhab.binding.http, component.id=13} | Bundle(org.openhab.binding.http_1.14.0 [226])]
java.util.UnknownFormatConversionException: Conversion = '2'
at java.util.Formatter.checkText(Formatter.java:2579) ~[?:1.8.0_212]
at java.util.Formatter.parse(Formatter.java:2555) ~[?:1.8.0_212]
at java.util.Formatter.format(Formatter.java:2501) ~[?:1.8.0_212]
at java.util.Formatter.format(Formatter.java:2455) ~[?:1.8.0_212]
at java.lang.String.format(String.java:2940) ~[?:1.8.0_212]
at org.openhab.binding.http.internal.HttpBinding.formatAndExecute(HttpBinding.java:294) ~[?:?]
at org.openhab.binding.http.internal.HttpBinding.internalReceiveCommand(HttpBinding.java:147) ~[?:?]
at org.openhab.core.binding.AbstractBinding.receiveCommand(AbstractBinding.java:97) ~[?:?]
at org.openhab.core.events.AbstractEventSubscriber.handleEvent(AbstractEventSubscriber.java:49) ~[?:?]
at org.apache.felix.eventadmin.impl.handler.EventHandlerProxy.sendEvent(EventHandlerProxy.java:415) [bundleFile:?]
at org.apache.felix.eventadmin.impl.tasks.HandlerTask.runWithoutBlacklistTiming(HandlerTask.java:82) [bundleFile:?]
at org.apache.felix.eventadmin.impl.tasks.SyncDeliverTasks.execute(SyncDeliverTasks.java:104) [bundleFile:?]
at org.apache.felix.eventadmin.impl.tasks.AsyncDeliverTasks$TaskExecuter.run(AsyncDeliverTasks.java:166) [bundleFile:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_212]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_212]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_212]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_212]
at java.lang.Thread.run(Thread.java:748) [?: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:
executeCommandLine('curl http://192.168.1.10:5000/webapi/entry.cgi?api=SYNO.SurveillanceStation.ExternalEvent&method=%22Trigger%22&version=1&eventId=1&eventName=%22Bewegung_Eingang%22&account=%22account%22&password=%22password%22',5000)
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?
Greetings
Markus