This page last changed on May 11, 2013 by simnet.

Hi there,

I have a little question to finish an home automation concept. We have some LUA script or bash script on a linux computer and we need to integrate Openremote macro or command on it.

It's possible to call an Openremote command or macro through the shell ? I have read the REST API but i don't found a procedure to execute a command that is not linked to a design ...

Possible ?

Thanks a lot for your answer.

Guillaume


SMSalert.png (image/png)
Sensor-command.png (image/png)

As far as I recall the REST call to trigger a command is based on the button ID, which would fit to your findings.
You can create a panel though where you don't have any navigation towards it and place the button on that.
Then you should be able to trigger the button (command) through the REST API.

Posted by mredeker at May 12, 2013 11:03

Yes I thought of this solution. But it's not very usefull.
There is no way to execute openremote command through shell ? Like the drools syntax execute.command() ?

Posted by simnet at May 12, 2013 17:55

No. Shell would be an external process which only has access through REST.
Drools is running inside the controller and therefor can execute commands directly.

Posted by mredeker at May 12, 2013 19:29

If you want to execute a command from an external shell, just use the curl command to trigger the REST HTTP call.
I've done it in the past for demo purposes and it does work.

However, you already found one of the limitations that you need to have a (potentially unused) button to trigger a command or macro.
The other issue is that the REST API uses the button id, which is generated when saving the XML/syncing with the controller and will potentially change from one sync to the next.

The ideal solution is to add an additional REST call on the controller that could take e.g. the command name and execute it.
I'm afraid we don't have time to work on this right now, but if you (or somebody else) want to take a shot at implementing it, I'm happy to point you in the right direction.

Posted by ebariaux at May 13, 2013 12:47

Ok thanks.

Yes it can be a very nice solution to integrate Openremote macros with Crestron or other home automation system.

We look in our side how we can help you on this development.

Regards

Posted by simnet at May 15, 2013 08:04

FYI: we do support a close integration with AMX control systems for the Pro version.

What other system were you thinking about ?

Also, a closer integration with Crestron could be nice.

Posted by ebariaux at May 15, 2013 13:04

Hello team,

I'm now starting with rule programming. The first one I have tried was a rule that execute a bash script after an event happens (for example light status on). The problem I had was the script never runs. I have added a sentence to check if the rule works, sending a message to the log when the lights goes on, and it worked fine, but the script doesn't run. I have tested the script solely and work fine.
I have tried this rule in two ways, putting the script name in the execute.command sentence (execute.command ("script name with entire path"), other way was creating a command type "shell executing protocol" and calling it from the execute.command in the rule.
Have somebody any idea why this happens?
I have created a new device called ShellExecution and have added a command type "Shell execution protocol" pointing to my bash script. I have created a button with this command and didn't work either.

The script I have created is like this (echo "message" | gokii --sendsms "phone number"). I have a gsm module connected in the USB port of my raspberry-pi and I use gnokii to send SMS messages. The idea is (if finally the rule works) to add a door sensor and send alerts when door is open.

Thanks in advance

Abraham Martin

Posted by abrmartin at Sep 30, 2013 20:53

If the script doesn't execute even from a button then there's something wrong with the inter-process communication. I'd leave the rules out of it for now and just try to get the button to work first. It may be a permission issue – at the moment I can't think of other reasons why the button would fail to execute a script. Unless there are some specific errors in the logs.

Posted by juha at Oct 02, 2013 11:42

Hello Juha,

As I see in another forum I have added a SHELL command log in the log4j.. configuration file and I have no error messages from the shell execution: Here you are the output:
" DEBUG 2013-10-02 16:40:01,012 (Shell): Will start shell command: /home/pi/.config/gnokii/mensajes/SMSalert.sh and use params: null
DEBUG 2013-10-02 16:40:01,075 (Shell): Shell command: /home/pi/.config/gnokii/mensajes/SMSalert.sh returned:
DEBUG 2013-10-02 16:41:01,004 (Shell): Found cached ShellExe command with id: 480 "

I cant't understand why the result of the shell doesn't work. I have no SMS received in my mobile, but it seems to be executed correctly.

If you have any idea to test, it will be very appreciated.

Abraham

Posted by abrmartin at Oct 02, 2013 15:49

Reading in another forum I have seen a problem like mine and the solution given was to create a new sensor type=custom and add the command that uses the "Shell execution protocol". After that I have an error in the shell.log file (I have no rule created only the sensor with the shell). The output is :

" DEBUG 2013-10-02 20:40:01,017 (Shell): Shell command: Rr returned:
DEBUG 2013-10-02 20:41:01,003 (Shell): Found cached ShellExe command with id: 484
DEBUG 2013-10-02 20:41:01,004 (Shell): Will start shell command: Rr and use params: null
ERROR 2013-10-02 20:41:01,012 (Shell): Could not execute shell command: Rr
java.io.IOException: Cannot run program "Rr": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1043)
at java.lang.Runtime.exec(Runtime.java:620)
at java.lang.Runtime.exec(Runtime.java:485)
at org.openremote.controller.protocol.shellexe.ShellExeCommand.executeCommand(ShellExeCommand.java:119)
at org.openremote.controller.protocol.shellexe.ShellExeCommand.send(ShellExeCommand.java:82)
at org.openremote.controller.model.Command.execute(Command.java:230)
at org.openremote.controller.model.Command.execute(Command.java:199)
at org.openremote.controller.statuscache.CommandFacade.command(CommandFacade.java:80)
at org.openremote.controller.statuscache.CommandFacade.command(CommandFacade.java:57)
at org.openremote.controller.model.event.Rule_TurnLightOff_0.defaultConsequence(Rule_TurnLightOff_0.java:15)
at org.openremote.controller.model.event.Rule_TurnLightOff_0DefaultConsequenceInvoker.evaluate(Rule_TurnLightOff_0DefaultConsequenceInvoker.java:25)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:917)
at org.drools.common.Scheduler$ActivationTimerJob.execute(Scheduler.java:73)
at org.drools.time.impl.JDKTimerService$JDKCallableJob.call(JDKTimerService.java:147)
at org.drools.time.impl.JDKTimerService$JDKCallableJob.call(JDKTimerService.java:125)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:724)
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:136)
at java.lang.ProcessImpl.start(ProcessImpl.java:134)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1024)
... 20 more
DEBUG 2013-10-02 20:41:01,019 (Shell): Shell command: Rr returned:
DEBUG 2013-10-02 20:41:14,438 (Shell): Found cached ShellExe command with id: 480
DEBUG 2013-10-02 20:41:14,448 (Shell): *** setSensor called as part of EventListener init *** sensor is: Sensor (Name = 'SMSAlert Sensor', ID = '3069850', State Mappings: {})"

The message "No such file or directory" I suppose is the key in this problem, but I don't know why it happens.

Abraham

Posted by abrmartin at Oct 02, 2013 19:48

It could be that the openremote controller is started with a user that does not have exec rights on your shell script.

Posted by mredeker at Oct 02, 2013 19:52

I have reviewed the rights that the script has and it seems to be ok. Here you are a snapshot:

pi@openremote ~/.config/gnokii/mensajes $ ls -la
total 12
drwxr-xr-x 2 pi pi 4096 sep 29 00:34 .
drwxr-xr-x 3 pi pi 4096 sep 28 14:34 ..
-rwxr-xr-x 1 pi pi 84 oct 2 16:31 SMSalert.sh

thanks

Abraham

Posted by abrmartin at Oct 02, 2013 22:06

Your log says:

 Shell command: Rr returned: 

But your command is SMSalert.sh.
It looks like your Button/Rule is triggering the wrong command or you have specified the wrong command path in the protocol.

Posted by mredeker at Oct 02, 2013 22:32

The command I have created is the next:

I have added the entire path to the command.

And the scrip is : SMSalert.sh

#!/bin/sh

echo "Alert: lights on" | gnokii --sendsms 999999999

Posted by abrmartin at Oct 03, 2013 18:56

1. Your command should be /bin/sh
2. Your command parameter should be /path/SMSalert.sh
3. Inside SMSalert.sh the path to gnokii should be specified.

Posted by aktur at Oct 03, 2013 19:55

Something seems to be wrong at anywhere. I have deleted the command SMSalert and in the log appears the same error massage as before, pointing to the path given in the shell execution protocol attributes. I have checheck the time and are new entries to the log, not old ones. I can't understand why this happens if the command doesn't exist.
I have rebooted the raspberrypi and now the OR has installed other configuration that isn't the actual I have in the Designer. It's like the system store the configuration and didn't refresh after presing the command "Sync with online designer"

Is there a cache to clear? The command "Reload configuration and clear cache" I can't use because it returns me the error "failed to reload configuration and clear cache"

Thanks

Posted by abrmartin at Oct 03, 2013 20:37

Is there a way to flush memmory after rule creation. After some modifications in the Designer, log continue showing the configuration as it was before the change. I have to reboot my raspberry to apply new changes.

Posted by abrmartin at Oct 03, 2013 21:49

Hi Michal,

When you write: "your command should be: /bin/sh" are you refering to the path?

Thanks

Posted by abrmartin at Oct 03, 2013 21:56

Hi Michal,

With your suggestion and appliying the information I asked in my last post finally it works. Great!. I have spent more than two week with this issue. I have not solved yet how to say gnokii to send a message when the command is executed by OR, but now I have the certaninty that the scipts runs.

Thanks to everybody that help me with this problem.

Abraham

Posted by abrmartin at Oct 03, 2013 23:24

Once solved the problem related with the Shell execution in rules I have the next issue related with rule scripting. Why the next rule works?

package org.openremote.controller.model.event

global org.openremote.controller.statuscache.CommandFacade execute;
global org.openremote.controller.statuscache.SwitchFacade switches;

import org.openremote.controller.protocol.*;

//-----------------------------------------------------------------------------------------------

rule "TurnLightOff"

timer (cron: 1 * * * * ?)

when

eval (true)

then

execute.command ("SMSalert") ;

end

and this one doesn't:

package org.openremote.controller.model.event

global org.openremote.controller.statuscache.CommandFacade execute;
global org.openremote.controller.statuscache.SwitchFacade switches;
import org.openremote.controller.protocol.*;

rule "Send Alert SMS" when

Event ( source == "Fibaro2-Luces_pasillo", value == "on" )

then

execute.command ("SMSalert");

end

"Fibaro2-Luces_pasillo" is a sensor with two possible values on/off

Thanks again.

Abraham Martín

Posted by abrmartin at Oct 06, 2013 05:44

Is that sensor of type:switch ?

Posted by pz1 at Oct 06, 2013 08:00

Yes, it is a type:switch sensor

Posted by abrmartin at Oct 07, 2013 08:11

Sorry, that the only thing that came up to my mind, except for checking once more if there isn't a typing error in the sensor name.
PS: For better readability enclose your rules within {code}..{code} tags(see markup instructions). Do not place a / inside the end tag. That makes the rules easier to read, which increases your chances to get an answer

Posted by pz1 at Oct 07, 2013 08:19

I just created a rule type:custom and worked fine. I don't know why but it worked!

Posted by abrmartin at Oct 07, 2013 08:54

There is something funny with this switch sensor. It is described as boolean, but has as values on and off instead of false/true what I would expect. Did you add any custom state items in the screen? If so which pairs did you enter?

Posted by pz1 at Oct 07, 2013 09:03

No, I haven't added nothing special. I only created a new sensor type:custom and added the same command that sensor type:switch had.

Abraham

Posted by abrmartin at Oct 07, 2013 12:36
Document generated by Confluence on Jun 05, 2016 09:41