How to launch script from Windows batch file

I’m new to OpenHAB, and I’m trying to figure out how to run a script via a Windows batch file.

I have a very simple script (C:\openHAB\conf\scripts\MiniplugOff.script):

if (itemRegistry.getItem('Miniplug1').getState() != 'ON') {
events.sendCommand('Miniplug1', 'ON');

It works when I run it from the web interface. Is there a way to run it from a Windows command prompt (or, equivalently, a batch file?)?

I’ve got OpenHAB set up and running as a service.

  • Platform information:
    • OS: Windows 10
    • Java Runtime Environment: Zulu 11.50.19 (11.0.12)
    • openHAB version: 3.1.0

What would you like to achieve ?
It is possible to run ‘something’ from the Windows command line in a batch file or from within Powershel but to do the same as described in your example you then would have to access the REST API ( openHAB REST API | openHAB ) e.g. to get the items’s state and to set a new value.
But this answer may not match in case you would like to do something complete different.

More specifically, I’d like to run the script to turn on a smart plug when windows comes out of sleep (with a trigger in Task Scheduler), and turn it off when it goes into sleep. I know how to launch batch files with those triggers from Task Scheduler, but I don’t know how to get a batch file (or other) to run the script.

I’m not sure exactly what you mean by “to do the same”.

It looks like the REST API is exactly what I need. I’ll mark this as a solution as soon as I get it working. Thank you.

He’s saying the conventional way to do is not trying to run an openHAB script remotely.
There’s a very functional API you can use to command OH Items directly, or to trigger OH rules.