[SOLVED] Send multiple channel tv to broadlink throu to only one rule

hello everyone good night I have made the following rule to control multiple television channels through broadlink,

I use DIRECTV and has declared approximately 40 television channels as Switch, when it is activated the code or channel number is sent to a rule which sends number by number to the broadlink

example TV channel MTV = 1334

sendCommand(One_DirecTv, ON)
sendCommand(Tree_DirecTv, ON)
sendCommand(Tree_DirecTv, ON)
sendCommand(Four_DirecTv, ON)

the problem is that the programming guide of my television is more than 200 TV channels for each television decoder or for each DIRECTV in my house I have 3 televisions and this generates a rule file of more than 9000 lines of code and 600 rules for each channel and that can make me independent of each of the 3 encoders

this works for me, the problem is that I have a rules file that is too large and when the raspberry restarts it takes approximately 45 minutes to load

this is my configuration

my Things

Bridge mqtt:broker:mosquitto [ host="192.168.0.30", port=1883, clientID="Domitic", secure=false]  
{

	Thing mqtt:topic:directvsala "DIRECTV SALA"  {
	Channels:
	
Type switch : Cero_DirecTv    [ commandTopic="broadlink/televisor/saladirectv/cero", on="play-780f77b943fb"]
Type number : Uno_DirecTv     [ commandTopic="broadlink/televisor/saladirectv/uno", on="play-780f77b943fb"]
Type number : Dos_DirecTv     [ commandTopic="broadlink/televisor/saladirectv/dos", on="play-780f77b943fb"]
Type number : Tres_DirecTv 	  [ commandTopic="broadlink/televisor/saladirectv/tres", on="play-780f77b943fb"]
Type number : Cuatro_DirecTv  [ commandTopic="broadlink/televisor/saladirectv/cuatro", on="play-780f77b943fb"]
Type number : Cinco_DirecTv	  [ commandTopic="broadlink/televisor/saladirectv/cinco", on="play-780f77b943fb"]
Type number : Seis_DirecTv	  [ commandTopic="broadlink/televisor/saladirectv/seis", on="play-780f77b943fb"]
Type number : Siete_DirecTv	  [ commandTopic="broadlink/televisor/saladirectv/siete", on="play-780f77b943fb"]
Type number : Ocho_DirecTv	  [ commandTopic="broadlink/televisor/saladirectv/ocho", on="play-780f77b943fb"]
Type number : Nueve_DirecTv	  [ commandTopic="broadlink/televisor/saladirectv/nueve", on="play-780f77b943fb"]

}
  }

items

Switch  TV1_Ch1524	           "HBO HD"		         		    (Switches, Gtv1)         
Switch  TV1_Ch1525	           "HBO 2 HD"		         		    (Switches, Gtv1)       
Switch  TV1_Ch1532	           "HBO Plus HD"		      	        (Switches, Gtv1)       
Switch  TV1_Ch1534	           "HBO Family HD"		         	    (Switches, Gtv1)       
Switch  TV1_Ch1542	           "Max Prime HD"		        	    (Switches, Gtv1)      
Switch  TV1_Ch1552	           "Fox Premium Series HD"		        (Switches, Gtv1)      
Switch  TV1_Ch1556	           "Fox Premium Family HD"		        (Switches, Gtv1)        
Switch  TV1_Ch1557	           "Fox Premium Comedy HD"		        (Switches, Gtv1)        
Switch  TV1_Ch1559	           "Fox Premium Movies HD"		        (Switches, Gtv1)        
Switch  TV1_Ch1561	           "Fox Premium Action HD"		        (Switches, Gtv1)        
Switch  TV1_Ch1562	           "Fox Premium Cinema HD"		        (Switches, Gtv1)        
Switch  TV1_Ch1604	           "Fox Sports HD"		         	    (Switches, Gtv1)        
Switch  TV1_Ch1608	           "Fox Sports 2 HD"		            (Switches, Gtv1)        
Switch  TV1_Ch1609	           "Fox Sports 3 HD"		            (Switches, Gtv1)        
Switch  TV1_Ch1610	           "DIRECTV Sports HD"		            (Switches, Gtv1)        
Switch  TV1_Ch1611	           "DIRECTV Sports HD Eventos"		    (Switches, Gtv1)     
Switch  TV1_Ch1612	           "DIRECTV Sports 2 HD"		        (Switches, Gtv1)     
Switch  TV1_Ch1613	           "DIRECTV Sports 3 HD"		        (Switches, Gtv1)     
Switch  TV1_Ch1620	           "ESPN HD"		         		    (Switches, Gtv1)     
Switch  TV1_Ch1621	           "ESPN + HD"		         		    (Switches, Gtv1)       
Switch  TV1_Ch1623	           "ESPN 2 HD"		         		    (Switches, Gtv1)       
Switch  TV1_Ch1626	           "ESPN 3 HD"		         		    (Switches, Gtv1)  

Rules

rule "HBO (ESTE) HD 1524"
  when
    Item TV1_Ch1524 received command ON
		then
			sendCommand(Uno_DirecTv,   ON)
					Thread::sleep(500)
			sendCommand(Cinco_DirecTv,   ON)
					Thread::sleep(500)	
			sendCommand(Dos_DirecTv,  ON)
					Thread::sleep(500)
			sendCommand(Cuatro_DirecTv,   ON) 
					Thread::sleep(500)
			sendCommand(Enter_DirecTv, ON)
			sendCommand(Exit_DirecTv, ON)
			sendCommand(TV1_Ch1524 ,   OFF)
			sendCommand(InfoCanal,   "State")				
end



rule "HBO 2 HD 1525"
  when
    Item TV1_Ch1525 received command ON
		then
			sendCommand(Uno_DirecTv,   ON)
					Thread::sleep(500)
			sendCommand(Cinco_DirecTv,   ON)
					Thread::sleep(500)	
			sendCommand(Dos_DirecTv,  ON)
					Thread::sleep(500)
			sendCommand(Cinco_DirecTv,   ON) 
					Thread::sleep(500)
			sendCommand(Enter_DirecTv, ON)
			sendCommand(Exit_DirecTv, ON)
			sendCommand(TV1_Ch1525 ,   OFF)
			sendCommand(InfoCanal,   "State")				
end


rule "HBO PLUS HD 1532"
  when
    Item TV1_Ch1532 received command ON
		then
			sendCommand(Uno_DirecTv,   ON)
					Thread::sleep(500)
			sendCommand(Cinco_DirecTv,   ON)
					Thread::sleep(500)	
			sendCommand(Tres_DirecTv,  ON)
					Thread::sleep(500)
			sendCommand(Dos_DirecTv,   ON) 
					Thread::sleep(500)
			sendCommand(Enter_DirecTv, ON)
			sendCommand(Exit_DirecTv, ON)
			sendCommand(TV1_Ch1532 ,   OFF)
			sendCommand(InfoCanal,   "State")				
end



rule "HBO FAMILY HD 1534"
  when
    Item TV1_Ch1534 received command ON
		then
			sendCommand(Uno_DirecTv,   ON)
					Thread::sleep(500)
			sendCommand(Cinco_DirecTv,   ON)
					Thread::sleep(500)	
			sendCommand(Tres_DirecTv,  ON)
					Thread::sleep(500)
			sendCommand(Cuatro_DirecTv,   ON) 
					Thread::sleep(500)
			sendCommand(Enter_DirecTv, ON)
			sendCommand(Exit_DirecTv, ON)
			sendCommand(TV1_Ch1534 ,   OFF)
			sendCommand(InfoCanal,   "State")				
end



rule "MAX PRIME HD 1542"
  when
    Item TV1_Ch1542 received command ON
		then
			sendCommand(Uno_DirecTv,   ON)
					Thread::sleep(500)
			sendCommand(Cinco_DirecTv,   ON)
					Thread::sleep(500)	
			sendCommand(Cuatro_DirecTv,  ON)
					Thread::sleep(500)
			sendCommand(Dos_DirecTv,   ON) 
					Thread::sleep(500)
			sendCommand(Enter_DirecTv, ON)
			sendCommand(Exit_DirecTv, ON)
			sendCommand(TV1_Ch1542 ,   OFF)
			sendCommand(InfoCanal,   "State")				
end



rule "FOX PREMIUM SERIES HD 1552"
  when
    Item TV1_Ch1552 received command ON
		then
			sendCommand(Uno_DirecTv,   ON)
					Thread::sleep(500)
			sendCommand(Cinco_DirecTv,   ON)
					Thread::sleep(500)	
			sendCommand(Cinco_DirecTv,  ON)
					Thread::sleep(500)
			sendCommand(Dos_DirecTv,   ON) 
					Thread::sleep(500)
			sendCommand(Enter_DirecTv, ON)
			sendCommand(Exit_DirecTv, ON)
			sendCommand(TV1_Ch1552 ,   OFF)
			sendCommand(InfoCanal,   "State")				
end



rule "FOX PREMIUM FAMILY HD 1556"
  when
    Item TV1_Ch1556 received command ON
		then
			sendCommand(Uno_DirecTv,   ON)
					Thread::sleep(500)
			sendCommand(Cinco_DirecTv,   ON)
					Thread::sleep(500)	
			sendCommand(Cinco_DirecTv,  ON)
					Thread::sleep(500)
			sendCommand(Seis_DirecTv,   ON) 
					Thread::sleep(500)
			sendCommand(Enter_DirecTv, ON)
			sendCommand(Exit_DirecTv, ON)
			sendCommand(TV1_Ch1556 ,   OFF)
			sendCommand(InfoCanal,   "State")				
end


rule "FOX PREMIUM COMEDY HD 1557"
  when
    Item TV1_Ch1557 received command ON
		then
			sendCommand(Uno_DirecTv,   ON)
					Thread::sleep(500)
			sendCommand(Cinco_DirecTv,   ON)
					Thread::sleep(500)	
			sendCommand(Cinco_DirecTv,  ON)
					Thread::sleep(500)
			sendCommand(Siete_DirecTv,   ON) 
					Thread::sleep(500)
			sendCommand(Enter_DirecTv, ON)
			sendCommand(Exit_DirecTv, ON)
			sendCommand(TV1_Ch1557 ,   OFF)
			sendCommand(InfoCanal,   "State")				
end



rule "FOX PREMIUM MOVIES HD 1559"
  when
    Item TV1_Ch1559 received command ON
		then
			sendCommand(Uno_DirecTv,   ON)
					Thread::sleep(500)
			sendCommand(Cinco_DirecTv,   ON)
					Thread::sleep(500)	
			sendCommand(Cinco_DirecTv,  ON)
					Thread::sleep(500)
			sendCommand(Nueve_DirecTv,   ON) 
					Thread::sleep(500)
			sendCommand(Enter_DirecTv, ON)
			sendCommand(Exit_DirecTv, ON)
			sendCommand(TV1_Ch1559 ,   OFF)
			sendCommand(InfoCanal,   "State")				
end


rule "FOX PREMIUM ACTION HD 1561"
  when
    Item TV1_Ch1561 received command ON
		then
			sendCommand(Uno_DirecTv,   ON)
					Thread::sleep(500)
			sendCommand(Cinco_DirecTv,   ON)
					Thread::sleep(500)	
			sendCommand(Seis_DirecTv,  ON)
					Thread::sleep(500)
			sendCommand(Uno_DirecTv,   ON) 
					Thread::sleep(500)
			sendCommand(Enter_DirecTv, ON)
			sendCommand(Exit_DirecTv, ON)
			sendCommand(TV1_Ch1561 ,   OFF)
			
			sendCommand(InfoCanal,   "State")				
end


rule "FOX PREMIUM CINEMA HD 1562"
  when
    Item TV1_Ch1562 received command ON
		then	
			sendCommand(Uno_DirecTv,   ON)
					Thread::sleep(500)
			sendCommand(Cinco_DirecTv,   ON)
					Thread::sleep(500)	
			sendCommand(Seis_DirecTv,  ON)
					Thread::sleep(500)
			sendCommand(Dos_DirecTv,   ON) 
					Thread::sleep(500)
			sendCommand(Enter_DirecTv, ON)
			sendCommand(Exit_DirecTv, ON)
			sendCommand(TV1_Ch1562 ,   OFF)
			sendCommand(InfoCanal,   "State")				
end


rule "FOX SPORT HD 1604"
  when
    Item TV1_Ch1604 received command ON
		then
			sendCommand(Uno_DirecTv,   ON)
					Thread::sleep(500)
			sendCommand(Seis_DirecTv,   ON)
					Thread::sleep(500)	
			sendCommand(Cero_DirecTv,  ON)
					Thread::sleep(500)
			sendCommand(Cuatro_DirecTv,   ON) 
					Thread::sleep(500)
			sendCommand(Enter_DirecTv, ON)
			sendCommand(Exit_DirecTv, ON)
			sendCommand(TV1_Ch1604 ,   OFF)
			sendCommand(InfoCanal,   "State")				
end


rule "FOX SPORT 2 HD 1608"
  when
    Item TV1_Ch1608 received command ON
		then
			sendCommand(Uno_DirecTv,   ON)
					Thread::sleep(500)
			sendCommand(Seis_DirecTv,   ON)
					Thread::sleep(500)	
			sendCommand(Cero_DirecTv,  ON)
					Thread::sleep(500)
			sendCommand(Ocho_DirecTv,   ON) 
					Thread::sleep(500)
			sendCommand(Enter_DirecTv, ON)
			sendCommand(Exit_DirecTv, ON)
			sendCommand(TV1_Ch1608 ,   OFF)
			sendCommand(InfoCanal,   "State")				
end


rule "FOX SPORT 3 HD 1609"
  when
    Item TV1_Ch1609 received command ON
		then
			sendCommand(Uno_DirecTv,   ON)
					Thread::sleep(500)
			sendCommand(Seis_DirecTv,   ON)
					Thread::sleep(500)	
			sendCommand(Cero_DirecTv,  ON)
					Thread::sleep(500)
			sendCommand(Nueve_DirecTv,   ON) 
					Thread::sleep(500)
			sendCommand(Enter_DirecTv, ON)
			sendCommand(Exit_DirecTv, ON)
			sendCommand(TV1_Ch1609 ,   OFF)
			sendCommand(InfoCanal,   "State")				
end


rule "DIRECTV SPORT HD 1610"
  when
    Item TV1_Ch1610 received command ON
		then
			sendCommand(Uno_DirecTv,   ON)
					Thread::sleep(500)
			sendCommand(Seis_DirecTv,   ON)
					Thread::sleep(500)	
			sendCommand(Uno_DirecTv,  ON)
					Thread::sleep(500)
			sendCommand(Cero_DirecTv,   ON) 
					Thread::sleep(500)
			sendCommand(Enter_DirecTv, ON)
			sendCommand(Exit_DirecTv, ON)
			sendCommand(TV1_Ch1610 ,   OFF)
			sendCommand(InfoCanal,   "State")				
end


rule "DIRECTV SPORT EVENTOS HD 1611"
  when
    Item TV1_Ch1611 received command ON
		then
			sendCommand(Uno_DirecTv,   ON)
					Thread::sleep(500)
			sendCommand(Seis_DirecTv,   ON)
					Thread::sleep(500)	
			sendCommand(Uno_DirecTv,  ON)
					Thread::sleep(500)
			sendCommand(Uno_DirecTv,   ON) 
					Thread::sleep(500)
			sendCommand(Enter_DirecTv, ON)
			sendCommand(Exit_DirecTv, ON)
			sendCommand(TV1_Ch1611 ,   OFF)
			sendCommand(InfoCanal,   "State")				
end


rule "DIRECTV SPORT 2 HD 1612"
  when
    Item TV1_Ch1612 received command ON
		then
			sendCommand(Uno_DirecTv,   ON)
					Thread::sleep(500)
			sendCommand(Seis_DirecTv,   ON)
					Thread::sleep(500)	
			sendCommand(Uno_DirecTv,  ON)
					Thread::sleep(500)
			sendCommand(Dos_DirecTv,   ON) 
					Thread::sleep(500)
			sendCommand(Enter_DirecTv, ON)
			Thread::sleep(500)
			sendCommand(Exit_DirecTv, ON)
			sendCommand(TV1_Ch1612 ,   OFF)
			sendCommand(InfoCanal,   "State")				
end


rule "DIRECTV SPORT + HD 1613"
  when
    Item TV1_Ch1613 received command ON
		then
			sendCommand(Uno_DirecTv,   ON)
					Thread::sleep(500)
			sendCommand(Seis_DirecTv,   ON)
					Thread::sleep(500)	
			sendCommand(Uno_DirecTv,  ON)
					Thread::sleep(500)
			sendCommand(Tres_DirecTv,   ON) 
					Thread::sleep(500)
			sendCommand(Enter_DirecTv, ON)
			Thread::sleep(500)
			sendCommand(Exit_DirecTv, ON)
			sendCommand(TV1_Ch1613 ,   OFF)
			sendCommand(InfoCanal,   "State")				
end


rule "ESPN HD 1620"
  when
    Item TV1_Ch1620 received command ON
		then
			sendCommand(Uno_DirecTv,   ON)
					Thread::sleep(500)
			sendCommand(Seis_DirecTv,   ON)
					Thread::sleep(500)	
			sendCommand(Dos_DirecTv,  ON)
					Thread::sleep(500)
			sendCommand(Cero_DirecTv,   ON) 
					Thread::sleep(500)
			sendCommand(Enter_DirecTv, ON)
			Thread::sleep(500)
			sendCommand(Exit_DirecTv, ON)
			sendCommand(TV1_Ch1620 ,   OFF)
			sendCommand(InfoCanal,   "State")				
end

rule "ESPN + HD 1621"
  when
    Item TV1_Ch1621 received command ON
		then
			sendCommand(Uno_DirecTv,   ON)
					Thread::sleep(500)
			sendCommand(Seis_DirecTv,   ON)
					Thread::sleep(500)	
			sendCommand(Dos_DirecTv,  ON)
					Thread::sleep(500)
			sendCommand(Uno_DirecTv,   ON) 
					Thread::sleep(500)
			sendCommand(Enter_DirecTv, ON)
			Thread::sleep(500)
			sendCommand(Exit_DirecTv, ON)
			sendCommand(TV1_Ch1621 ,   OFF)
			sendCommand(InfoCanal,   "State")				
end


rule "ESPN 2 HD 1623"
  when
    Item TV1_Ch625 received command ON
		then
			sendCommand(Uno_DirecTv,   ON)
					Thread::sleep(500)
			sendCommand(Seis_DirecTv,   ON)
					Thread::sleep(500)	
			sendCommand(Dos_DirecTv,  ON)
					Thread::sleep(500)
			sendCommand(Tres_DirecTv,   ON) 
					Thread::sleep(500)
			sendCommand(Enter_DirecTv, ON)
			Thread::sleep(500)
			sendCommand(Exit_DirecTv, ON)
			sendCommand(TV1_Ch1623 ,   OFF)
			sendCommand(InfoCanal,   "State")				
end


rule "ESPN 3 HD 1626"
  when
    Item TV1_Ch1626 received command ON
		then
			sendCommand(Uno_DirecTv,   ON)
					Thread::sleep(500)
			sendCommand(Seis_DirecTv,   ON)
					Thread::sleep(500)	
			sendCommand(Dos_DirecTv,  ON)
					Thread::sleep(500)
			sendCommand(Seis_DirecTv,   ON) 
					Thread::sleep(500)
			sendCommand(Enter_DirecTv, ON)
			Thread::sleep(500)
			sendCommand(Exit_DirecTv, ON)
			sendCommand(TV1_Ch1626 ,   OFF)
			sendCommand(InfoCanal,   "State")				
end

Sitemap

Switch     item=TV1_Ch1524	      label="HBO HD"		         		mappings=[ON="Ver"] 	icon="tv1524"
						Switch     item=TV1_Ch1525	      label="HBO 2 HD"		         		mappings=[ON="Ver"] 	icon="tv1525"
						Switch     item=TV1_Ch1532	      label="HBO Plus HD"		      	    mappings=[ON="Ver"] 	icon="tv1532"
						Switch     item=TV1_Ch1534	      label="HBO Family HD"		         	mappings=[ON="Ver"] 	icon="tv1534"
						Switch     item=TV1_Ch1542	      label="Max Prime HD"		        	mappings=[ON="Ver"] 	icon="tv1542"
						Switch     item=TV1_Ch1552	      label="Fox Premium Series HD"		    mappings=[ON="Ver"] 	icon="tv1552"
						Switch     item=TV1_Ch1556	      label="Fox Premium Family HD"		    mappings=[ON="Ver"] 	icon="tv1556"
						Switch     item=TV1_Ch1557	      label="Fox Premium Comedy HD"		    mappings=[ON="Ver"] 	icon="tv1557"
						Switch     item=TV1_Ch1559	      label="Fox Premium Movies HD"		    mappings=[ON="Ver"] 	icon="tv1559"
						Switch     item=TV1_Ch1561	      label="Fox Premium Action HD"		    mappings=[ON="Ver"] 	icon="tv1561"
						Switch     item=TV1_Ch1562	      label="Fox Premium Cinema HD"		    mappings=[ON="Ver"] 	icon="tv1562"
						Switch     item=TV1_Ch1604	      label="Fox Sports HD"		         	mappings=[ON="Ver"] 	icon="tv1604"
						Switch     item=TV1_Ch1608	      label="Fox Sports 2 HD"		        mappings=[ON="Ver"] 	icon="tv1608"
						Switch     item=TV1_Ch1609	      label="Fox Sports 3 HD"		        mappings=[ON="Ver"] 	icon="tv1609"
						Switch     item=TV1_Ch1610	      label="DIRECTV Sports HD"		        mappings=[ON="Ver"] 	icon="tv1610"
						Switch     item=TV1_Ch1611	      label="DIRECTV Sports HD Eventos"		mappings=[ON="Ver"] 	icon="tv1611"
						Switch     item=TV1_Ch1612	      label="DIRECTV Sports 2 HD"		    mappings=[ON="Ver"] 	icon="tv1612"
						Switch     item=TV1_Ch1613	      label="DIRECTV Sports 3 HD"		    mappings=[ON="Ver"] 	icon="tv1613"
						Switch     item=TV1_Ch1620	      label="ESPN HD"		         		mappings=[ON="Ver"] 	icon="tv1620"
						Switch     item=TV1_Ch1621	      label="ESPN + HD"		         		mappings=[ON="Ver"] 	icon="tv1621"
						Switch     item=TV1_Ch1623	      label="ESPN 2 HD"		         		mappings=[ON="Ver"] 	icon="tv1623"
						Switch     item=TV1_Ch1626	      label="ESPN 3 HD"		         		mappings=[ON="Ver"] 	icon="tv1626"

I have seen an example in this community where they use toString.substring (0, 1) to create a single rule in which it receives the command in string and then separates it and sends data by command data but it has not worked for me

rule "SEND COMMAND ONLY ONE RULE"
when
    Item Channel_select changed
then
    if (Channel_select.state == "NULL") return; // If NULL do nothing
    var topic = "broadlink/televisor/saladirectv/" + Channel_select.state.toString.substring(0, 1)
    publish("mosquitto", topic, "play-780f77b943fb")
    createTimer(now.plusSeconds(1)) [ |
        topic = "broadlink/televisor/saladirectv/" + Channel_select.state.toString.substring(1, 2)
        publish("mosquitto", topic, "play-780f77b943fb")
    ]
    createTimer(now.plusSeconds(2)) [|
        topic = "broadlink/televisor/saladirectv/" + Channel_select.state.toString.substring(2)
        publish("mosquitto", topic, "play-780f77b943fb")
    ]
end

in this example I base myself to try to reduce my code but it didn’t work for me

https://community.openhab.org/t/solved-channel-select-with-broadlink-and-mqtt/56680/2

can someone help me or give me an orientation

Yes because the MQTT action doesn’t work like this anymore:

I’m doing the following test

Sitemap

Switch item=Channel_select  label="Channel"  mappings=[112="112", 111=" 111 ", 114="114"]  icon="suenos"

Items

Number          Channel_select       "Channel select"

Things

Bridge mqtt:broker:mosquitto [ host="192.168.0.30", port=1883, clientID="Domitic", secure=false]  
{

	Thing mqtt:topic:directvsala "DIRECTV SALA"  {
	Channels:
	
Type number : Cero_DirecTv    [ commandTopic="broadlink/televisor/saladirectv/0", on="play-780f77b943fb"]
Type number : one_DirecTv     [ commandTopic="broadlink/televisor/saladirectv/1", on="play-780f77b943fb"]
Type number : two_DirecTv     [ commandTopic="broadlink/televisor/saladirectv/2", on="play-780f77b943fb"]
Type number : Tree_DirecTv 	  [ commandTopic="broadlink/televisor/saladirectv/3", on="play-780f77b943fb"]
Type number : four_DirecTv    [ commandTopic="broadlink/televisor/saladirectv/4", on="play-780f77b943fb"]
Type number : five_DirecTv	  [ commandTopic="broadlink/televisor/saladirectv/5", on="play-780f77b943fb"]
Type number : Six_DirecTv	  [ commandTopic="broadlink/televisor/saladirectv/6", on="play-780f77b943fb"]
Type number : seven_DirecTv	  [ commandTopic="broadlink/televisor/saladirectv/7", on="play-780f77b943fb"]
Type number : eight_DirecTv	  [ commandTopic="broadlink/televisor/saladirectv/8", on="play-780f77b943fb"]
Type number : nine_DirecTv	  [ commandTopic="broadlink/televisor/saladirectv/9", on="play-780f77b943fb"]

}
  }

Rule

import java.util.HashMap
import java.lang.String

rule "Tvswitcher"
when
    Item Channel_select changed
then
    if (Channel_select.state == "NULL") return; // If NULL do nothing
    val topic = "broadlink/televisor/saladirectv/" + Channel_select.state.toString.substring(0, 1)
    actions.publishMQTT("mosquitto", topic, "play-780f77b943fb")
    createTimer(now.plusSeconds(1)) [ |
        topic = "broadlink/televisor/saladirectv/" + Channel_select.state.toString.substring(1, 2)
        actions.publishMQTT("mosquitto", topic, "play-780f77b943fb")
    ]
    createTimer(now.plusSeconds(2)) [|
        topic = "broadlink/televisor/saladirectv/" + Channel_select.state.toString.substring(2)
        actions.publishMQTT("mosquitto", topic, "play-780f77b943fb")
    ]
end

in the sitemap of when I press any of the channels that are in the mapping, it sends its value to the variable or to the Item called Channel_select once it receives the value the rule is activated.

in the Log it shows me that the Item receives the value

==> /var/log/openhab2/events.log <==

2019-09-27 09:08:19.128 [ome.event.ItemCommandEvent] - Item 'Channel_select' received command 114

2019-09-27 09:08:19.147 [vent.ItemStateChangedEvent] - Channel_select changed from 111 to 114


but I get the following error

2019-09-27 09:09:26.680 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Tvswitcher': An error occurred during the script execution: index=0, size=0

can you help me, I would like to know what could be happening because I guess the digits are not separating me, because at least I think so

This is similar to what I did, as a challenge, here: Loop of flashing light inside a timer. This might be useful.

The error is complaining about the calls to substring. It’s telling you that Channel_select.state.toString is the empty String. Log value of Channel_select.state.toString and follow the state changes to that Item in events.log to see whether, when, and why it’s being set to the empty String.

i cant understand you… i see the example but i dont know how do it

I don’t know how to say it any simpler.

The empty String is a String with no letters.

The Item Channel_select is being set to the empty String.

There is no substring(0, 1) on a String with no letters.

You do not expect Chanbel_select to be the empty String.

Your team is to figure it why the Item is being set to the empty String.

I think I understand what you want to tell me is that I am only sending to the item a type of data in number format, so the tostring cannot separate the data since the type of data or information that is being received is type is not a string

Nowhere did I say anything about numbers.

If you log Channel_select.state.toString you will sometimes see that it is blank.

I already solved the problem … and I could make it work … the solution was none of the above …

Please share your solution for the benefit of others who may come after you.