[Solved] Sending commands to OH(2) from external scripts

Hello everybody,

I need to trigger an openhab switch from an external script. Currently I do it like this.

/usr/share/openhab2/runtime/bin/client send frontdoorTriggered ON

But that way it takes about two seconds until the command is actually issued in OpenHAB which is too long in that special case because an image has to be captured immediatly. Are there better (and faster) ways to send commands to OH?

Thanks in advance!
Stephan

Hello Stephan

May you try to trigger the switch via REST API?

You’ll find informations in the Documentation.

Regards
Michael

very simple example in the script I just posted: Detecting offline Things

Thanks Dan, that does the trick! Even more simple when configuring public-key authentication for karaf as described here:
https://karaf.apache.org/manual/latest/security

Now, sending a command to OH from a script is that simple:

ssh -p 8101 localhost <command>

E.G.

ssh -p 8101 localhost "smarthome:send frontdoorTriggered ON"

…and that with nearly zero latency! Great! :slight_smile:

Thanks again, Dan for pointing me into the right direction.

Actually I didn’t mean that - I meant the wget method

Dan

OK, but I think the ssh method is even better to change values and states. Also for getting the status of items it’s really handy:

openhab@vdr:~$ ssh -p 8101 localhost smarthome:status frontdoorTriggered
ON