I am working on setting up openhab2 on Ubuntu server 16.04 with the Zulu JVM. I am attempting to use the exec addon binding to run a python script. However I am having trouble getting the state of my Color item type into the command line arguments. Viewing the openhab.log file I find the following error,
2017-08-29 23:50:27.540 [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''
At the bottom of my openhab start page it says, openHAB 2.1.0 - release build -.
Looking at the Exec binding code, namely this file,
There is a line which exactly matches the error received. It is from the following block of code,
try {
if (lastInput != null) {
commandLine = String.format(commandLine, Calendar.getInstance().getTime(), lastInput);
} else {
commandLine = String.format(commandLine, Calendar.getInstance().getTime());
}
} catch (IllegalFormatException e) {
logger.error(
"An exception occurred while formatting the command line with the current time and input values : '{}'",
e.getMessage());
updateState(RUN, OnOffType.OFF);
return;
}
From this I am wondering lastInput starts out as null so the if condition is not met. Therefore commandLine = String.format(commandLine, Calendar.getInstance().getTime()); is run, and %2$s clearly does not exist, as only one argument is given to format(). I wonder if this would work better if the if condition was not used and allow null to be passed to the external program.
I’ll ask back how did plan on using Sunrise as the argument to your script in the first place? That is what the input channel is for.
You can put it on your sitemap with a Color element and choose a Color.
Create a rule and postUpdate an HSBType to Sunrise.
But given the whole purpose of input channel is to pass arguments to your script I assumed you already figured out how you want to populate the Item linked to the input channel.
I currently have it set up in a .items file shown in my original post. This appears in the PaperUI. It is set up with autorun=true so whenever the Color item is changed the script is run. I can tell that this should be working because when I change the color I get the same error in the openhab.log file again.
You have autorun=true and interval=1 in your Thing which means that the script is executed every second in addition to being run every time the Color Item is updated.
If you are changing the Color Item then that Item isn’t NULL.