Exec bindings help

noob here Im new to openhab and have yet to get anything working, I’ve followed the instructions at http://smarthome.hallojapan.de/2014/11/controlling-lights-with-openhab-raspberry-pi-and-433mhz-remote-switches/ and am able to run the shell script from terminal via ssh but can’t figure out the bit at the bottom “Add openHAB item” I’ve tried for three days now but can’t find simple instructions on exec bindings. I’ve copied and pasted the code into a sitemap file but nothing appears. please help

Hi, and welcome i am prettey new as well.

Are u using openhab 1.x or Openhab 2 ?
your tuturial is for Openhab1.x i think
The code does not belong in the Sitemap´file :wink:

In Openhab you have amongst other things:

  • Items: (or Things as well in Openhab2) The *.items file defines the Variables u are using.
    A switch (Variable Type) is what is used in ur example. A Switch can only have the states “ON” or “OFF”. Then the code(python script) for ON/OFF is executet as the state changes. So this example code code goes in the *items file.

  • Sitemaps: Sitemaps define what you see in the UI For example:

Switch item= Lamp_LV_Standing icon="light"

This would display a switch with the icon of a lightbulb that switches your variable " Lamp_LV_Standing "

I’m using openhab2, Would you recommend i use openhab 1? I will try what you said right now

please excuse my ignorance, Where would it display a switch with an icon of a lightbulb? I’m completely lost here

you cann use openhab1.x, I would recommend openhab2 since it kind of replaces the old one.

Like @borderbridge said the code does not belong in the Sitemap file.

  • first add the exec binding if you haven’t yet (via PaperUI in your browser or the addons.cfg)

  • then create an item:

Switch Lamp_LV_Standing "Standing Lamp" {exec=">[OFF:sudo /opt/rc-switch/switchOff.sh 1] >[ON:sudo /opt/rc-switch/switchOn.sh 1]"}

This should be put in an .item file in the item directory. Maybe you will have to change the filepath.

  • then add
Switch item= Lamp_LV_Standing icon="light"

to your sitemap.

The item file defines an item and the sitemap file puts it on your sitemap, so you can see it.

You should definitely read up on the openhab structure an concepts if you want to use it for more applications.


I know that it is a lot to start with, but I guarantee it’s worth it :wink:

Thank you both for your help, I’ve done what you have said and the item now appears, however it doesn’t change the state, i have run sudo /opt/rc-switch/switchOn.sh and sudo /opt/rc-switch/switchOff.sh in the command line and it works ok but not on the ui

i have installed exec binding via paper ui, do i need to do anything else with it?

Yes, that’s my fault, I forgot the “thing”, which is a new concept of openhab2.

Look here:

github exec binding

“For each command a separate Thing has to be defined.”

please go easy i am a complete noob, I’ve read that page about things for exec binding 10 times but still no clue what to do with it

is this correct?

Thing exec:command:apc [command="sudo /opt/rc-switch/switchOn.sh", interval=0, timeout=15]

Me too, i’m here since last week and did not work with exec before :smiley:

Yes it is correct, but you have to change the items now :wink:

apc - name of the thing

–> a thing has different channels

–> each item can use one channel

Your item should look like that now:

Switch Lamp_LV_Standing { channel="exec:command:apc:run"}

The sitemap remains the same.

I hope this does the trick :smiley:

finger crossed

Make sure you are using the correct Exec binding for the tutorials or examples you are following. The 1.x Exec binding needs { exec="..." } in your .items file, while the 2.x Exec binding uses { channel="..." } syntax in your .items file. The configurations are completely different from one another. The 1.x Exec binding involves quite a lot less manual configuration than the 2.x binding requires.

unfortunately that didn’t work, I’m using exec 2.0.0

It works!!! Well sort of. at least it switches on, I think i need to add another line of things? maybe > Thing exec:command:apc [command=“sudo /opt/rc-switch/switchOff.sh”, interval=0, timeout=15]

Yes like mentioned before “For each command a separate Thing has to be defined.” But then you would have to use another Switch… I don’t know how to do it with one switch.
Maybe someone more experienced has an idea.

can’t seem to find a way to switch it off, If anyone can give me some direction please help.

1 Like

can someone please help me? I’m able to turn them on but nothing happens when i turn them off, I’ve added two switches, one for on and one for off but its not how i wanted to do it.

Use a only one switch for turning it on and a rule that is activated when the switch is turned from ON to OFF to start the off-script.

rule turnOFF
	Item Lamp_LV_Standing turned from ON to OFF
	executeCommandLine("sudo /opt/rc-switch/switchOff.sh 1")

Thanks for that, I’ll give that a go right now.