Creating exec commands with rules / switches

Hello OH community. I am new at this, and I am trying to create some scripts that will control my TV. I’ve already installed the Samsung bindings, but unfortunately, my TV isn’t supported for the source switching. I can control power, volume and mute though. With that said, I have a linux server dedicated to my OpenHAB install and I’ve installed samsungctl (a linux tool that does support my TV).

After some research, I found that I can execute command line scripts from OH. Well, to my surprise, I can’t get it working within my OH scripts. Can someone please point me in the right direction on getting these rules to work properly. Thanks.


Number  tv_control      "TV Control"
String  tv_command      "TV Command"    { command="/usr/bin/samsungctl --host --id banshee %2$s" }


rule "TV Source"
      Item    tv_control      received command
      switch(receivedCommand) {
         case 1 : tv_command.sendCommand("tv")
         case 2 : tv_command.sendCommand("hdmi1")
         case 3 : tv_command.sendCommand("hdmi2")
         case 4 : tv_command.sendCommand("hdmi3")
         case 5 : tv_command.sendCommand("hdmi4")


Frame label="TV" {
     Selection       item=tv_control         icon="receiver"                 label="TV Control"      mappings=[1="TV", 2="Roku", 3="PS4", 4="Steam", 5="Nintendo"]

My intention was to create number place-holder so that I could see what input my TV was on, then change it with a selection but use a rule to pass the argument in so that I could keep track of the source.

Maybe I am way off, but I really felt like I was on to something. Thanks again for the help.


Have you installed exec binding version 1.x? I’m not at all sure that works in OH2. Are you following some old guide?

There is an exec binding v2 but it works with things and channels.

I have the exec binding 2.4.0 installed (from the Paper UI Bindings/Addon installer).

Okeydoke, then you need to set up a thing, and link your Item to its input channel instead.

Your general principle is sound, but you’re following the wrong binding guide.

So, I added a thing with the exec command, but still not winning…


Thing   exec:command:tv_input   [ command="/usr/bin/samsungctl --host --id banshee %2$s", autorun=false ]


Number  tv_control      "TV Control"
String  tv_command      "TV Command"    { channel="exec:command:tv:tv_input:input" }

I think this is probably a better model to follow though

check that

I changed it and it works!!!

String  tv_command      "TV Command"    { channel="exec:command:tv_input:input" }

Thanks a lot, I appreciate the help.


1 Like