Executing command on command line

i want to execute a command on command line of rpi. i am able to control my tv with rpi command line using command such as irsend SEND_ONCE ~/akaitv.conf KEY_VOLUME
i want to do similar thing using openhab.please suggest how to give a command on command line usinbg it

*using it

You can use

executeCommandLine

in your rules.

So make a switch for your TV, and set up a rule along the lines of

rule "TV power"
		when 
			Item TV received command ON
		then
			executeCommandLine("irsend SEND_ONCE ~/akaitv.conf KEY_VOLUME")
end

I had issues with this method when trying to run a python script. A solution I found on this forum was to write a shell script and call that instead.

So something along the lines of:

#!/bin/sh
irsend SEND_ONCE ~/akaitv.conf KEY_VOLUME

Save it as TV.sh or whatever you wish to call it.

Then you need to make it executable by:

chmod +x TV.sh

Then call that from your rule instead:

rule "TV power"
		when 
			Item TV received command ON
		then
			executeCommandLine(" ~/openhab/conf/scripts/TV.sh")
end

(I have my .sh files saved in the scripts folder in openhab 2 - you will need to change the above to mirror the OH version and location of your scripts).

I don’t know why the shell script works when calling the command directly doesn’t, but the above works for me.

thanks for your reply can you please explain what is to be include in items and sitemaps.i want to know how does rule get trigger.??

what is to be added to items i am not able to understand it ???

how is rule trigered ??
what is to be in rule

import ??
rule " ??"
when
???
then
executeCommandLine(“irsend SEND_ONCE ~/akaitv.conf KEY_VOLUME”)
end

i am adding this to my sitemap

Frame label="akaitv remote control "
{
Switch item=power
Switch item=channelup
Switch item=channeldown
Switch item=volumeup
Switch item=volumedown
}

is it fine if i use this in item

Switch power
Switch channelup

and now in rule

import ???
rule "anything it doesnot matter"
when
Item power received command ON
then
executeCommandLine(“irsend SEND_ONCE ~/akaitv.conf KEY_POWER”)
end

Yeah that should do it.

it does not work.it says it says it is executing command but in actual anything does not happen.as i had not imported anything.please tell what to do as i even tried to execute this(( "sudo cp ~/akaitv.conf ~/checking.conf ))) but it does not do anything.so i think there is need of a binding.to be imported

As stated above I had issues getting this to work.

As also stated above, try saving the command you want to execute into a shell script, and calling that instead.

See the second half of my first post.

is there need to import any binding ???

the path of file is to to given from where ie home,root,pi or somewhere else

No, no binding needed. You need to create the TV.sh and make it executable as explained.

but address is to be given from where as openhab is in /opt/openhab

It depends on your file structure and where you save your TV.sh file. If saved in scripts and you’re running OH2, then /opt/openhab/conf/scripts/TV.sh should work.

i simply paste this command on my command line after saving tv.sh in scripts.but it sys cant find the directory

again it depends on your file structure.

navigate to the folder where you saved the TV.sh file and enter this on the command line:

echo $(cd $(dirname “$1”) && pwd -P)/$(basename “$1”)

it will give you the path of that directory. Use that in front of the TV.sh.

when i try to run script from command line it works.as it can be seen.

when same thing goes from here i check again but it does not work.

so there is problem with working of openhab as it seems to working fine from command line.i have changed the script for making a file workingcheck but it does not form anything

is there need to download anythiing as i am had installed only openhab,neither of his addons and neither any demo. and even in one tutorial it wasmention you need java-jdk.i had not even downloaded that

The setup you have now works for me. I am using openhab 2, and did install oracle jdk. This may be your issue.