Problem with exec binding: Format specifier '%2$s' error

Hi, I want to migrate from HC2 by adding devices through the API first, and then move z-wave devices gradually. I first tried to do this using the HTTP binding, but as far as I could understand, it did not work with POST data?

Next try was using the exec binding, where I made a script which forwards the values to HC2. The script works fine from the shell. This is the binding used:

Thing exec:command:hc2 [command="/home/pi/hc2_setvalue 28 %2$s"]

However, I get the following error:

[ERROR] [hab.binding.exec.handler.ExecHandler] - An exception occurred while formatting the command line with the current time and input values : 'Format specifier '%2$s''

Is this a bug, or some error on my end?

What is your item channel binding?

The last I tried was the one below. For me it seemed like the Thing was the error, I did not think to investigate the Item.

Dimmer Livingroom_TvLight [%s] { channel="exec:command:hc2:input" }

I was just thinking about making a HTTP get wrapper, if I don’t get further with this approach…

No, this happens if you never sent a Command to the input channel before. Once you send a first value to your Item, the error goes away

Thank you! That was not very intuitive, it threw me off as I expected something was wrong with the “Thing”. However, I never got it to work. Any pointers?

I just coded a small server in Python (it was time to learn some Python anyways :slight_smile: ) which listens on a TCP port and forwards the input to the HC2 API.

… just realized that it was probably not what I wanted, as openHAB sends HTTP request, not raw TCP data…

Still no luck. I tried to remove the %2$s parameter from the equation by making both parameters to the script constant, but from what I can see, it is not even executing when the item is changing (but it does three times when I save the .things file!).

Here is my configuration:

Dimmer Livingroom_TvLight [%s] { channel="exec:command:hc2:input" }
Thing exec:command:hc2 [command="/home/pi/hc2_setvalue 28 30" autorun=true]

When I save the file, I get the following errors, although it seems to return immediately from the command line:

20:05:19.886 [INFO ] [smarthome.event.ThingUpdatedEvent   ] - Thing 'exec:command:hc2' has been updated.
20:05:19.917 [INFO ] [smarthome.event.ThingUpdatedEvent   ] - Thing 'exec:command:hc2' has been updated.
20:05:19.955 [ERROR] [hab.binding.exec.handler.ExecHandler] - An exception occured while waiting for the process ('/home/pi/hc2_setvalue 28 30') to finish : 'null'
20:05:19.961 [WARN ] [hab.binding.exec.handler.ExecHandler] - Forcibly termininating the process ('/home/pi/hc2_setvalue 28 30') after a timeout of 15000 ms
20:05:19.982 [ERROR] [hab.binding.exec.handler.ExecHandler] - An exception occured while waiting for the process ('/home/pi/hc2_setvalue 28 30') to finish : 'null'
20:05:19.983 [WARN ] [hab.binding.exec.handler.ExecHandler] - Forcibly termininating the process ('/home/pi/hc2_setvalue 28 30') after a timeout of 15000 ms

I don’t know what’s happening when the .things file is saved, but the autorun=true only applies to item commands rather than state changes.

I have discovered that when autorun=true, the command gets sent periodically. However, changing the item through a sitemap does not trigger the command. Am I on the wrong path here? Could you maybe point me to an example with a sitemap -> item -> thing configuration for exec that gives the slider value as a parameter to the exec command?

Changing the item type to String seemed to do the trick! I also had to add a comma before autorun=true, now it works fine :smiley: I guess I should polish and publish this script.

That’s great. Are you still seeing the script being invoked periodically even without any command input? If so, you may need to add an interval=0 to the thing configuration.

Thanks for the suggestion, I’ll watch for it. Are there any place for publishing homemade scripts for OH2? I guess the wiki is mostly for OH1.

I don’t know of any place to publish OH2 user scripts and recipes (other than in the tutorial section of this forum), but maybe @ThomDietrich does.

Hi !

I installed the “Exec Binding (1.x)” instead of the “Exec Binding 2.0”. It works fine using the same .items file than in OpenHAB 1.8.3, without creating any .things file for that. Previously I activated the OH1.x compatibility layer.

Hi All,
I am having a really hard time with the exec2 binding. I have 2.1.0 configured with the demo setting (option selected right at the start), then i added the exec binding with a basic command to run and print the arguments it gets.

openhab> smarthome:items list | grep exec
exec_command_15de85cfbd2_output (Type=StringItem, State=NULL, Label=Output, Category=null)
exec_command_15de85cfbd2_input (Type=StringItem, State=a123b, Label=Input, Category=null)
exec_command_15de85cfbd2_exit (Type=NumberItem, State=NULL, Label=Exit Value, Category=null)
exec_command_15de85cfbd2_run (Type=SwitchItem, State=OFF, Label=Running, Category=null)
exec_command_15de85cfbd2_lastexecution (Type=DateTimeItem, State=NULL, Label=Last Execution, Category=null)

All the links are setup between the Thing and Items (i set the “simple” option to create them automatically).
Then I set the Input to “a123b”, and the command to:
/…/scripts/openhab ‘%1$s’ '%2$s’
As you can see, the input channel is setup.

Everything works find if I remove the ‘%2$s’ from the command, but if I add it in I get this error:

2017-08-15 20:07:12.902 [ERROR] [hab.binding.exec.handler.ExecHandler] - An exception occurred while formatting the command line with the current time and input values : ‘Format specifier ‘%2$s’’

Thanks for your help,
Paul