cURL command with Exec Binding doesn't send

I created a cURL command for sending a serial command to my HDMI matrix switch via a Global Cache iTach Flex adapter. I successfully tested the command via command line but I can’t get the Exec Binding to execute.

I created a switch as an item and added the Exec command as follows:
Switch Tv1Source1 “Family TV STB 1” {exec=“>[ON:curl -H “Content-Type: text/plain; charset=UTF-8” -X POST --data-binary “OUTPUT01 01;” \]" }

The logs indicate the item is getting the “on” command from the switch but no command is being sent to the device (as monitored from Docklight).

I am using Openhab2 and I installed the Exec binding via the Paper UI.

Can anyone offer me any pointers?

You may need to use the @@ separator instead of spaces - see

When working with Exec binding, I recommend using a rule and the executeCommandLine action so you can get what ever the command printed to stdout and stderr and log it. Once you get it working with executeCommandLine you can then transfer the call to an Exec binding if desired.

NOTE: there are two exeucteCommandLine actions, one that takes a timeout and one that doesn’t. You need to use the one that takes the timeout.


Thanks Rich, I tried creating a VERY basic rule but I’m new to creating anything other than the basics. Here is what I have

rule "HDMI Matrix - Output 1 Source 1"
Item TV1Source1 changed
executeCommandLine(curl@@-H@@“Content-Type:@@text/plain;@@charset=UTF-8”@@-X@@POST@@–data-binary@@“OUTPUT01@@01;”@@\, 5)

I found a small blurb about the executeCommandLine action for the time out. I added a number but I wasn’t able to find any context as to what the number will do for a timeout. What else do I add to get the stderr adn stdout messages logged?

I apologize for what are probably basic programming questions but I’m new to this end of the business and I can’t find any reference materials to help me bludgeon through getting this to work :slight_smile:

Any help you can provide would be greatly appreciated.

The number is in milliseconds. You are only giving the command five milliseconds to complete. That isn’t nearly enough time. You should be using something closer to 5 seconds (i.e. 5000).

The number represents the number of milliseconds OH will wait before giving up on the command completing. If the command completes before the time is up executeCommandLine will immediately return.


Update: After fiddling around with the executeCommandLine statement and the cURL syntax…I bailed out and created a Python script that worked flawlessly (and within about 5 minutes).

One issue I was having was the API for the Global Cache iTach Flex requires a “” right before the URL to the device. I could not figure out the right syntax so the “” character would register. Also the log showed that using @@ put comma’s between each statement. Either way, I was able to use the Python version of the API and call the script using the same executeCommandLine command. A bit more messy than I wanted (I have several units and hundreds of commands to create) but still functional.

Thank you for your help!

Don’t forget that you can pass command line arguments to your Python script. That might mage it somewhat easier.

Hi! I am not able to get this to work. This is the command that is working fine when run from command line:

curl --data-binary '{ "jsonrpc": "2.0", "method": "VideoLibrary.Scan", "id": "mybash"}' -H 'content-type: application/json;' http://kodi:@

And this ist the command I’m trying to execute within my rule:

executeCommandLine("curl@@--data-binary@@'{@@"jsonrpc":@@"2.0",@@"method":@@"VideoLibrary.Scan",@@"id":@@"mybash"}'@@-H@@'content-type:@@application/json;'@@http://kodi:@") (I replaced every space within the quotation marks with ‘@@’.)

When the rule is activated, I get the following error in the log:
[ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Kodi Rescan Video': An error occured during the script execution: The name 'jsonrpc' cannot be resolved to an item or type.

Any ideas?


You need to escape the quotes in the curl command using ".

You should probably also add a timeout to the call and print the results of the command in a log.

val results = executeCommandLine("curl@@--data-binary@@'{@@\"jsonrpc\":@@\"2.0\",@@\"method\":@@\"VideoLibrary.Scan\",@@\"id\":@@\"mybash\"}'@@-H@@'content-type:@@application/json;'@@http://kodi:@", 5000)

logInfo("Test", results)

There is also something fishey about the line above because the forum will not correctly format it. I would scrub the command very carefully to make sure all your single quotes are not back-tics and that all single and double quotes are matched.

1 Like

Hi Rich & thanks for your support!

I’ve got it working now by creating a shell script with the curl-command end executing that script from openHAB.

I don’t have the patience to fiddle around endlessly with escaping all the characters for openHAB and curl :-D. Thanks anyway for the advice!