I’m running openhab on a windows 10 PC and I want to run a batch command file from habpanel. I’ve set the Thing and Items configs this way
Things:
Thing exec:command:pbalogo [ comand=“C:\PBAplay.bat %1”, interval=0 , autorun=true ]
This is what is in the event log:
2019-07-16 15:13:57.342 [ome.event.ItemCommandEvent] - Item ‘pbalogo_file’ received command “C:\DOCS\PBALogo.mp4”
2019-07-16 15:13:57.344 [nt.ItemStatePredictedEvent] - pbalogo_file predicted to become NULL
The command to the send file name to the pba_logo item is working but how does it start the send command item pbalogo
“C:\DOCS\PBALogo.mp4” is not a command. It is not executable , so it has no (NULL) output. IT appears OH is trying to execute the mp4 with the batch file as a parameter?
Just a newbie guess.
That’s fine, Item ‘pbalogo_file’ is a String type and you can send it any string you like as a command.
The ‘prediction’ in the events.log comes from autoupdate, we can ignore that.
Okay, so we get a command string arrive at pbalogo_file. That is linked to the exec binding input channel. You have autorun=true set in the Thing, so the arrival of this command should trigger exec.
What should happen next is that exec will change the state of the Switch Item pbalogo, which is linked to the run channel, to ON, to say it is running. No sign of that in your events.log. So exec isn’t running.
Have you fixed that typo in your Thing yet?
Please post your Thing definition in code fences
It’s the opposite. You define the batch filename in the exec binding Thing, and may then send extra parameters like “banana” via the input channel. In this case, the parameter is a filename but exec don’t care.
Then, you’ll need to fix your parameter.
As per the exec binding docs, using %1 is about inserting current date and time.
If instead you want to use the input channel command as a parameter, then you must use %2. As you want it as a string, you’d use format $s
So, together %2$s
Fixed the typo, now its trying to process the command and shows this error on the openhab.log
2019-07-17 17:50:58.038 [ERROR] [hab.binding.exec.handler.ExecHandler] - An exception occurred while formatting the command line with the current time and input values : ‘Conversion = ‘1’’
Event log:
2019-07-17 17:50:58.022 [ome.event.ItemCommandEvent] - Item ‘pbalogo_file’ received command “C:\DOCS\PBALogo.mp4”
2019-07-17 17:50:58.032 [nt.ItemStatePredictedEvent] - pbalogo_file predicted to become “C:\DOCS\PBALogo.mp4”
2019-07-17 17:50:58.041 [vent.ItemStateChangedEvent] - pbalogo_file changed from NULL to “C:\DOCS\PBALogo.mp4”
2019-07-17 17:50:58.046 [vent.ItemStateChangedEvent] - pbalogo changed from NULL to ON
2019-07-17 17:50:58.048 [vent.ItemStateChangedEvent] - pbalogo changed from ON to OFF
in the example in the exec bind doc it shows the parm as %2$s in the Things, is this some form of formatting for the parm.
message in event log
2019-07-17 18:42:48.779 [ome.event.ItemCommandEvent] - Item ‘pbalogo_file’ received command “C:\DOCS\PBALogo.mp4”
2019-07-17 18:42:48.786 [nt.ItemStatePredictedEvent] - pbalogo_file predicted to become “C:\DOCS\PBALogo.mp4”
2019-07-17 18:42:48.789 [vent.ItemStateChangedEvent] - pbalogo_file changed from “C:\DOCS\PBALogo.mp4” to “C:\DOCS\PBALogo.mp4”
2019-07-17 18:42:48.790 [vent.ItemStateChangedEvent] - pbalogo changed from OFF to ON
2019-07-17 18:42:48.900 [vent.ItemStateChangedEvent] - pbalogo changed from ON to OFF
2019-07-17 18:42:48.779 [ome.event.ItemCommandEvent] - Item ‘pbalogo_file’ received command “C:\DOCS\PBALogo.mp4”
2019-07-17 18:42:48.786 [nt.ItemStatePredictedEvent] - pbalogo_file predicted to become “C:\DOCS\PBALogo.mp4”
2019-07-17 18:42:48.789 [vent.ItemStateChangedEvent] - pbalogo_file changed from “C:\DOCS\PBALogo.mp4” to “C:\DOCS\PBALogo.mp4”
2019-07-17 18:42:48.790 [vent.ItemStateChangedEvent] - pbalogo changed from OFF to ON
2019-07-17 18:42:48.900 [vent.ItemStateChangedEvent] - pbalogo changed from ON to OFF
2019-07-17 18:42:48.779 [ome.event.ItemCommandEvent] - Item 'pbalogo_file' received command "C:\\DOCS\\PBALogo.mp4"
2019-07-17 18:42:48.786 [nt.ItemStatePredictedEvent] - pbalogo_file predicted to become "C:\\DOCS\\PBALogo.mp4"
2019-07-17 18:42:48.789 [vent.ItemStateChangedEvent] - pbalogo_file changed from "C:\DOCS\PBALogo.mp4" to "C:\\DOCS\\PBALogo.mp4"
2019-07-17 18:42:48.790 [vent.ItemStateChangedEvent] - pbalogo changed from OFF to ON
2019-07-17 18:42:48.900 [vent.ItemStateChangedEvent] - pbalogo changed from ON to OFFyour code goes here
2019-07-17 21:58:06.543 [ome.event.ItemCommandEvent] - Item 'pbalogo_file' received command "C:\\DOCS\\PBALogo.mp4"
2019-07-17 21:58:06.551 [nt.ItemStatePredictedEvent] - pbalogo_file predicted to become "C:\\DOCS\\PBALogo.mp4"
2019-07-17 21:58:06.557 [vent.ItemStateChangedEvent] - pbalogo_file changed from NULL to "C:\\DOCS\\PBALogo.mp4"
2019-07-17 21:58:06.559 [vent.ItemStateChangedEvent] - pbalogo changed from NULL to ON
2019-07-17 21:58:06.646 [vent.ItemStateChangedEvent] - pbalogo changed from ON to OFF
Yes, that is exactly what we expect to see in events log.
The command comes in from your habpanel.
Exec binding turns pbalogo ON then OFF as it runs the script.
Job finished.
You don’t tell us, but is it not working still? With no clues in openhab.log I would guess everything on the exec binding side is working normally…
What does your batch script do if it gets a nonsense parameter? Does Windows give us permission to run it?
Sometimes you can gain more info by temporarily using the exec action in a rule - because you can get a result to look at
rule "testing batch"
when
Item pbalogo_file received command
then
var execresult = executeCommandLine( "C:\\openhab2\\conf\\scripts\\PBAplay.bat C:\\DOCS\\PBALogo.mp4", 3000)
logInfo("test". "result: " + execresult
end