[SOLVED] Channel select with broadlink and mqtt

hello

i have this in my setup

item

Number Channel_select “Channel select”

sitemap

Selection item=Channel_select mappings=[001=“MOVIES 1”, 002=“MOVIES 2”, 003=“MOVIES 3”, 004=“MOVIES 4”…

rule

rule “Tvswitcher”
when
Item Channel_select changed
then
if (Channel_select.state == “NULL”) return; // If NULL do nothing
val topic = “broadlink/tvswicher/select/tv” + Channel_select.state
publish(“mosquitto”, topic, “play-0d43b4e42518”)
end

when i select one of the channels, i get this (for example channel 001)

broadlink/tvswicher/select/tv001

and i want it to send 3 command with the first, second and third number, like this

broadlink/tvswicher/select/tv0
wait 1sec
broadlink/tvswicher/select/tv0
wait 1sec
broadlink/tvswicher/select/tv1

how can i do it?

thanks

First things first, please use the code fences when publishing code, thanks

There are several solutions to your problem.

  • Solution 1: Use timers (Recommended)
var topic = "" //AT THE TOP OF THE RULES FILE!!

rule “Tvswitcher”
when
    Item Channel_select changed
then
    if (Channel_select.state == “NULL”) return; // If NULL do nothing
    topic = “broadlink/tvswicher/select/tv” + Channel_select.state.toString.substring(0, 1)
    publish(“mosquitto”, topic, “play-0d43b4e42518”)
    createTimer(now.plusSeconds(1), [ |
        topic = “broadlink/tvswicher/select/tv” + Channel_select.state.toString.substring(1, 2)
        publish(“mosquitto”, topic, “play-0d43b4e42518”)
    |]
    createTimer(now.plusSeconds(2), [ |
        topic = “broadlink/tvswicher/select/tv” + Channel_select.state.toString.substring(2)
        publish(“mosquitto”, topic, “play-0d43b4e42518”)
    |]
end

If the string was longer we would use a loop through the string an increment the substring indexes when looping but as you only have 3 characters this should be enough and writing the loop will not save lines of code

When the rule executes it will send the find message straight away and create 2 timers to be executed 1 seconds after and 2 seconds after with the respective topics. Because the timers are execute outside the rule, we need to move the declaration of the topic variable to the top of the rules file and that it’s scope becomes global and can be accessed by the timers.

  • Solution 2: Use Thread::sleep (Not recommended)
rule “Tvswitcher”
when
    Item Channel_select changed
then
    if (Channel_select.state == “NULL”) return; // If NULL do nothing
    var topic = “broadlink/tvswicher/select/tv” + Channel_select.state.toString.substring(0, 1)
    publish(“mosquitto”, topic, “play-0d43b4e42518”)
    Thread::sleep(1)
    topic = “broadlink/tvswicher/select/tv” + Channel_select.state.toString.substring(1, 2)
    publish(“mosquitto”, topic, “play-0d43b4e42518”)
    Thread::sleep(1)
    topic = “broadlink/tvswicher/select/tv” + Channel_select.state.toString.substring(2)
    publish(“mosquitto”, topic, “play-0d43b4e42518”)
end
2 Likes

I think I do similar. Are you using broadlink-MQTT service. It has macros. Ie multiple commands

Will post sitemap/items tomorrow

thanks you, this is what i was looking for “toString.substring(0, 1)”

working now

i’m using this

it as gui for recording command and i dont think it support macros

I use this one: https://github.com/eschava/broadlink-mqtt

Then my items file

String rm3_dining_stereo_radio "Source" (g_rm3_lounge_samsung) {mqtt=">[openhab:broadlink/34ea34b2fa7f/receiver/yamaha/1:command:zm:replay],>[openhab:broadlink/34ea34b2fa7f/receiver/yamaha/4:command:sound:replay],>[openhab:broadlink/34ea34b2fa7f/receiver/yamaha/2:command:edge:replay]"}

And sitemap

Selection item=rm3_dining_stereo_radio mappings=[zm=ZM,edge="The Edge",sound=Sound]

i ask the devloper to add macros, dont know if he will, but i love the gui where i can record and see all commands list, also can check fast and easy if i have problem with my commands

THat one above, the commands and macros are recorded as files, which makes them transferable…and with some conversion you can convert them to other broadlink formats (ie the broadlink binding)

can you help me with something similar ? I have a Directv television encoder in my house

In my configuration I have certain channels declared as a switch

so

Items

Switch         TV1_Ch1130	           "RCN HD"			         	    (Switches, Gtv1)
Switch         TV1_Ch1208	           "Sony HD"		         	    (Switches, Gtv1) 
Switch         TV1_Ch1217                  "FX HD"                          (Switches, Gtv1)                                       
Switch         TV1_Ch1218                  "Universal TV HD"                (Switches, Gtv1)						
Switch         TV1_Ch1502	           "TNT HD"		         		    (Switches, Gtv1)

when I press to activate a channel, that is to say, they change from one channel to another already predetermined

What I do is the following

My Rules

rule "FOX LIFE HD 1212"
  when
    Item TV1_Ch1212 received command ON
		then
			sendCommand(Uno_DirecTv,   ON)
					Thread::sleep(500)
			sendCommand(Dos_DirecTv,   ON)
					Thread::sleep(500)	
			sendCommand(Uno_DirecTv,  ON)
					Thread::sleep(500)
			sendCommand(Dos_DirecTv,   ON) 
					Thread::sleep(500)
			sendCommand(Enter_DirecTv, ON)
			sendCommand(TV1_Ch1212 ,   OFF)
			sendCommand(InfoCanal,   "State")				
end


rule "TNT SERIES HD 1213"
  when
    Item TV1_Ch1213 received command ON
		then
			sendCommand(Uno_DirecTv,   ON)
					Thread::sleep(500)
			sendCommand(Dos_DirecTv,   ON)
					Thread::sleep(500)	
			sendCommand(Uno_DirecTv,  ON)
					Thread::sleep(500)
			sendCommand(Tres_DirecTv,   ON) 
					Thread::sleep(500)
			sendCommand(Enter_DirecTv, ON)
			sendCommand(TV1_Ch1213 ,   OFF)
			sendCommand(InfoCanal,   "State")				
end

what he does in the rules is by emplo if the channel is “1114”

sendCommand (one_DirecTv, ON)
time 500
sendCommand (one_DirecTv, ON)
time 500
sendCommand (one_DirecTv, ON)
time 500
sendCommand (four_DirecTv, ON)

the problem is that there are more than 270 telvision channels, which has generated me a file with 270 rules over 4000 lines of code.

this works for me but the rules take more than 20 minutes to load

You’d be better to use groups to turn off all the old switches
There a way of figuring out what particular item of a group was activated…and from that you could pull the name ie TV1_Ch1212 and split it into the 1,2,1,2 for sending.

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

I put my example of how I have configured everything …

to extract the chain I understand what you say and apply it but it did not work could you help me with just one example for a single channel

exposing the mqtt.things, rules, and Items for a single channel … I don’t know if it’s necessary but I’m using this broadlink integration in my system …
https://github.com/fbacker/broadlink-mqtt-bridge
I don’t know if this has something to do if the way to receive the command is different