Hi,
This is my first post here.
I am trying to use openhab 3 rules and I am using the javascript for that. Previously I have used openhab 2.5 (which is still running) and I am trying to “port” over some of the rules I have in 2.5.
I am have trouble getting the Exec.executeCommandLine to work with variables. I can make it work if I HARD code the values in but if I try to use a variable it doesn’t work.
What I am trying to do is sent a MQTT command to a sonoff device that has a small display unit on it. The executeCommandLine dosn’t seem to like having spaces in it.
Here is the code. (I have never used javascript unti to day by the way)
// logger.info(“About to test executeCommandLine”);
var logger = Java.type(‘org.slf4j.LoggerFactory’).getLogger(‘org.openhab.rule.’ + ctx.ruleUID);
var Exec = Java.type(“org.openhab.core.model.script.actions.Exec”);
var Duration = Java.type(“java.time.Duration”);
var stateof = “TEST”;
results = Exec.executeCommandLine(Duration.ofSeconds(5), “/usr/bin/mosquitto_pub”,"-h",“192.168.0.164”,"-t",“cmnd/coffee/displaytext”,"-m","[zOa2f0s1l1c1]Door-garage[s3l2c1]MOVE[s1l8c1]Updated[c9]at:[c13tS]");
java.lang.Thread.sleep(5000);
Exec.executeCommandLine(Duration.ofSeconds(5), “/usr/bin/mosquitto_pub”,"-h",“192.168.0.164”,"-t",“cmnd/coffee/displaytext”,"-m","[o]");
logger.info("results = " + results);
What I would like to achieve is where the the word MOVE is I want to put the variable stateof there instead.
Anyone know how to do this?
Thanks