Special character to cut out an exec binding config, on multiples lines

Hi!

Let say I want to breakdown a binding configuration into mutiples lines, representing each state of the same item. Is there a character permetting to ignore line return? I’ve try with “” without sucess.

I’ve seen some Binding configs in examples on multiple lines. Have you just tried just typing return and not trying to escape it?

Switch MySwitch {bind1="Some info", 
                             bind2="Some more bind info"
                             bind3="Some more bind info" }    

However, if you are talking about within a single binding string, that would probably be something implemented by the individual binding so I’d say give it a try and if it doesn’t work it doesn’t work.

Yes! It’s inside a binding this is with exec binding. I tried, no character, “”, “\”, " /", “;” and “,”. :confused:

Here an exemple for my TV Numpad :

String TvSharpNum {exec=">[0:/bin/sh@@-c@@echo 'sendir,1:2,0,38000,3,1,10,70,10,30BBBABABAAAABA,10,1343' | nc -C -i 1 192.168.9.71 4998]/
 >[1:/bin/sh@@-c@@echo 'sendir,1:2,1,37000,3,1,10,68,10,29BBBBAAAAAAABA,10,1305' | nc -C -i 1 192.168.9.71 4998]/
 >[2:/bin/sh@@-c@@echo 'sendir,1:2,2,38000,3,1,10,70,10,30BBBBABBBBBBAB,10,1343' | nc -C -i 1 192.168.9.71 4998]/
 >[3:/bin/sh@@-c@@echo 'sendir,1:2,3,37000,3,1,10,68,10,28BBBBBAAAAAABA,10,1305' | nc -C -i 1 192.168.9.71 4998]/
 >[4:/bin/sh@@-c@@echo 'sendir,1:2,4,37000,3,1,10,68,10,28BBBBBABBBBBAB,10,1305' | nc -C -i 1 192.168.9.71 4998]/
 >[5:/bin/sh@@-c@@echo 'sendir,1:2,5,37000,3,1,10,68,10,28BBBBABAAAAABA,10,1305' | nc -C -i 1 192.168.9.71 4998]/
 >[6:/bin/sh@@-c@@echo 'sendir,1:2,6,37000,3,1,10,67,10,28BBBBAABBBBBAB,10,1305' | nc -C -i 1 192.168.9.71 4998]/
 >[7:/bin/sh@@-c@@echo 'sendir,1:2,7,38000,3,1,10,70,10,29BBBAAABBBBBAB,10,1343' | nc -C -i 1 192.168.9.71 4998]/
 >[8:/bin/sh@@-c@@echo 'sendir,1:2,8,38000,3,1,10,70,10,29BBBBBBABBBBAB,10,1343' | nc -C -i 1 192.168.9.71 4998]/
 >[9:/bin/sh@@-c@@echo 'sendir,1:2,9,38000,3,1,10,70,10,29BBBABBABBBBAB,10,1343' | nc -C -i 1 192.168.9.71 4998]"}

I’m afraid you might be stuck if the exec binding does not support it.

However, you can move the logic to a Rule.

String TvSharpNum
rule "Send TvSharpNum"
when
    Item TvSharpNum received command
then
    if(TvSharpNum.state == "0") {
        executeCommandLine("/bin/sh@@-c@@echo 'sendir,1:2,0,38000,3,1,10,70,10,30BBBABABAAAABA,10,1343' | nc -C -i 1 192.168.9.71 4998")
    } else if(TvSharpNum.state == "1"){
        executeCommandLine("/bin/sh@@-c@@echo 'sendir,1:2,1,37000,3,1,10,68,10,29BBBBAAAAAAABA,10,1305' | nc -C -i 1 192.168.9.71 4998")
    }
...
end

When writing a forum posting that includes code you can:

  • Indent by four spaces
  • Write the code, highlight what you wrote and click the </> button
  • If it is a short bit you can surround the text with back-ticks (that is how I was able to write </>above
  • If you have multiple lines of code you can put three back ticks on the line before and three after
    ```
    My Code
    ```

All of these will preserve your indentations and special characters, and make the rest of the forum readers happy.

Thanks for you reply! I’ve just correct that .

Unfortunately, I can’t use a rule because it’s adding a delay causing my channels rules to tune incorectly. For exemple, if I tune the channel 45, it send 4, then the tv tune to 4, it send 5, then the tv tune to 5. This is partly due to my slow hardware. Previouly I was using a bash script to execute the code and also had this delay issue. So that is why I’ve come up with an extremely long line, to speedup the code execution, and also to simplifiy code.

String TvSharpNum (TapSwitch) {exec=">[0:/bin/sh@@-c@@echo 'sendir,1:2,0,38000,3,1,10,70,10,30BBBABABAAAABA,10,1343' | nc -C -i 1 192.168.9.71 4998] >[1:/bin/sh@@-c@@echo 'sendir,1:2,1,37000,3,1,10,68,10,29BBBBAAAAAAABA,10,1305' | nc -C -i 1 192.168.9.71 4998] >[2:/bin/sh@@-c@@echo 'sendir,1:2,2,38000,3,1,10,70,10,30BBBBABBBBBBAB,10,1343' | nc -C -i 1 192.168.9.71 4998] >[3:/bin/sh@@-c@@echo 'sendir,1:2,3,37000,3,1,10,68,10,28BBBBBAAAAAABA,10,1305' | nc -C -i 1 192.168.9.71 4998] >[4:/bin/sh@@-c@@echo 'sendir,1:2,4,37000,3,1,10,68,10,28BBBBBABBBBBAB,10,1305' | nc -C -i 1 192.168.9.71 4998] >[5:/bin/sh@@-c@@echo 'sendir,1:2,5,37000,3,1,10,68,10,28BBBBABAAAAABA,10,1305' | nc -C -i 1 192.168.9.71 4998] >[6:/bin/sh@@-c@@echo 'sendir,1:2,6,37000,3,1,10,67,10,28BBBBAABBBBBAB,10,1305' | nc -C -i 1 192.168.9.71 4998] >[7:/bin/sh@@-c@@echo 'sendir,1:2,7,38000,3,1,10,70,10,29BBBAAABBBBBAB,10,1343' | nc -C -i 1 192.168.9.71 4998] >[8:/bin/sh@@-c@@echo 'sendir,1:2,8,38000,3,1,10,70,10,29BBBBBBABBBBAB,10,1343' | nc -C -i 1 192.168.9.71 4998] >[9:/bin/sh@@-c@@echo 'sendir,1:2,9,38000,3,1,10,70,10,29BBBABBABBBBAB,10,1343' | nc -C -i 1 192.168.9.71 4998]"}

I could use a separate item for each number but this is incompatible with my sitemap.

Frame label="Canaux"{
	Switch icon="" label="." item=TvSharpNum mappings=[1='1', 2='2', 3='3']
	Switch icon="" label="." item=TvSharpNum mappings=[4='4', 5='5', 6='6']
	Switch icon="" label="." item=TvSharpNum mappings=[7='7', 8='8', 9='9']
	Switch icon="" label="." item=TvSharpNum mappings=[10='.', 0='0', 11='.']
	Switch icon="" label="." item=TvSharpCh mappings=["chdown"='-', "chup"='+']
}

So in my quest to simplify code, I get stuck with hard to write and maintain code, but hey, I’m not sad, because you know what, it’s works like a charm! I realy like this binding, it’s almost perfect. i’ve manage a way to control almost everything with it. Just missing the ability to breakdown code on multiples lines.

If your system is that sensitive to timing I would not have any confidence that putting it all into a binding like that will work reliably all the time. If you happen to trigger an event when the system is doing something else (e.g. performing garbage collection) you will be right back in the same boat. I also do not think OH does anything to guarantee that events are processed in the order they are received.

In short, I suspect you might find even your current approach to be flaky and unreliable. But if it is working for you now it will probably work most of the time. Just don’t be surprised when it has a hick-up now and again.

One last thing to note. In your rule when you call executeCommandLine without supplying a timeout parameter it immediately returns without waiting for the command to return (unlike a Bash script which will wait for the command to complete). Thus, my rule above might indeed be fast enough since it will be processing each button press in parallel rather than waiting for one to finish before processing the second,. Of course, the lack of a guarantee in processing the events in order may come into play here as well.

Thanks for this clarification! I’ve comme up with an hybrid solution to gain some speed:
I will replace my channel rule:

rule "FavoriTVSharp"
when
	Item TvSharpTune received command
then
	//TVA
	if(receivedCommand == 8){
		sendCommand(TvSharpNum, 8)
	}
	//TQC
	if(receivedCommand == 45){
		sendCommand(TvSharpNum, 4)
		sendCommand(TvSharpNum, 5)
	}
	//VTV
	if(receivedCommand == 16){
		sendCommand(TvSharpNum, 1)
		sendCommand(TvSharpNum, 6)
	}
	//RadioCanada
	if(receivedCommand == 13){
		sendCommand(TvSharpNum, 1)
		sendCommand(TvSharpNum, 3)
	}
end

By this one :

rule "FavoriTVChambre"
when
	Item TvSharpTune received command
then
	//TVA
	if(receivedCommand == 8){
		executeCommandLine("/bin/sh@@-c@@echo 'sendir,1:2,8,38000,3,1,10,70,10,29BBBBBBABBBBAB,10,1343' | nc -C -i 1 192.168.9.71 4998")
	}
	//TQC
	if(receivedCommand == 45){
		executeCommandLine("/bin/sh@@-c@@echo 'sendir,1:2,4,37000,3,1,10,68,10,28BBBBBABBBBBAB,10,1305' | nc -C -i 1 192.168.9.71 4998")
		executeCommandLine("/bin/sh@@-c@@echo 'sendir,1:2,5,37000,3,1,10,68,10,28BBBBABAAAAABA,10,1305' | nc -C -i 1 192.168.9.71 4998")
	}
	//VTV
	if(receivedCommand == 16){
		executeCommandLine("/bin/sh@@-c@@echo 'sendir,1:2,1,37000,3,1,10,68,10,29BBBBAAAAAAABA,10,1305' | nc -C -i 1 192.168.9.71 4998")
		executeCommandLine("/bin/sh@@-c@@echo 'sendir,1:2,6,37000,3,1,10,67,10,28BBBBAABBBBBAB,10,1305' | nc -C -i 1 192.168.9.71 4998")
	}
	//RadioCanada
	if(receivedCommand == 13){
		executeCommandLine("/bin/sh@@-c@@echo 'sendir,1:2,1,37000,3,1,10,68,10,29BBBBAAAAAAABA,10,1305' | nc -C -i 1 192.168.9.71 4998")
		executeCommandLine("/bin/sh@@-c@@echo 'sendir,1:2,3,37000,3,1,10,68,10,28BBBBBAAAAAABA,10,1305' | nc -C -i 1 192.168.9.71 4998")
	}
end